From 2136d199e6ec605747728f3ab9cbe433294d6c1b Mon Sep 17 00:00:00 2001 From: Amy S <159793890+amy-gb@users.noreply.github.com> Date: Thu, 4 Jul 2024 09:36:26 +0200 Subject: [PATCH] PR review update: minor refactors --- troubadix/standalone_plugins/deprecate_vts.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/troubadix/standalone_plugins/deprecate_vts.py b/troubadix/standalone_plugins/deprecate_vts.py index c52fc9ae..444becd6 100644 --- a/troubadix/standalone_plugins/deprecate_vts.py +++ b/troubadix/standalone_plugins/deprecate_vts.py @@ -30,7 +30,7 @@ class DeprecatedFile: content: str -KB_ITEMS = re.compile(r"set_kb_item\(.+\);") +KB_ITEMS_PATTERN = re.compile(r"set_kb_item\(.+\);") def update_summary(file: DeprecatedFile, deprecation_reason: str) -> str: @@ -51,9 +51,7 @@ def update_summary(file: DeprecatedFile, deprecation_reason: str) -> str: print(f"No summary in: {file.name}") return file.content - deprecate_text = "Note: This VT has been deprecated " + DEPRECATIONS.get( - deprecation_reason - ) + deprecate_text = f"Note: This VT has been deprecated {DEPRECATIONS[deprecation_reason]}" new_summary = old_summary + "\n" + deprecate_text file.content = file.content.replace(old_summary, new_summary) @@ -88,6 +86,7 @@ def filter_files( DeprecatedFile objects Args: + files: a list of files to deprecate, should be .nasl VTs filename_prefix: an optional prefix to filter only specific files Returns: @@ -139,7 +138,7 @@ def deprecate( """ output_path.mkdir(parents=True, exist_ok=True) for file in to_deprecate: - if re.findall(KB_ITEMS, file.content): + if re.findall(KB_ITEMS_PATTERN, file.content): print( f"Unable to deprecate {file.name}. There are still KB keys " f"remaining." @@ -204,7 +203,7 @@ def parse_args(args: Iterable[str] = None) -> Namespace: "-r", "--deprecation-reason", metavar="", - choices=["notus", "merged", "duplicate", "defunct"], + choices=DEPRECATIONS.keys(), type=str, help="The reason the VT is being deprecated. Options are 'notus':" "The VT has been replaced by a new Notus VT. 'Merged': the VT has" @@ -217,7 +216,7 @@ def parse_args(args: Iterable[str] = None) -> Namespace: "-f", "--files", metavar="", - nargs="*", + nargs="+", default=None, type=file_type, help="Files to deprecate", @@ -235,14 +234,13 @@ def parse_args(args: Iterable[str] = None) -> Namespace: def main(): args = parse_args() - output_path = Path(args.output_path) - input_path = Path(args.input_path) if args.input_path else None + input_path = args.input_path if args.input_path else None filename_prefix = args.filename_prefix files = args.files or get_files_from_path(input_path) filtered_files = filter_files(files, filename_prefix) - deprecate(output_path, filtered_files, args.deprecation_reason) + deprecate(args.output_path, filtered_files, args.deprecation_reason) if __name__ == "__main__":