# HG changeset patch # User Dirk Olmes # Date 1314103018 -7200 # Node ID 5b131f82057d3b66b11949a674739b79b4382fe0 # Parent 7217b060b39cbb705c5098577fc46912c5d4b08f allow choosing the backend via commandline option diff -r 7217b060b39c -r 5b131f82057d BackendFactory.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BackendFactory.py Tue Aug 23 14:36:58 2011 +0200 @@ -0,0 +1,23 @@ + +import argparse + +SQLALCHEMY_BACKEND = "sqlalchemy" +COUCHDB_BACKEND = "couchdb" + +def _parseArguments(): + parser = argparse.ArgumentParser() + parser.add_argument("--backend", nargs="?", choices=[SQLALCHEMY_BACKEND, COUCHDB_BACKEND], + required=True, help="Specify the backend to use: either sqlalchemy or couchdb") + return parser.parse_known_args() + +def createBackend(): + args = _parseArguments() + backend = args[0].backend + if backend == SQLALCHEMY_BACKEND: + from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend + return SqlAlchemyBackend() + elif backend == COUCHDB_BACKEND: + from backend.couchdb.CouchDbBackend import CouchDbBackend + return CouchDbBackend() + else: + raise Exception("no backend configured") diff -r 7217b060b39c -r 5b131f82057d backend/sqlalchemy/Database.py --- a/backend/sqlalchemy/Database.py Tue Aug 23 04:15:46 2011 +0200 +++ b/backend/sqlalchemy/Database.py Tue Aug 23 14:36:58 2011 +0200 @@ -2,7 +2,7 @@ from sqlalchemy.engine import create_engine from sqlalchemy.orm import sessionmaker import Mapping -import sys +import argparse import util # Keep the connection to the database only once. The feed updater and the GUI app will @@ -19,10 +19,10 @@ return SessionMaker() def _getDatabaseUrl(): - if len(sys.argv) < 2: - print("Usage: %s " % (sys.argv[0])) - sys.exit(1) - return sys.argv[1] + parser = argparse.ArgumentParser() + parser.add_argument("--dburl", nargs="?", required=True, help="Database URL for the sqlalchemy backend") + args = parser.parse_known_args() + return args[0].dburl def initEngine(databaseUrl): global engine diff -r 7217b060b39c -r 5b131f82057d feedupdate.py --- a/feedupdate.py Tue Aug 23 04:15:46 2011 +0200 +++ b/feedupdate.py Tue Aug 23 14:36:58 2011 +0200 @@ -1,13 +1,11 @@ #!/usr/bin/env python +import BackendFactory import logging -#from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend -from backend.couchdb.CouchDbBackend import CouchDbBackend if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) -# backend = SqlAlchemyBackend() - backend = CouchDbBackend() + backend = BackendFactory.createBackend() backend.updateAllFeeds() backend.expireFeedEntries() backend.dispose() diff -r 7217b060b39c -r 5b131f82057d feedupdate.sh --- a/feedupdate.sh Tue Aug 23 04:15:46 2011 +0200 +++ b/feedupdate.sh Tue Aug 23 14:36:58 2011 +0200 @@ -1,4 +1,4 @@ #!/bin/bash DB_URL="mysql://root:mysql@xanthippe/feedworm?use_unicode=1&charset=utf8" -./feedupdate.py ${DB_URL} +./feedupdate.py --backend sqlalchemy --dburl ${DB_URL} diff -r 7217b060b39c -r 5b131f82057d feedworm-gui.py --- a/feedworm-gui.py Tue Aug 23 04:15:46 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ - -from MainWindow import MainWindow -from PyQt4 import QtGui -from PyQt4.QtNetwork import QNetworkProxy -from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend -from backend.couchdb.CouchDbBackend import CouchDbBackend -import logging -import sys - -def setupProxy(preferences): - if preferences.isProxyConfigured(): - proxyHost = preferences.proxyHost() - proxyPort = preferences.proxyPort() - proxy = QNetworkProxy(QNetworkProxy.HttpProxy, proxyHost, proxyPort) - QNetworkProxy.setApplicationProxy(proxy) - -if __name__ == '__main__': - logging.basicConfig(level=logging.DEBUG) -# backend = SqlAlchemyBackend() - backend = CouchDbBackend() - preferences = backend.preferences() - - setupProxy(preferences) - - app = QtGui.QApplication(sys.argv) - mainWindow = MainWindow(backend) - - maximized = preferences.startMaximized() - if maximized: - mainWindow.showMaximized() - else: - mainWindow.show() - - sys.exit(app.exec_()) diff -r 7217b060b39c -r 5b131f82057d feedworm.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/feedworm.py Tue Aug 23 14:36:58 2011 +0200 @@ -0,0 +1,31 @@ + +from MainWindow import MainWindow +from PyQt4 import QtGui +from PyQt4.QtNetwork import QNetworkProxy +import BackendFactory +import logging +import sys + +def setupProxy(preferences): + if preferences.isProxyConfigured(): + proxyHost = preferences.proxyHost() + proxyPort = preferences.proxyPort() + proxy = QNetworkProxy(QNetworkProxy.HttpProxy, proxyHost, proxyPort) + QNetworkProxy.setApplicationProxy(proxy) + +if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG) + backend = BackendFactory.createBackend() + preferences = backend.preferences() + setupProxy(preferences) + + app = QtGui.QApplication(sys.argv) + mainWindow = MainWindow(backend) + + maximized = preferences.startMaximized() + if maximized: + mainWindow.showMaximized() + else: + mainWindow.show() + + sys.exit(app.exec_()) diff -r 7217b060b39c -r 5b131f82057d feedworm.sh --- a/feedworm.sh Tue Aug 23 04:15:46 2011 +0200 +++ b/feedworm.sh Tue Aug 23 14:36:58 2011 +0200 @@ -1,4 +1,4 @@ #!/bin/bash DB_URL="mysql://root:mysql@xanthippe/feedworm?use_unicode=1&charset=utf8" -/usr/bin/python ./feedworm-gui.py ${DB_URL} +/usr/bin/python ./feedworm.py --backend sqlalchemy --dburl ${DB_URL}