TLS sdc-be-init: truststore & keystore handling
[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=None):
16     if arg:
17         print(desc, arg)
18     else:
19         print(desc)
20
21
22 def print_and_exit(error_code, error_desc):
23     if error_code > 0:
24         print("status={0}. {1}".format(error_code, '' if not error_desc else error_desc))
25     else:
26         print("status={0}".format(error_code))
27     sys.exit(error_code)
28
29
30 def print_name_and_return_code(name, code, with_line=True):
31     if _strings_correct(name, code):
32         if with_line:
33             print("----------------------------------------")
34         print("{0:30} | {1:6}".format(name, code))
35         if with_line:
36             print("----------------------------------------")
37     else:
38         print("name of the item or return code from request is none -> error occurred!!")
39
40
41 def _strings_correct(*strings):
42     results = [(string is not None and string != "") for string in strings]
43     return all(results) is True
44
45 # def parse_cmd_line_params(argv):
46 #     print('Number of arguments:', len(sys.argv), 'arguments.')
47 #
48 #     opts = []
49 #
50 #     be_host = 'localhost'
51 #     be_port = '8080'
52 #     admin_user = 'jh0003'
53 #     scheme = 'http'
54 #
55 #     try:
56 #         opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
57 #     except getopt.GetoptError:
58 #         usage()
59 #         error_and_exit(2, 'Invalid input')
60 #
61 #     for opt, arg in opts:
62 #         # print opt, arg
63 #         if opt == '-h':
64 #             usage()
65 #             sys.exit(3)
66 #         elif opt in ("-i", "--ip"):
67 #             be_host = arg
68 #         elif opt in ("-p", "--port"):
69 #             be_port = arg
70 #         elif opt in ("-u", "--user"):
71 #             admin_user = arg
72 #         elif opt in ("-s", "--scheme"):
73 #             scheme = arg
74 #
75 #     print('scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user)
76 #
77 #     if be_host is None:
78 #         usage()
79 #         sys.exit(3)
80 #     return scheme, be_host, be_port, admin_user
81 #
82 #
83 # def usage():
84 #     print(sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http ] '
85 #                        '[-i <be host> | --ip=<be host>] [-p <be port> | '
86 #                        '--port=<be port> ] [-u <user userId> | --user=<user userId> ] ')