From: Sascha Steinbiss Date: Sat, 19 Jan 2019 23:10:19 +0000 (+0100) Subject: address code comments X-Git-Tag: 1.1.0rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d75a5d45188c7d4b08f605394cbf888a8cd728b;p=thirdparty%2Fsuricata-update.git address code comments --- diff --git a/suricata/update/commands/enablesource.py b/suricata/update/commands/enablesource.py index 6bf72fb..1211385 100644 --- a/suricata/update/commands/enablesource.py +++ b/suricata/update/commands/enablesource.py @@ -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