Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tryton/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Transfer configuration, profiles and plugins from previous version
* Don't reset date/datetime/time to None when it is invalid

Version 6.8.3 - 2023-09-06
Expand Down
2 changes: 1 addition & 1 deletion tryton/tryton/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from gi.repository import Gdk, Gio, Gtk

from tryton import __version__, common, gui, translate
from tryton.config import CONFIG, get_config_dir
from tryton.config import CONFIG, copy_previous_configuration, get_config_dir
from tryton.gui.window.dblogin import DBLogin


Expand Down
49 changes: 43 additions & 6 deletions tryton/tryton/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,57 @@
_ = gettext.gettext


def get_config_dir():
def _reverse_series_iterator(starting_version):
major, minor = map(int, starting_version.split('.'))
while major >= 0 and minor >= 0:
yield f"{major}.{minor}"
if minor == 0:
major -= 1
minor = 8
else:
minor -= 2 if not minor % 2 else 1


def copy_previous_configuration(config_element):
current_version = __version__.rsplit('.', 1)[0]
config_dir = get_config_root()
for version in _reverse_series_iterator(current_version):
config_path = os.path.join(config_dir, version, config_element)
if version == current_version and os.path.exists(config_path):
break
elif os.path.exists(config_path):
if os.path.isfile(config_path):
shutil.copy(config_path, get_config_dir())
elif os.path.isdir(config_path):
shutil.copytree(
config_path,
os.path.join(get_config_dir(), config_element))
break


def get_config_root():
if os.name == 'nt':
appdata = os.environ['APPDATA']
if not isinstance(appdata, str):
appdata = str(appdata, sys.getfilesystemencoding())
return os.path.join(appdata, '.config', 'tryton',
__version__.rsplit('.', 1)[0])
config_path = os.getenv('XDG_CONFIG_HOME', os.path.join('~', '.config'))
return os.path.expanduser(
os.path.join(config_path, 'tryton', __version__.rsplit('.', 1)[0]))
config_path = os.path.join(appdata, '.config')
else:
config_path = os.path.expanduser(os.getenv(
'XDG_CONFIG_HOME', os.path.join('~', '.config')))
return os.path.join(config_path, 'tryton')


def get_config_dir():
return os.path.join(get_config_root(), __version__.rsplit('.', 1)[0])


if not os.path.isdir(get_config_dir()):
os.makedirs(get_config_dir(), 0o700)
copy_previous_configuration('tryton.conf')
copy_previous_configuration('known_hosts')
copy_previous_configuration('accel_map')
copy_previous_configuration('profiles.cfg')
copy_previous_configuration('plugins')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour moi ça c'est bon, ça évite de tenter de copier à chaque fois qu'on lancer le client.



class ConfigManager(object):
Expand Down
2 changes: 1 addition & 1 deletion tryton/tryton/gui/window/dblogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def __init__(self):
temp_name = temp_file.name
shutil.copy(self.profile_cfg, temp_name)
logger.error(
f"Failed to parse {self.profiles_cfg}. "
f"Failed to parse {self.profile_cfg}. "
f"A backup can be found at {temp_name}",
exc_info=True)
for section in self.profiles.sections():
Expand Down