diff sat/tools/config.py @ 3053:8b36e5c3f28f

misc: don't import memory in launch script: launch script was importing a method from memory (fixLocalDir), but memory is importing twisted.internet.reactor which can result to a ReactorAlreadyInstalledError. This patch fixes it by moving fixLocalDir to tools/config. The launch script is now using /usr/bin/env.
author Goffi <goffi@goffi.org>
date Tue, 08 Oct 2019 12:10:26 +0200
parents 98d1f34ce5b9
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat/tools/config.py	Mon Oct 07 17:29:28 2019 +0200
+++ b/sat/tools/config.py	Tue Oct 08 12:10:26 2019 +0200
@@ -70,6 +70,35 @@
                                                 config_file=target_file))
 
 
+# XXX: tmp update code, will be removed in the future
+# When you remove this, please add the default value for
+# 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG
+def fixLocalDir(silent=True):
+    """Retro-compatibility with the previous local_dir default value.
+
+    @param silent (boolean): toggle logging output (must be True when called from sat.sh)
+    """
+    user_config = ConfigParser()
+    try:
+        user_config.read(C.CONFIG_FILES)
+    except:
+        pass  # file is readable but its structure if wrong
+    try:
+        current_value = user_config.get("DEFAULT", "local_dir")
+    except (NoOptionError, NoSectionError):
+        current_value = ""
+    if current_value:
+        return  # nothing to do
+    old_default = "~/.sat"
+    if os.path.isfile(os.path.expanduser(old_default) + "/" + C.SAVEFILE_DATABASE):
+        if not silent:
+            log.warning(_(
+                "A database has been found in the default local_dir for previous "
+                "versions (< 0.5)"
+            ))
+        fixConfigOption("", "local_dir", old_default, silent)
+
+
 def parseMainConf():
     """look for main .ini configuration file, and parse it"""
     config = ConfigParser(defaults=C.DEFAULT_CONFIG)