comparison sat/tools/config.py @ 3482:acb28399480f

tools (config): show a warning when no config file has been found + don't use hardcoded filename in `fixConfigOption`
author Goffi <goffi@goffi.org>
date Sat, 20 Mar 2021 20:42:07 +0100
parents be6d91572633
children 3c7a64d6f49f
comparison
equal deleted inserted replaced
3481:7892585b7e17 3482:acb28399480f
56 config.read([file_]) 56 config.read([file_])
57 target_file = file_ 57 target_file = file_
58 break 58 break
59 if not target_file: 59 if not target_file:
60 # ... otherwise we create a new config file for that user 60 # ... otherwise we create a new config file for that user
61 target_file = BaseDirectory.save_config_path("sat") + "/sat.conf" 61 target_file = (
62 f"{BaseDirectory.save_config_path(C.APP_NAME_FILE)}/{C.APP_NAME_FILE}.conf"
63 )
62 if section and section.upper() != DEFAULTSECT and not config.has_section(section): 64 if section and section.upper() != DEFAULTSECT and not config.has_section(section):
63 config.add_section(section) 65 config.add_section(section)
64 config.set(section, option, value) 66 config.set(section, option, value)
65 with open(target_file, "wb") as configfile: 67 with open(target_file, "wb") as configfile:
66 config.write(configfile) # for the next time that user launches sat 68 config.write(configfile) # for the next time that user launches sat
82 filenames = config.read(C.CONFIG_FILES) 84 filenames = config.read(C.CONFIG_FILES)
83 except Exception as e: 85 except Exception as e:
84 log.error(_("Can't read main config: {msg}").format(msg=e), exc_info=True) 86 log.error(_("Can't read main config: {msg}").format(msg=e), exc_info=True)
85 else: 87 else:
86 if log_filenames: 88 if log_filenames:
87 log.info( 89 if filenames:
88 _("Configuration was read from: {filenames}").format( 90 log.info(
89 filenames=', '.join(filenames))) 91 _("Configuration was read from: {filenames}").format(
92 filenames=', '.join(filenames)))
93 else:
94 log.warning(
95 _("No configuration file found, using default settings")
96 )
90 97
91 return config 98 return config
92 99
93 100
94 def getConfig(config, section, name, default=None): 101 def getConfig(config, section, name, default=None):