blob: 726c20ef96cca6eb0a0240d34053fe130b847a63 [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
Alex41485522019-04-12 17:26:18 -050014def get_arg(args, str_arg):
15 _attr = getattr(args, str_arg)
16 if _attr:
17 return _attr
Alex Savatieievc9055712019-03-01 14:43:56 -060018 else:
Alex41485522019-04-12 17:26:18 -050019 _c = args.command if hasattr(args, 'command') else ''
20 _t = args.type if hasattr(args, 'type') else ''
21 raise ConfigException(
Alexe0c5b9e2019-04-23 18:51:23 -050022 "Argument '{}' not found executing: mcp-check {} {}".format(
Alex41485522019-04-12 17:26:18 -050023 str_arg,
24 _c,
25 _t
26 )
27 )
Alex Savatieievc9055712019-03-01 14:43:56 -060028
29
30def get_path_arg(path):
31 if os.path.exists(path):
32 return path
33 else:
34 raise ConfigException("'{}' not exists".format(path))
Alex41485522019-04-12 17:26:18 -050035
36
Alexbab1efe2019-04-23 18:51:23 -050037def get_network_map_type_and_filename(args):
38 if args.html or args.text:
39 if args.html and args.text:
40 raise ConfigException("Multuple report types not supported")
41 if args.html is not None:
42 return 'html', args.html
43 if args.text is not None:
44 return 'text', args.text
45 else:
46 return 'console', None
47
48
49def get_package_report_type_and_filename(args):
Alex41485522019-04-12 17:26:18 -050050 if args.html or args.csv:
51 if args.html and args.csv:
52 raise ConfigException("Multuple report types not supported")
53 if args.html is not None:
54 return 'html', args.html
55 if args.csv is not None:
56 return 'csv', args.csv
57 else:
58 raise ConfigException("Report type and filename not set")