add --config-path option so that we can specify the root folder of config files. see #2149
This commit is contained in:
parent
85158665d4
commit
3b9966960d
|
@ -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,51 +73,45 @@ 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():
|
# LOG is deprecated
|
||||||
paths = ConfigPaths()
|
k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' )
|
||||||
|
v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons')
|
||||||
|
|
||||||
# LOG is deprecated
|
if os.name == 'nt':
|
||||||
k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' )
|
v = map(lambda x: x.capitalize(), v)
|
||||||
v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons')
|
|
||||||
|
|
||||||
if os.name == 'nt':
|
for n, p in zip(k, v):
|
||||||
v = map(lambda x: x.capitalize(), v)
|
self.add_from_root(n, p)
|
||||||
|
|
||||||
for n, p in zip(k, v):
|
self.add('DATA', os.path.join(u'..', windowsify(u'data')))
|
||||||
paths.add_from_root(n, p)
|
self.add('HOME', fse(os.path.expanduser('~')))
|
||||||
|
self.add('TMP', fse(tempfile.gettempdir()))
|
||||||
|
|
||||||
paths.add('DATA', os.path.join(u'..', windowsify(u'data')))
|
try:
|
||||||
paths.add('HOME', fse(os.path.expanduser('~')))
|
import svn_config
|
||||||
paths.add('TMP', fse(tempfile.gettempdir()))
|
svn_config.configure(self)
|
||||||
|
except (ImportError, AttributeError):
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
# for k, v in paths.iteritems():
|
||||||
import svn_config
|
# print "%s: %s" % (repr(k), repr(v))
|
||||||
svn_config.configure(paths)
|
|
||||||
except (ImportError, AttributeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# for k, v in paths.iteritems():
|
def init_profile(self, profile):
|
||||||
# print "%s: %s" % (repr(k), repr(v))
|
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):
|
gajimpaths = ConfigPaths()
|
||||||
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))
|
|
||||||
|
|
26
src/gajim.py
26
src/gajim.py
|
@ -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']
|
||||||
|
|
Loading…
Reference in New Issue