Mercurial > hg > Feedworm
changeset 180:a4832a180c69
allow setting the URL to the database via command line
author | dirk |
---|---|
date | Sat, 10 Sep 2011 04:43:40 +0200 |
parents | c8393c2cd324 |
children | 1ab48428e2f9 |
files | backend/couchdb/CouchDb.py backend/couchdb/CouchDbBackend.py |
diffstat | 2 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/couchdb/CouchDb.py Sat Sep 10 04:32:53 2011 +0200 +++ b/backend/couchdb/CouchDb.py Sat Sep 10 04:43:40 2011 +0200 @@ -1,17 +1,32 @@ from argparse import ArgumentParser +database_url = None database = "feedworm" def init(): + args = _parseArguments() + _setDatabaseName(args) + _setDatabaseUrl(args) + +def _parseArguments(): parser = ArgumentParser() parser.add_argument("--dbname", nargs="?", help="Name of the database") - args = parser.parse_known_args() + parser.add_argument("--dburl", nargs="?", help="URL of the database") + return parser.parse_known_args() + +def _setDatabaseName(args): dbname = args[0].dbname if dbname is not None: global database database = dbname +def _setDatabaseUrl(args): + dburl = args[0].dburl + if dburl is not None: + global database_url + database_url = dburl + # # accessor methods for the various views #
--- a/backend/couchdb/CouchDbBackend.py Sat Sep 10 04:32:53 2011 +0200 +++ b/backend/couchdb/CouchDbBackend.py Sat Sep 10 04:43:40 2011 +0200 @@ -15,10 +15,16 @@ def __init__(self): CouchDb.init() - server = couchdb.Server() + server = self._initServer() self.database = server[CouchDb.database] self.prefs = None + def _initServer(self): + if CouchDb.database_url is not None: + return couchdb.Server(CouchDb.database_url) + else: + return couchdb.Server() + def preferences(self): if self.prefs is None: self.prefs = Preferences(self.database)