From 4dc60e4f1e7db13caf0e733f289fe03d1bb110f2 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 21 Feb 2013 20:50:08 +0100 Subject: [PATCH 1/2] added --version option Every program should have this, really. --- aqt/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aqt/__init__.py b/aqt/__init__.py index 58dcfa9c2..2f25acbba 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -163,7 +163,7 @@ class AnkiApp(QApplication): def parseArgs(argv): "Returns (opts, args)." - parser = optparse.OptionParser() + parser = optparse.OptionParser(version="%prog " + appVersion) parser.usage = "%prog [OPTIONS] [file to import]" parser.add_option("-b", "--base", help="path to base folder") parser.add_option("-p", "--profile", help="profile name to load") From 370fd6507d3a431828b2abaca8db03f8998b5153 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 21 Feb 2013 20:51:06 +0100 Subject: [PATCH 2/2] move parseArgs to the top of aqt.run() By placing argument parsing at the top, we skip starting up all the QT stuff when using options like --help or --version that cause the program to exit anyway. --- aqt/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aqt/__init__.py b/aqt/__init__.py index 2f25acbba..002b87d6e 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -174,6 +174,11 @@ def run(): global mw from anki.utils import isMac + # parse args + opts, args = parseArgs(sys.argv) + opts.base = unicode(opts.base or "", sys.getfilesystemencoding()) + opts.profile = unicode(opts.profile or "", sys.getfilesystemencoding()) + # on osx we'll need to add the qt plugins to the search path if isMac and getattr(sys, 'frozen', None): rd = os.path.abspath(moduleDir + "/../../..") @@ -203,11 +208,6 @@ environment points to a valid, writable folder.""") "upgrade to a newer Qt, you may experience issues such as images " "failing to show up during review.") - # parse args - opts, args = parseArgs(sys.argv) - opts.base = unicode(opts.base or "", sys.getfilesystemencoding()) - opts.profile = unicode(opts.profile or "", sys.getfilesystemencoding()) - # profile manager from aqt.profiles import ProfileManager pm = ProfileManager(opts.base, opts.profile)