Byron Clark avatar Byron Clark committed 85f76ce

Add an option for an alternate config file.

Comments (0)

Files changed (2)

 if __name__ == '__main__':
     import datetime
     import logging
+    import optparse
     import os
     import string
     import sys
     logging.getLogger('').addHandler(console)
     logging.getLogger('').setLevel(logging.INFO)
 
+    logger = logging.getLogger('comicbox')
+
+    parser = optparse.OptionParser()
+    parser.add_option('-f', '--file', dest='filename',
+                      help='alternate configuration FILE', metavar='FILE')
+    (options, args) = parser.parse_args()
+
     import comicbox.configuration
     from comicbox.download import fetch_strips
-
-    logger = logging.getLogger('comicbox')
-    today = datetime.datetime.now()
     # parse the configuration
     try:
-        exepath = os.path.dirname(os.path.abspath(sys.argv[0]))
-        conf = comicbox.configuration.load_configuration(exepath)
+        configs = [os.path.expanduser('~/.comicboxrc')]
+        if options.filename:
+            configs.append(options.filename)
+        conf = comicbox.configuration.load_configuration(configs)
     except comicbox.configuration.ConfigurationError, err:
         logger.fatal('unable to load configuration: %s' % (err,))
         sys.exit(1)
     except ImportError, err:
         logger.fatal('unable to load backend: %s' % (err,))
 
+    today = datetime.datetime.now()
     b = backend(today, backend_args)
     fetch_strips(strips, b, today)
     b.finish()

comicbox/configuration.py

     pass
 
 
-def load_configuration(exepath):
+def load_configuration(config_files):
     """load comicbox configuration from a file.
 
-    Loads the comicbox configuration from comicboxrc in same dir as
-    sys.argv[0] and ~/.comicboxrc.  Settings in ~/.comicboxrc override settings
-    in sys.argv[0]/comicboxrc.
+    Loads the comicbox configuration from config_files.
 
     There must be at least a 'comicbox' section in the configuration file.
     This section holds the backend and chosen strips.  If the backend takes
     additional parameters they will be in a section with the same name as the
     backend.  See doc/comicboxrc.example for an example."""
 
-    config_files = [os.path.join(exepath, 'comicboxrc'),
-                    os.path.expanduser('~/.comicboxrc')]
-
     parser = ConfigParser.SafeConfigParser()
     if len(parser.read(config_files)) == 0:
         raise ConfigurationError('No configuration files found')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.