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