blob: 498ed30ebe6f54325a9f8ee9f5122121c761d876 [file] [log] [blame]
Alex265f45e2019-04-23 18:51:23 -05001import argparse
Alex Savatieievc9055712019-03-01 14:43:56 -06002import os
Alex265f45e2019-04-23 18:51:23 -05003import sys
Alex Savatieievc9055712019-03-01 14:43:56 -06004
5from cfg_checker.common.exception import ConfigException
6
7
Alex265f45e2019-04-23 18:51:23 -05008class MyParser(argparse.ArgumentParser):
9 def error(self, message):
10 sys.stderr.write('Error: {0}\n\n'.format(message))
11 self.print_help()
12
13
Alexe9908f72020-05-19 16:04:53 -050014def get_skip_args(args):
15 if hasattr(args, "skip_nodes"):
16 _skip = getattr(args, "skip_nodes")
17 if _skip:
18 _skip = _skip.split(',')
19 else:
20 _skip = None
21 if hasattr(args, "skip_nodes_file"):
22 _skip_file = getattr(args, "skip_nodes_file")
23 else:
24 _skip_file = None
25 return _skip, _skip_file
26
27
Alex41485522019-04-12 17:26:18 -050028def get_arg(args, str_arg):
29 _attr = getattr(args, str_arg)
30 if _attr:
31 return _attr
Alex Savatieievc9055712019-03-01 14:43:56 -060032 else:
Alex41485522019-04-12 17:26:18 -050033 _c = args.command if hasattr(args, 'command') else ''
34 _t = args.type if hasattr(args, 'type') else ''
35 raise ConfigException(
Alexe0c5b9e2019-04-23 18:51:23 -050036 "Argument '{}' not found executing: mcp-check {} {}".format(
Alex41485522019-04-12 17:26:18 -050037 str_arg,
38 _c,
39 _t
40 )
41 )
Alex Savatieievc9055712019-03-01 14:43:56 -060042
43
44def get_path_arg(path):
45 if os.path.exists(path):
46 return path
47 else:
48 raise ConfigException("'{}' not exists".format(path))
Alex41485522019-04-12 17:26:18 -050049
50
Alexbab1efe2019-04-23 18:51:23 -050051def get_network_map_type_and_filename(args):
52 if args.html or args.text:
53 if args.html and args.text:
54 raise ConfigException("Multuple report types not supported")
55 if args.html is not None:
56 return 'html', args.html
57 if args.text is not None:
58 return 'text', args.text
59 else:
60 return 'console', None
61
62
63def get_package_report_type_and_filename(args):
Alex41485522019-04-12 17:26:18 -050064 if args.html or args.csv:
65 if args.html and args.csv:
66 raise ConfigException("Multuple report types not supported")
67 if args.html is not None:
68 return 'html', args.html
69 if args.csv is not None:
70 return 'csv', args.csv
71 else:
72 raise ConfigException("Report type and filename not set")