diff --git a/CHANGELOG b/CHANGELOG index 40d42b7151..c74216ec97 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Use versioned configuration directory * Next and Previous scroll per page on list and don't loop * Add AccelGroup on search windows (CTRL+Return) * Use same keyboard shortcut for xxx2many than for other fields diff --git a/doc/usage.rst b/doc/usage.rst index 35d56fb1d0..d0578ed3e0 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -919,8 +919,8 @@ Configuration File :: - ~./tryton # General configuration - ~./trytonsc # Shortcut configuration + ~/.config/tryton/x.y/tryton.conf # General configuration + ~/.config/tryton/x.y/accel.map # Accelerators configuration :Authors: Udo Spallek, Bertrand Chenal, Mattias Behrle, Anne Krings diff --git a/tryton/client.py b/tryton/client.py index c836ccac6a..2e6ab3dd7e 100644 --- a/tryton/client.py +++ b/tryton/client.py @@ -15,7 +15,7 @@ import logging from tryton import version from tryton import config from tryton.config import CONFIG, CURRENT_DIR, PREFIX, PIXMAPS_DIR, \ - TRYTON_ICON, get_home_dir + TRYTON_ICON, get_config_dir from tryton import translate from tryton import gui import traceback @@ -105,7 +105,7 @@ class TrytonClient(object): except KeyboardInterrupt: CONFIG.save() if hasattr(gtk, 'accel_map_save'): - gtk.accel_map_save(os.path.join(get_home_dir(), '.trytonsc')) + gtk.accel_map_save(os.path.join(get_config_dir(), 'accel.map')) if __name__ == "__main__": CLIENT = TrytonClient() diff --git a/tryton/config.py b/tryton/config.py index 273b942feb..4d10b3bddb 100644 --- a/tryton/config.py +++ b/tryton/config.py @@ -14,33 +14,18 @@ import gtk _ = gettext.gettext def get_home_dir(): - """ - Return the closest possible equivalent to a 'home' directory. - For Posix systems, this is $HOME, and on NT it's $HOMEDRIVE\$HOMEPATH. - Currently only Posix and NT are implemented, a HomeDirError exception is - raised for all other OSes. - """ + if os.name == 'nt': + return os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH']) + return os.environ['HOME'] - if os.name == 'posix': - return os.path.expanduser('~') - elif os.name == 'nt': - try: - return os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH']) - except: - try: - import _winreg as wreg - key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, - "Software\Microsoft\Windows\Current" \ - "Version\Explorer\Shell Folders") - homedir = wreg.QueryValueEx(key, 'Personal')[0] - key.Close() - return homedir - except: - return 'C:\\' - elif os.name == 'dos': - return 'C:\\' - else: - return '.' +def get_config_dir(): + if os.name == 'nt': + return os.path.join(os.environ['APPDATA'], '.config', 'tryton', + VERSION.rsplit('.', 1)[0]) + return os.path.join(os.environ['HOME'], '.config', 'tryton', + VERSION.rsplit('.', 1)[0]) +if not os.path.isdir(get_config_dir()): + os.makedirs(get_config_dir(), 0700) def find_path(progs, args): if os.name == 'nt': @@ -126,7 +111,7 @@ class ConfigManager(object): if opt.config and not os.path.isfile(opt.config): raise Exception(_('File "%s" not found') % (opt.config,)) - self.rcfile = opt.config or os.path.join(get_home_dir(), '.tryton') + self.rcfile = opt.config or os.path.join(get_config_dir(), 'tryton.conf') self.load() for arg in ('log_level', 'log_logger'): diff --git a/tryton/gui/main.py b/tryton/gui/main.py index 709f99c70d..fcb821eea0 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -7,7 +7,8 @@ import urlparse import gobject import gtk import tryton.rpc as rpc -from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR, DATA_DIR, get_home_dir +from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR, DATA_DIR, \ + get_config_dir import tryton.common as common from tryton.action import Action from tryton.gui.window import Window @@ -97,7 +98,7 @@ class Main(object): gtk.gdk.CONTROL_MASK) if hasattr(gtk, 'accel_map_load'): - gtk.accel_map_load(os.path.join(get_home_dir(), '.trytonsc')) + gtk.accel_map_load(os.path.join(get_config_dir(), 'accel.map')) self.tooltips = common.Tooltips() @@ -1270,7 +1271,7 @@ class Main(object): CONFIG['client.default_height'] = Main.get_main()._height CONFIG.save() if hasattr(gtk, 'accel_map_save'): - gtk.accel_map_save(os.path.join(get_home_dir(), '.trytonsc')) + gtk.accel_map_save(os.path.join(get_config_dir(), 'accel.map')) gtk.main_quit() sys.exit()