-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.py
57 lines (45 loc) · 2.19 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from config.constances import PARSER_CLASSES, TESTS_PATH, PARSERS_PATH, PARSERS_NAMES_TO_FIX
from config.enums import SourceTypes
def check_keys_parser_classes():
"""
Check that all parsers are in PARSER_CLASSES const
:return:
"""
parsers_dir = os.listdir(PARSERS_PATH)
set_parsers_classes = set(PARSER_CLASSES.keys())
exists_parsers: set[str] = set()
for parser_file in parsers_dir:
parser_file = parser_file.replace(".py", "")
if (
parser_file not in ("__init__", "abstract", "__pycache__")
):
if parser_file not in PARSER_CLASSES:
raise ValueError(f"Parser {parser_file} not in PARSER_CLASSES")
exists_parsers.add(parser_file)
for directory in os.listdir(TESTS_PATH):
if os.path.isdir(os.path.join(TESTS_PATH, directory)):
for scanner in os.listdir(os.path.join(TESTS_PATH, directory)):
if scanner in PARSER_CLASSES:
exists_parsers.add(scanner)
if xor_set := exists_parsers.symmetric_difference(set_parsers_classes):
raise ValueError(f"{xor_set} scanners are not provided")
def validate_args(args):
# Приведение к нижнему регистру и замена "-" на "_" если scanner в PARSERS_NAMES_TO_FIX
args.type = args.type.lower()
args.scanner = args.scanner.replace('-', '_') if args.scanner in PARSERS_NAMES_TO_FIX else args.scanner
if args.format is None:
if args.scanner not in PARSER_CLASSES.keys():
raise ValueError("scanner is not supported, provide format if available")
args.format = args.scanner
if args.type == SourceTypes.CODEBASE.value:
if not args.url or not args.name:
raise ValueError("url and name are required for CODEBASE source_type")
elif args.type == SourceTypes.INSTANCE.value:
if not args.url or not args.name:
raise ValueError("url is required for INSTANCE source_type")
elif args.type == SourceTypes.ARTIFACT.value:
if not args.url or not args.name:
raise ValueError("url is required for ARTIFACT source_type")
else:
raise ValueError("Invalid source type")