From 3b9966960d9acd1e6bbb8d4ecec03fcabe5c1670 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 25 Jul 2007 23:04:15 +0000 Subject: [PATCH] add --config-path option so that we can specify the root folder of config files. see #2149 --- src/common/configpaths.py | 75 +++++++++++++++++++-------------------- src/gajim.py | 26 ++++++++------ 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/common/configpaths.py b/src/common/configpaths.py index f7e09a686..be64f013b 100644 --- a/src/common/configpaths.py +++ b/src/common/configpaths.py @@ -25,6 +25,11 @@ def fse(s): '''Convert from filesystem encoding if not already Unicode''' return unicode(s, sys.getfilesystemencoding()) +def windowsify(s): + if os.name == 'nt': + return s.capitalize() + return s + class ConfigPaths: def __init__(self, root=None): self.root = root @@ -68,51 +73,45 @@ class ConfigPaths: for key in self.paths.iterkeys(): yield (key, self[key]) -def windowsify(s): - if os.name == 'nt': - return s.capitalize() - return s + def init(self, root = None): + if self.root is not None: + self.root = root -def init(): - paths = ConfigPaths() + # LOG is deprecated + k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' ) + v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons') - # LOG is deprecated - k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' ) - v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons') + if os.name == 'nt': + v = map(lambda x: x.capitalize(), v) - if os.name == 'nt': - v = map(lambda x: x.capitalize(), v) + for n, p in zip(k, v): + self.add_from_root(n, p) - for n, p in zip(k, v): - paths.add_from_root(n, p) + self.add('DATA', os.path.join(u'..', windowsify(u'data'))) + self.add('HOME', fse(os.path.expanduser('~'))) + self.add('TMP', fse(tempfile.gettempdir())) - paths.add('DATA', os.path.join(u'..', windowsify(u'data'))) - paths.add('HOME', fse(os.path.expanduser('~'))) - paths.add('TMP', fse(tempfile.gettempdir())) + try: + import svn_config + svn_config.configure(self) + except (ImportError, AttributeError): + pass - try: - import svn_config - svn_config.configure(paths) - except (ImportError, AttributeError): - pass + # for k, v in paths.iteritems(): + # print "%s: %s" % (repr(k), repr(v)) - # for k, v in paths.iteritems(): - # print "%s: %s" % (repr(k), repr(v)) + def init_profile(self, profile): + conffile = windowsify(u'config') + pidfile = windowsify(u'gajim') - return paths + if len(profile) > 0: + conffile += u'.' + profile + pidfile += u'.' + profile + pidfile += u'.pid' + self.add_from_root('CONFIG_FILE', conffile) + self.add_from_root('PID_FILE', pidfile) -gajimpaths = init() + # for k, v in paths.iteritems(): + # print "%s: %s" % (repr(k), repr(v)) -def init_profile(profile, paths=gajimpaths): - conffile = windowsify(u'config') - pidfile = windowsify(u'gajim') - - if len(profile) > 0: - conffile += u'.' + profile - pidfile += u'.' + profile - pidfile += u'.pid' - paths.add_from_root('CONFIG_FILE', conffile) - paths.add_from_root('PID_FILE', pidfile) - - # for k, v in paths.iteritems(): - # print "%s: %s" % (repr(k), repr(v)) +gajimpaths = ConfigPaths() diff --git a/src/gajim.py b/src/gajim.py index 538cf1296..c21f43669 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -72,10 +72,11 @@ def parseAndSetLogLevels(arg): def parseOpts(): profile = '' verbose = False + config_path = None try: - shortargs = 'hqvl:p:' - longargs = 'help quiet verbose loglevel= profile=' + shortargs = 'hqvl:p:c:' + longargs = 'help quiet verbose loglevel= profile= config_path=' opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split()) except getopt.error, msg: print msg @@ -95,11 +96,22 @@ def parseOpts(): profile = a elif o in ('-l', '--loglevel'): 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 +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 from chat_control import ChatControlBase @@ -198,12 +210,6 @@ from common import optparser if verbose: gajim.verbose = True del verbose -import locale -profile = unicode(profile, locale.getpreferredencoding()) - -import common.configpaths -common.configpaths.init_profile(profile) -del profile gajimpaths = common.configpaths.gajimpaths pid_filename = gajimpaths['PID_FILE']