Merge branch 'dev' into 'master'

Improvements for Configpaths

See merge request !22
This commit is contained in:
Philipp Hörist 2017-01-07 19:36:13 +01:00
commit e967d4ed77
2 changed files with 19 additions and 27 deletions

View File

@ -130,9 +130,7 @@ def split_db():
print('spliting database') print('spliting database')
if os.name == 'nt': if os.name == 'nt':
try: try:
import configpaths OLD_LOG_DB_FOLDER = os.path.join(os.environ['appdata'], 'Gajim')
OLD_LOG_DB_FOLDER = os.path.join(configpaths.fse(
os.environ['appdata']), 'Gajim')
except KeyError: except KeyError:
OLD_LOG_DB_FOLDER = '.' OLD_LOG_DB_FOLDER = '.'
else: else:
@ -187,8 +185,7 @@ def check_and_possibly_move_config():
if os.name == 'nt': if os.name == 'nt':
try: try:
OLD_LOG_DB_FOLDER = os.path.join(configpaths.fse( OLD_LOG_DB_FOLDER = os.path.join(os.environ['appdata'], 'Gajim')
os.environ['appdata']), 'Gajim')
except KeyError: except KeyError:
OLD_LOG_DB_FOLDER = '.' OLD_LOG_DB_FOLDER = '.'
else: else:

View File

@ -52,17 +52,17 @@ TYPE_DATA
# just leave it as is. Since these paths are meant to be internal to Gajim and # just leave it as is. Since these paths are meant to be internal to Gajim and
# not displayed to the user, Unicode is not really necessary here. # not displayed to the user, Unicode is not really necessary here.
def fse(s):
"""
Convert from filesystem encoding if not already Unicode
"""
return s
def windowsify(s): def windowsify(s):
if os.name == 'nt': if os.name == 'nt':
return s.capitalize() return s.capitalize()
return s return s
def get(key):
return gajimpaths[key]
class ConfigPaths: class ConfigPaths:
def __init__(self): def __init__(self):
# {'name': (type, path), } type can be TYPE_CONFIG, TYPE_CACHE, TYPE_DATA # {'name': (type, path), } type can be TYPE_CONFIG, TYPE_CACHE, TYPE_DATA
@ -77,7 +77,7 @@ class ConfigPaths:
# variable 'appdata' is in? Assuming it to be in filesystem # variable 'appdata' is in? Assuming it to be in filesystem
# encoding. # encoding.
self.config_root = self.cache_root = self.data_root = \ self.config_root = self.cache_root = self.data_root = \
os.path.join(fse(os.environ['appdata']), 'Gajim') os.path.join(os.environ['appdata'], 'Gajim')
except KeyError: except KeyError:
# win9x, in cwd # win9x, in cwd
self.config_root = self.cache_root = self.data_root = '.' self.config_root = self.cache_root = self.data_root = '.'
@ -97,6 +97,13 @@ class ConfigPaths:
base = expand('~/.local/share') base = expand('~/.local/share')
self.data_root = os.path.join(base, 'gajim') self.data_root = os.path.join(base, 'gajim')
basedir = os.environ.get('GAJIM_BASEDIR', defs.basedir)
self.add('DATA', None, os.path.join(basedir, 'data'))
self.add('GUI', None, os.path.join(basedir, 'data', 'gui'))
self.add('ICONS', None, os.path.join(basedir, 'icons'))
self.add('HOME', None, os.path.expanduser('~'))
self.add('PLUGINS_BASE', None, os.path.join(basedir, 'plugins'))
def add(self, name, type_, path): def add(self, name, type_, path):
self.paths[name] = (type_, path) self.paths[name] = (type_, path)
@ -159,24 +166,12 @@ class ConfigPaths:
else: else:
self.add('MY_CONFIG', TYPE_CONFIG, '') self.add('MY_CONFIG', TYPE_CONFIG, '')
basedir = fse(os.environ.get('GAJIM_BASEDIR', defs.basedir))
self.add('DATA', None, os.path.join(basedir, windowsify('data')))
self.add('ICONS', None, os.path.join(basedir, windowsify('icons')))
self.add('HOME', None, fse(os.path.expanduser('~')))
self.add('PLUGINS_BASE', None, os.path.join(basedir,
windowsify('plugins')))
try: try:
self.add('TMP', None, fse(tempfile.gettempdir())) self.add('TMP', None, tempfile.gettempdir())
except IOError as e: except IOError as e:
print('Error opening tmp folder: %s\nUsing %s' % (str(e), print('Error opening tmp folder: %s\nUsing %s' % (str(e),
os.path.expanduser('~')), file=sys.stderr) os.path.expanduser('~')), file=sys.stderr)
self.add('TMP', None, fse(os.path.expanduser('~'))) self.add('TMP', None, os.path.expanduser('~'))
try:
import svn_config
svn_config.configure(self)
except (ImportError, AttributeError):
pass
def init_profile(self, profile): def init_profile(self, profile):
conffile = windowsify('config') conffile = windowsify('config')