Decouple TXT Report file writing and formatting logic (6/6)
[sdc.git] / catalog-be / src / main / resources / scripts / import / tosca / importCommon.py
1 import getopt
2 import sys
3
4 ###############################################################################################################
5 #
6 #
7 ###############################################################################################################
8
9 debugFlag = True
10
11
12 def join_strings(lst):
13     concat = ""
14     for string in lst:
15         if string is not None:
16             if type(string) == int:
17                 string = str(string)
18             concat += (string + " ")
19     return concat
20
21
22 def debug(desc, *args):
23     if debugFlag:
24         print desc, join_strings(args)
25
26
27 def is_debug():
28     return debugFlag
29
30
31 def log(desc, arg=None):
32     print desc, arg
33
34
35 def error_and_exit(error_code, error_desc):
36     if error_code > 0:
37         print "status={0}. {1}".format(error_code, '' if error_desc is None else error_desc)
38     else:
39         print "status={0}".format(error_code)
40     sys.exit(error_code)
41
42
43 def print_name_and_return_code(name, code):
44     print "{0:30} | {1:6}".format(name, code)
45
46
47 def print_frame_line():
48     print "----------------------------------------"
49
50
51 def parse_cmd_line_params(argv):
52     print 'Number of arguments:', len(sys.argv), 'arguments.'
53
54     be_host = 'localhost'
55     be_port = '8080'
56     admin_user = 'jh0003'
57     scheme = 'http'
58
59     try:
60         opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
61     except getopt.GetoptError:
62         usage()
63         error_and_exit(2, 'Invalid input')
64
65     for opt, arg in opts:
66         # print opt, arg
67         if opt == '-h':
68             usage()
69             sys.exit(3)
70         elif opt in ("-i", "--ip"):
71             be_host = arg
72         elif opt in ("-p", "--port"):
73             be_port = arg
74         elif opt in ("-u", "--user"):
75             admin_user = arg
76         elif opt in ("-s", "--scheme"):
77             scheme = arg
78
79     print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
80
81     if be_host is None:
82         usage()
83         sys.exit(3)
84     return scheme, be_host, be_port, admin_user
85
86
87 def usage():
88     print sys.argv[
89         0], '[optional -s <scheme> | --scheme=<scheme>, default http ] [-i <be host> | --ip=<be host>] [-p <be port> ' \
90             '| --port=<be port> ] [-u <user userId> | --user=<user userId> ] '