Mercurial > hg > Feedworm
changeset 137:5b131f82057d
allow choosing the backend via commandline option
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Tue, 23 Aug 2011 14:36:58 +0200 |
parents | 7217b060b39c |
children | 2642c8d89bdc 2cd30af937fa |
files | BackendFactory.py backend/sqlalchemy/Database.py feedupdate.py feedupdate.sh feedworm-gui.py feedworm.py feedworm.sh |
diffstat | 7 files changed, 63 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- /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")
--- 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 <database url>" % (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
--- 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()
--- 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}
--- 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_())
--- /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_())
--- 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}