[tor-commits] [sbws/master] Stop creating user configuration if it does not exists

pastly at torproject.org pastly at torproject.org
Thu Aug 9 14:21:20 UTC 2018


commit 2b9fcca8e00ff09fe386f2767b8a162e3f8eed07
Author: juga0 <juga at riseup.net>
Date:   Tue Jul 24 18:19:13 2018 +0000

    Stop creating user configuration if it does not exists
---
 sbws/util/config.py | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index 99c7d67..d6bb115 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -1,5 +1,4 @@
 """Util functions to manage sbws configuration files."""
-import shutil
 
 from configparser import (ConfigParser, ExtendedInterpolation)
 from configparser import InterpolationMissingOptionError
@@ -10,7 +9,7 @@ from urllib.parse import urlparse
 from string import Template
 from tempfile import NamedTemporaryFile
 from sbws.globals import (DEFAULT_CONFIG_PATH, DEFAULT_LOG_CONFIG_PATH,
-                          MINIMUM_USER_CONFIG_PATH, USER_CONFIG_PATH)
+                          USER_CONFIG_PATH, fail_hard)
 
 _ALPHANUM = 'abcdefghijklmnopqrstuvwxyz'
 _ALPHANUM += _ALPHANUM.upper()
@@ -32,12 +31,6 @@ def _expand_path(path):
     return os.path.expanduser(os.path.expandvars(path))
 
 
-def _create_user_config_file(fname):
-    """Copy minimal user config to user config path."""
-    if not os.path.isfile(fname):
-        shutil.copyfile(MINIMUM_USER_CONFIG_PATH, fname)
-
-
 def _extend_config(conf, fname):
     """Extend ConfigParser from file configuration."""
     log.debug('Reading config file %s', fname)
@@ -66,14 +59,12 @@ def _get_user_config(args, conf=None):
         assert isinstance(conf, ConfigParser)
     if args.config:
         if not os.path.isfile(args.config):
-            log.warning('Configuration file %s not found, '
-                        'using default configuration, and creating a minimal '
-                        'configuration in %s.', args.config, args.config)
-            _create_user_config_file(args.config)
-            return conf
+            fail_hard('Configuration file %s not found.', args.config)
         return _extend_config(conf, args.config)
-    _create_user_config_file(USER_CONFIG_PATH)
-    return _extend_config(conf, USER_CONFIG_PATH)
+    if os.path.isfile(USER_CONFIG_PATH):
+        return _extend_config(conf, USER_CONFIG_PATH)
+    log.debug('No user config found.')
+    return conf
 
 
 def _get_default_logging_config(conf=None):





More information about the tor-commits mailing list