comparison sat/tools/config.py @ 3281:a3639d6d9643

core: replaced `sat` shell script by a python script: the backend is now launched by `sat.core.launcher`, and the script is generated during installation with a new entry point in `setup.py`.
author Goffi <goffi@goffi.org>
date Mon, 25 May 2020 15:50:01 +0200
parents 60a9e47ef988
children be6d91572633
comparison
equal deleted inserted replaced
3280:96b9b65b4368 3281:a3639d6d9643
32 32
33 log = getLogger(__name__) 33 log = getLogger(__name__)
34 34
35 35
36 def fixConfigOption(section, option, value, silent=True): 36 def fixConfigOption(section, option, value, silent=True):
37 """Force a configuration option value, writing it in the first found user 37 """Force a configuration option value
38 config file, eventually creating a new user config file if none is found. 38
39 the option will be written in the first found user config file, a new user
40 config will be created if none is found.
39 41
40 @param section (str): the config section 42 @param section (str): the config section
41 @param option (str): the config option 43 @param option (str): the config option
42 @param value (str): the new value 44 @param value (str): the new value
43 @param silent (boolean): toggle logging output (must be True when called from sat.sh) 45 @param silent (boolean): toggle logging output (must be True when called from sat.sh)
66 if option in ("passphrase",): # list here the options storing a password 68 if option in ("passphrase",): # list here the options storing a password
67 value = "******" 69 value = "******"
68 log.warning(_("Config auto-update: {option} set to {value} in the file " 70 log.warning(_("Config auto-update: {option} set to {value} in the file "
69 "{config_file}.").format(option=option, value=value, 71 "{config_file}.").format(option=option, value=value,
70 config_file=target_file)) 72 config_file=target_file))
71
72
73 # XXX: tmp update code, will be removed in the future
74 # When you remove this, please add the default value for
75 # 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG
76 def fixLocalDir(silent=True):
77 """Retro-compatibility with the previous local_dir default value.
78
79 @param silent (boolean): toggle logging output (must be True when called from sat.sh)
80 """
81 user_config = ConfigParser()
82 try:
83 user_config.read(C.CONFIG_FILES)
84 except:
85 pass # file is readable but its structure if wrong
86 try:
87 current_value = user_config.get("DEFAULT", "local_dir")
88 except (NoOptionError, NoSectionError):
89 current_value = ""
90 if current_value:
91 return # nothing to do
92 old_default = "~/.sat"
93 if os.path.isfile(os.path.expanduser(old_default) + "/" + C.SAVEFILE_DATABASE):
94 if not silent:
95 log.warning(_(
96 "A database has been found in the default local_dir for previous "
97 "versions (< 0.5)"
98 ))
99 fixConfigOption("", "local_dir", old_default, silent)
100 73
101 74
102 def parseMainConf(log_filenames=False): 75 def parseMainConf(log_filenames=False):
103 """Look for main .ini configuration file, and parse it 76 """Look for main .ini configuration file, and parse it
104 77