add --config-path option so that we can specify the root folder of config files. see #2149

This commit is contained in:
Yann Leboulanger 2007-07-25 23:04:15 +00:00
parent 85158665d4
commit 3b9966960d
2 changed files with 53 additions and 48 deletions

View File

@ -25,6 +25,11 @@ def fse(s):
'''Convert from filesystem encoding if not already Unicode''' '''Convert from filesystem encoding if not already Unicode'''
return unicode(s, sys.getfilesystemencoding()) return unicode(s, sys.getfilesystemencoding())
def windowsify(s):
if os.name == 'nt':
return s.capitalize()
return s
class ConfigPaths: class ConfigPaths:
def __init__(self, root=None): def __init__(self, root=None):
self.root = root self.root = root
@ -68,13 +73,9 @@ class ConfigPaths:
for key in self.paths.iterkeys(): for key in self.paths.iterkeys():
yield (key, self[key]) yield (key, self[key])
def windowsify(s): def init(self, root = None):
if os.name == 'nt': if self.root is not None:
return s.capitalize() self.root = root
return s
def init():
paths = ConfigPaths()
# LOG is deprecated # LOG is deprecated
k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' ) k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' )
@ -84,26 +85,22 @@ def init():
v = map(lambda x: x.capitalize(), v) v = map(lambda x: x.capitalize(), v)
for n, p in zip(k, v): for n, p in zip(k, v):
paths.add_from_root(n, p) self.add_from_root(n, p)
paths.add('DATA', os.path.join(u'..', windowsify(u'data'))) self.add('DATA', os.path.join(u'..', windowsify(u'data')))
paths.add('HOME', fse(os.path.expanduser('~'))) self.add('HOME', fse(os.path.expanduser('~')))
paths.add('TMP', fse(tempfile.gettempdir())) self.add('TMP', fse(tempfile.gettempdir()))
try: try:
import svn_config import svn_config
svn_config.configure(paths) svn_config.configure(self)
except (ImportError, AttributeError): except (ImportError, AttributeError):
pass pass
# for k, v in paths.iteritems(): # for k, v in paths.iteritems():
# print "%s: %s" % (repr(k), repr(v)) # print "%s: %s" % (repr(k), repr(v))
return paths def init_profile(self, profile):
gajimpaths = init()
def init_profile(profile, paths=gajimpaths):
conffile = windowsify(u'config') conffile = windowsify(u'config')
pidfile = windowsify(u'gajim') pidfile = windowsify(u'gajim')
@ -111,8 +108,10 @@ def init_profile(profile, paths=gajimpaths):
conffile += u'.' + profile conffile += u'.' + profile
pidfile += u'.' + profile pidfile += u'.' + profile
pidfile += u'.pid' pidfile += u'.pid'
paths.add_from_root('CONFIG_FILE', conffile) self.add_from_root('CONFIG_FILE', conffile)
paths.add_from_root('PID_FILE', pidfile) self.add_from_root('PID_FILE', pidfile)
# for k, v in paths.iteritems(): # for k, v in paths.iteritems():
# print "%s: %s" % (repr(k), repr(v)) # print "%s: %s" % (repr(k), repr(v))
gajimpaths = ConfigPaths()

View File

@ -72,10 +72,11 @@ def parseAndSetLogLevels(arg):
def parseOpts(): def parseOpts():
profile = '' profile = ''
verbose = False verbose = False
config_path = None
try: try:
shortargs = 'hqvl:p:' shortargs = 'hqvl:p:c:'
longargs = 'help quiet verbose loglevel= profile=' longargs = 'help quiet verbose loglevel= profile= config_path='
opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split()) opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split())
except getopt.error, msg: except getopt.error, msg:
print msg print msg
@ -95,11 +96,22 @@ def parseOpts():
profile = a profile = a
elif o in ('-l', '--loglevel'): elif o in ('-l', '--loglevel'):
parseAndSetLogLevels(a) parseAndSetLogLevels(a)
return profile, verbose elif o in ('-c', '--config-path'):
config_path = a
return profile, verbose, config_path
profile, verbose = parseOpts() profile, verbose, config_path = parseOpts()
del parseOpts, parseAndSetLogLevels, parseLogTarget, parseLogLevel del parseOpts, parseAndSetLogLevels, parseLogTarget, parseLogLevel
import locale
profile = unicode(profile, locale.getpreferredencoding())
import common.configpaths
common.configpaths.gajimpaths.init(config_path)
del config_path
common.configpaths.gajimpaths.init_profile(profile)
del profile
import message_control import message_control
from chat_control import ChatControlBase from chat_control import ChatControlBase
@ -198,12 +210,6 @@ from common import optparser
if verbose: gajim.verbose = True if verbose: gajim.verbose = True
del verbose del verbose
import locale
profile = unicode(profile, locale.getpreferredencoding())
import common.configpaths
common.configpaths.init_profile(profile)
del profile
gajimpaths = common.configpaths.gajimpaths gajimpaths = common.configpaths.gajimpaths
pid_filename = gajimpaths['PID_FILE'] pid_filename = gajimpaths['PID_FILE']