diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-05-18 20:14:52 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-05-18 20:14:52 +0200 |
commit | e56bc4b33263d4224fe162157bed0dd157471934 (patch) | |
tree | d5da9c9f49bce1218738df458cc4f3f459400172 /kittystore | |
parent | c91bf003fb5d5d91343e296b9a82345d44529b3e (diff) | |
download | kittystore-e56bc4b33263d4224fe162157bed0dd157471934.tar.gz kittystore-e56bc4b33263d4224fe162157bed0dd157471934.tar.xz kittystore-e56bc4b33263d4224fe162157bed0dd157471934.zip |
Allow reading the KittyStore URL from Django
Diffstat (limited to 'kittystore')
-rw-r--r-- | kittystore/scripts.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/kittystore/scripts.py b/kittystore/scripts.py index 33bfc73..67d7b4c 100644 --- a/kittystore/scripts.py +++ b/kittystore/scripts.py @@ -23,7 +23,10 @@ Various utility scripts. Author: Aurelien Bompard <abompard@fedoraproject.org> """ +from __future__ import absolute_import +import importlib +import sys from optparse import OptionParser from kittystore import get_store @@ -35,17 +38,34 @@ from kittystore import get_store def updatedb(): parser = OptionParser(usage="%prog -s store_url") - parser.add_option("-s", "--store", help="the URL to the store database") + parser.add_option("-s", "--store", metavar="URL", + help="the URL to the store database") + parser.add_option("--settings", + help="the Python path to a settings module") + parser.add_option("--pythonpath", + help="a directory to add to the Python path") parser.add_option("-d", "--debug", action="store_true", - help="show SQL queries") + help="show SQL queries") opts, args = parser.parse_args() - if opts.store is None: - parser.error("the store URL is missing (eg: " - "sqlite:///kittystore.sqlite).") + if opts.store is not None: + store_url = opts.store + elif opts.settings is not None: + if opts.pythonpath is not None: + sys.path.append(opts.pythonpath) + try: + mod = importlib.import_module(opts.settings) + except ImportError as e: + parser.error("could not import settings '%s' (Is it on " + "sys.path?): %s" % (opts.settings, e)) + store_url = mod.KITTYSTORE_URL + else: + parser.error("you must either specify a store URL (eg: " + "sqlite:///kittystore.sqlite) or a Django configuration " + "module (Python path to the settings module)") if args: parser.error("no arguments allowed.") print 'Upgrading the database schema if necessary...' - store = get_store(opts.store, debug=opts.debug) + store = get_store(store_url, debug=opts.debug) version = list(store.db.execute( "SELECT patch.version FROM patch " "ORDER BY version DESC LIMIT 1" |