Author: asterix
Date: 2007-07-26 01:04:15 +0200 (Thu, 26 Jul 2007)
New Revision: 8434
Modified:
trunk/src/common/configpaths.py
trunk/src/gajim.py
Log:
add --config-path option so that we can specify the root folder of config files. see #2149
Modified: trunk/src/common/configpaths.py
===================================================================
--- trunk/src/common/configpaths.py 2007-07-25 23:02:55 UTC (rev 8433)
+++ trunk/src/common/configpaths.py 2007-07-25 23:04:15 UTC (rev 8434)
@@ -25,6 +25,11 @@
'''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 @@
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()
Modified: trunk/src/gajim.py
===================================================================
--- trunk/src/gajim.py 2007-07-25 23:02:55 UTC (rev 8433)
+++ trunk/src/gajim.py 2007-07-25 23:04:15 UTC (rev 8434)
@@ -72,10 +72,11 @@
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 @@
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 @@
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']