diff options
author | 2020-02-28 14:26:07 +0100 | |
---|---|---|
committer | 2020-03-23 09:48:56 +0000 | |
commit | 5944b441468500fffa7111b5dea9181461ae1303 (patch) | |
tree | 9b358b2d25a309c1d6dfd86227ec75b52b2ccefa /catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py | |
parent | ec7da6aea30a1b73d1e0f5f75d2b6119ed8fa251 (diff) |
Refactoring the sdc-BE-init python scripts
Adjust to the correct python syntax.
Remove not used imports.
Also fixed:
- the indents
- checking that all normative imported correctly logic
Issue-ID: SDC-2784
Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Change-Id: If7edc867f3cb591be157073fbc12b9842b200023
Diffstat (limited to 'catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py')
-rw-r--r-- | catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py | 110 |
1 files changed, 54 insertions, 56 deletions
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py index e0f5c40ac9..989233d380 100644 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py @@ -1,11 +1,7 @@ -import pycurl -import sys, getopt -from StringIO import StringIO -import json -import copy -from importNormativeElements import createNormativeElement +import importCommon from importCommon import * -import importCommon +from importNormativeElements import createNormativeElement + ################################################################################################################################################################################################# # # @@ -19,62 +15,64 @@ import importCommon # # ################################################################################################################################################################################################# - + def usage(): - print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + print sys.argv[0], \ + '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + +def importNormativeCapabilities(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): + result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, + "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes", + "capabilityTypeZip") -def importNormativeCapabilities(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir): - result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes", "capabilityTypeZip") - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() + print_frame_line() + print_name_and_return_code(result[0], result[1]) + print_frame_line() - if ( result[1] == None or result[1] not in [200, 201, 409] ): - importCommon.error_and_exit(1, None) - else: - if (exitOnSuccess == True): - importCommon.error_and_exit(0, None) + if result[1] is None or result[1] not in [200, 201, 409]: + importCommon.error_and_exit(1, None) + else: + if exit_on_success is True: + importCommon.error_and_exit(0, None) def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - beHost = 'localhost' - bePort = '8080' - adminUser = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv,"i:p:u:h:s:",["ip=","port=","user=","scheme="]) - except getopt.GetoptError: - usage() - importCommon.error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - #print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - beHost = arg - elif opt in ("-p", "--port"): - bePort = arg - elif opt in ("-u", "--user"): - adminUser = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser - - if ( beHost == None ): - usage() - sys.exit(3) - - importNormativeCapabilities(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/capability-types/") + print 'Number of arguments:', len(sys.argv), 'arguments.' + be_host = 'localhost' + be_port = '8080' + admin_user = 'jh0003' + scheme = 'http' -if __name__ == "__main__": - main(sys.argv[1:]) + try: + opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) + except getopt.GetoptError: + usage() + importCommon.error_and_exit(2, 'Invalid input') + for opt, arg in opts: + # print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + be_host = arg + elif opt in ("-p", "--port"): + be_port = arg + elif opt in ("-u", "--user"): + admin_user = arg + elif opt in ("-s", "--scheme"): + scheme = arg + + print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user + + if be_host is None: + usage() + sys.exit(3) + + importNormativeCapabilities(scheme, be_host, be_port, admin_user, True, "../../../import/tosca/capability-types/") + + +if __name__ == "__main__": + main(sys.argv[1:]) |