diff sat/tools/config.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 0fa217fafabf
line wrap: on
line diff
--- a/sat/tools/config.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/tools/config.py	Wed Jun 27 20:14:46 2018 +0200
@@ -21,6 +21,7 @@
 """ Configuration related useful methods """
 
 from sat.core.log import getLogger
+
 log = getLogger(__name__)
 
 from sat.core.constants import Const as C
@@ -50,23 +51,28 @@
         if not silent:
             log.debug(_(u"Testing file %s") % file_)
         if os.path.isfile(file_):
-            if file_.startswith(os.path.expanduser('~')):
+            if file_.startswith(os.path.expanduser("~")):
                 config.read([file_])
                 target_file = file_
             break
     if not target_file:
         # ... otherwise we create a new config file for that user
-        target_file = BaseDirectory.save_config_path('sat') + '/sat.conf'
+        target_file = BaseDirectory.save_config_path("sat") + "/sat.conf"
     if section and section.upper() != DEFAULTSECT and not config.has_section(section):
         config.add_section(section)
     config.set(section, option, value)
-    with open(target_file, 'wb') as configfile:
+    with open(target_file, "wb") as configfile:
         config.write(configfile)  # for the next time that user launches sat
     if not silent:
-        if option in ('passphrase',):  # list here the options storing a password
-            value = '******'
-        log.warning(_(u"Config auto-update: %(option)s set to %(value)s in the file %(config_file)s") %
-                    {'option': option, 'value': value, 'config_file': target_file})
+        if option in ("passphrase",):  # list here the options storing a password
+            value = "******"
+        log.warning(
+            _(
+                u"Config auto-update: %(option)s set to %(value)s in the file %(config_file)s"
+            )
+            % {"option": option, "value": value, "config_file": target_file}
+        )
+
 
 def parseMainConf():
     """look for main .ini configuration file, and parse it"""
@@ -77,6 +83,7 @@
         log.error(_("Can't read main config !"))
     return config
 
+
 def getConfig(config, section, name, default=None):
     """Get a configuration option
 
@@ -93,25 +100,29 @@
         section = DEFAULTSECT
 
     try:
-        value = config.get(section, name).decode('utf-8')
+        value = config.get(section, name).decode("utf-8")
     except (NoOptionError, NoSectionError) as e:
         if default is Exception:
             raise e
         return default
 
-    if name.endswith('_path') or name.endswith('_dir'):
+    if name.endswith("_path") or name.endswith("_dir"):
         value = os.path.expanduser(value)
     # thx to Brian (http://stackoverflow.com/questions/186857/splitting-a-semicolon-separated-string-to-a-dictionary-in-python/186873#186873)
-    elif name.endswith('_list'):
-        value = csv.reader([value], delimiter=',', quotechar='"', skipinitialspace=True).next()
-    elif name.endswith('_dict'):
+    elif name.endswith("_list"):
+        value = csv.reader(
+            [value], delimiter=",", quotechar='"', skipinitialspace=True
+        ).next()
+    elif name.endswith("_dict"):
         try:
             value = json.loads(value)
         except ValueError as e:
             raise exceptions.ParsingError(u"Error while parsing data: {}".format(e))
         if not isinstance(value, dict):
-            raise exceptions.ParsingError(u"{name} value is not a dict: {value}".format(name=name, value=value))
-    elif name.endswith('_json'):
+            raise exceptions.ParsingError(
+                u"{name} value is not a dict: {value}".format(name=name, value=value)
+            )
+    elif name.endswith("_json"):
         try:
             value = json.loads(value)
         except ValueError as e: