Add commandline option for specifying config file
This commit is contained in:
parent
f8b59348c6
commit
6f4cc90d52
|
@ -421,6 +421,8 @@ class ConfigBase(Borg):
|
||||||
Borg.__init__(self, self.__class__.__name__)
|
Borg.__init__(self, self.__class__.__name__)
|
||||||
|
|
||||||
self.prepare_attributes()
|
self.prepare_attributes()
|
||||||
|
import optionparse
|
||||||
|
self.command_line_options = optionparse.options
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
def prepare_attributes(self):
|
def prepare_attributes(self):
|
||||||
|
@ -520,7 +522,10 @@ class ConfigBase(Borg):
|
||||||
dbg('ConfigBase::load: config already loaded')
|
dbg('ConfigBase::load: config already loaded')
|
||||||
return
|
return
|
||||||
|
|
||||||
filename = os.path.join(get_config_dir(), 'config')
|
if not self.command_line_options.config:
|
||||||
|
self.command_line_options.config = os.path.join(get_config_dir(), 'config')
|
||||||
|
filename = self.command_line_options.config
|
||||||
|
|
||||||
dbg('looking for config file: %s' % filename)
|
dbg('looking for config file: %s' % filename)
|
||||||
try:
|
try:
|
||||||
configfile = open(filename, 'r')
|
configfile = open(filename, 'r')
|
||||||
|
@ -616,7 +621,7 @@ class ConfigBase(Borg):
|
||||||
if not os.path.isdir(config_dir):
|
if not os.path.isdir(config_dir):
|
||||||
os.makedirs(config_dir)
|
os.makedirs(config_dir)
|
||||||
try:
|
try:
|
||||||
parser.write(open(os.path.join(config_dir, 'config'), 'w'))
|
parser.write(open(self.command_line_options.config, 'w'))
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
err('ConfigBase::save: Unable to save config: %s' % ex)
|
err('ConfigBase::save: Unable to save config: %s' % ex)
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ import config
|
||||||
import version
|
import version
|
||||||
from translation import _
|
from translation import _
|
||||||
|
|
||||||
|
options = None
|
||||||
|
|
||||||
def execute_cb(option, opt, value, lparser):
|
def execute_cb(option, opt, value, lparser):
|
||||||
"""Callback for use in parsing execute options"""
|
"""Callback for use in parsing execute options"""
|
||||||
assert value is None
|
assert value is None
|
||||||
|
@ -40,7 +42,6 @@ def parse_options():
|
||||||
"""Parse the command line options"""
|
"""Parse the command line options"""
|
||||||
usage = "usage: %prog [options]"
|
usage = "usage: %prog [options]"
|
||||||
|
|
||||||
configobj = config.Config()
|
|
||||||
parser = OptionParser(usage)
|
parser = OptionParser(usage)
|
||||||
|
|
||||||
parser.add_option('-v', '--version', action='store_true', dest='version',
|
parser.add_option('-v', '--version', action='store_true', dest='version',
|
||||||
|
@ -55,6 +56,8 @@ def parse_options():
|
||||||
help=_('Hide the window at startup'))
|
help=_('Hide the window at startup'))
|
||||||
parser.add_option('-T', '--title', dest='forcedtitle', help=_('Specify a \
|
parser.add_option('-T', '--title', dest='forcedtitle', help=_('Specify a \
|
||||||
title for the window'))
|
title for the window'))
|
||||||
|
parser.add_option('-c', '--config', dest='config', help=_('Specify a \
|
||||||
|
config file'))
|
||||||
parser.add_option('--geometry', dest='geometry', type='string', help=_('Set \
|
parser.add_option('--geometry', dest='geometry', type='string', help=_('Set \
|
||||||
the preferred size and position of the window (see X man page)'))
|
the preferred size and position of the window (see X man page)'))
|
||||||
parser.add_option('-e', '--command', dest='command', help=_('Specify a \
|
parser.add_option('-e', '--command', dest='command', help=_('Specify a \
|
||||||
|
@ -82,6 +85,7 @@ different profile as the default'))
|
||||||
parser.add_option(item, dest='dummy', action='store',
|
parser.add_option(item, dest='dummy', action='store',
|
||||||
help=SUPPRESS_HELP)
|
help=SUPPRESS_HELP)
|
||||||
|
|
||||||
|
global options
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
parser.error('Additional unexpected arguments found: %s' % args)
|
parser.error('Additional unexpected arguments found: %s' % args)
|
||||||
|
@ -118,6 +122,7 @@ different profile as the default'))
|
||||||
if options.layout is None:
|
if options.layout is None:
|
||||||
options.layout = 'default'
|
options.layout = 'default'
|
||||||
|
|
||||||
|
configobj = config.Config()
|
||||||
if options.profile and options.profile not in configobj.list_profiles():
|
if options.profile and options.profile not in configobj.list_profiles():
|
||||||
options.profile = None
|
options.profile = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue