]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
address code comments
authorSascha Steinbiss <satta@debian.org>
Sat, 19 Jan 2019 23:10:19 +0000 (00:10 +0100)
committerShivani Bhardwaj <shivanib134@gmail.com>
Wed, 3 Apr 2019 19:26:16 +0000 (00:56 +0530)
suricata/update/commands/enablesource.py

index 6bf72fb820ad4f3fddcab41615c173fb766327d7..121138542f0d24df5927b358b5ba812359b6ed7d 100644 (file)
@@ -40,13 +40,13 @@ def register(parser):
 
 def enable_source():
     name = config.args().name
-    updating = False
+    update_params = False
 
     # Check if source is already enabled.
     enabled_source_filename = sources.get_enabled_source_filename(name)
     if os.path.exists(enabled_source_filename):
         logger.warning("The source %s is already enabled.", name)
-        updating = True
+        update_params = True
 
     # First check if this source was previous disabled and then just
     # re-enable it.
@@ -54,7 +54,7 @@ def enable_source():
     if os.path.exists(disabled_source_filename):
         logger.info("Re-enabling previously disabled source for %s.", name)
         os.rename(disabled_source_filename, enabled_source_filename)
-        updating = True
+        update_params = True
 
     if not os.path.exists(sources.get_index_filename()):
         logger.warning("Source index does not exist, will use bundled one.")
@@ -73,34 +73,36 @@ def enable_source():
         opts[key] = val
 
     params = {}
-    if updating:
+    if update_params:
         source = yaml.safe_load(open(sources.get_enabled_source_filename(name), "rb"))
-        if "params" in source:
-            params = source["params"]
-            for old_param in source["params"]:
-                if old_param in opts and source["params"][old_param] != opts[old_param]:
-                    logger.info("Updating source parameter '%s': '%s' -> '%s'." % (
-                        old_param, source["params"][old_param], opts[old_param]))
-                    params[old_param] = opts[old_param]
     else:
         source = source_index.get_sources()[name]
 
-        if "subscribe-url" in source:
-            print("The source %s requires a subscription. Subscribe here:" % (name))
-            print("  %s" % source["subscribe-url"])
-
-        if "parameters" in source:
-            for param in source["parameters"]:
-                if param in opts:
-                    params[param] = opts[param]
-                else:
-                    prompt = source["parameters"][param]["prompt"]
-                    while True:
-                        r = input("%s (%s): " % (prompt, param))
-                        r = r.strip()
-                        if r:
-                            break
-                    params[param] = r.strip()
+    if "params" in source:
+        params = source["params"]
+        for old_param in source["params"]:
+            if old_param in opts and source["params"][old_param] != opts[old_param]:
+                logger.info("Updating source parameter '%s': '%s' -> '%s'." % (
+                    old_param, source["params"][old_param], opts[old_param]))
+                params[old_param] = opts[old_param]
+
+    if "subscribe-url" in source:
+        print("The source %s requires a subscription. Subscribe here:" % (name))
+        print("  %s" % source["subscribe-url"])
+
+    if "parameters" in source:
+        for param in source["parameters"]:
+            if param in opts:
+                params[param] = opts[param]
+            else:
+                prompt = source["parameters"][param]["prompt"]
+                while True:
+                    r = input("%s (%s): " % (prompt, param))
+                    r = r.strip()
+                    if r:
+                        break
+                params[param] = r.strip()
+
     new_source = sources.SourceConfiguration(name, params=params)
 
     # If the source directory does not exist, create it. Also create