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