Merge upstream version
Related-PROD: PROD-28199
Change-Id: I5d9dbde1c3ac577fb30fa5d6b1ff18bcee28a0d7
diff --git a/cfg_checker/helpers/args_utils.py b/cfg_checker/helpers/args_utils.py
index d7b694d..f8453e4 100644
--- a/cfg_checker/helpers/args_utils.py
+++ b/cfg_checker/helpers/args_utils.py
@@ -3,11 +3,20 @@
from cfg_checker.common.exception import ConfigException
-def get_file_arg(args):
- if args.file:
- return args.file
+def get_arg(args, str_arg):
+ _attr = getattr(args, str_arg)
+ if _attr:
+ return _attr
else:
- raise ConfigException("No report filename supplied")
+ _c = args.command if hasattr(args, 'command') else ''
+ _t = args.type if hasattr(args, 'type') else ''
+ raise ConfigException(
+ "Argument '{}' not found executing: mcp_check {} {}".format(
+ str_arg,
+ _c,
+ _t
+ )
+ )
def get_path_arg(path):
@@ -15,3 +24,15 @@
return path
else:
raise ConfigException("'{}' not exists".format(path))
+
+
+def get_report_type_and_filename(args):
+ if args.html or args.csv:
+ if args.html and args.csv:
+ raise ConfigException("Multuple report types not supported")
+ if args.html is not None:
+ return 'html', args.html
+ if args.csv is not None:
+ return 'csv', args.csv
+ else:
+ raise ConfigException("Report type and filename not set")
diff --git a/cfg_checker/helpers/console_utils.py b/cfg_checker/helpers/console_utils.py
new file mode 100644
index 0000000..33e1a39
--- /dev/null
+++ b/cfg_checker/helpers/console_utils.py
@@ -0,0 +1,30 @@
+from time import sleep
+import sys
+
+
+class Progress(object):
+ def __init__(self, max_index, bar_size=21):
+ self.total = max_index
+ # bar size in symbols
+ self.bar_size = bar_size
+
+ def write_progress(self, index, note=''):
+ #calc index and percent values
+ _percent = (100 * index) / self.total
+ _index = (self.bar_size * index) / self.total
+ # clear the line
+ sys.stdout.write('\r')
+ # print new progress
+ _format = "[{:"+str(self.bar_size-1)+"}] {}/{} ({}%) {}"
+ sys.stdout.write(_format.format(
+ '='*_index,
+ index,
+ self.total,
+ _percent,
+ note
+ ))
+ sys.stdout.flush()
+
+ @staticmethod
+ def newline():
+ sys.stdout.write('\n')