diff options
author | k.kedron <k.kedron@partner.samsung.com> | 2020-02-28 14:26:07 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-03-23 09:48:56 +0000 |
commit | 5944b441468500fffa7111b5dea9181461ae1303 (patch) | |
tree | 9b358b2d25a309c1d6dfd86227ec75b52b2ccefa /catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.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/importNormativeAll.py')
-rw-r--r-- | catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py | 121 |
1 files changed, 58 insertions, 63 deletions
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py index e4f536ff85..c61b8bcc03 100644 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py @@ -1,23 +1,18 @@ -import pycurl -import sys, getopt, os -from StringIO import StringIO -import json -import copy +import os import time -# from importNormativeElements import createNormativeElement -from importNormativeElements import * -from importNormativeTypes import importNormativeTypes -from importHeatTypes import importHeatTypes -from importNormativeCapabilities import importNormativeCapabilities -from importNormativeRelationships import importNormativeRelationships + +import importCommon +from importAnnotationTypes import import_annotation_types from importCategoryTypes import importCategories -from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType +from importCommon import * from importDataTypes import importDataTypes from importGroupTypes import importGroupTypes +from importHeatTypes import importHeatTypes +from importNormativeCapabilities import importNormativeCapabilities +from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType +from importNormativeRelationships import importNormativeRelationships +from importNormativeTypes import importNormativeTypes from importPolicyTypes import importPolicyTypes -from importAnnotationTypes import import_annotation_types -from importCommon import * -import importCommon ################################################################################################################################################################################################################################# @@ -34,34 +29,34 @@ 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> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]' + 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> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]' -def handleResults(results, updateversion): +def handleResults(results, update_version): print_frame_line() for result in results: print_name_and_return_code(result[0], result[1]) print_frame_line() - responseCodes = [200, 201] + response_codes = [200, 201] - if (updateversion == 'false'): - responseCodes = [200, 201, 409] + if update_version == 'false': + response_codes = [200, 201, 409] - failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results) - if (len(failedResults) > 0): + failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results) + if len(list(failed_results)) > 0: error_and_exit(1, None) def main(argv): print 'Number of arguments:', len(sys.argv), 'arguments.' - beHost = 'localhost' - bePort = '8080' - adminUser = 'jh0003' - debugf = None - updateversion = 'true' + be_host = 'localhost' + be_port = '8080' + admin_user = 'jh0003' + debug_f = None + update_version = 'true' importCommon.debugFlag = False scheme = 'http' @@ -78,70 +73,70 @@ def main(argv): usage() sys.exit(3) elif opt in ("-i", "--ip"): - beHost = arg + be_host = arg elif opt in ("-p", "--port"): - bePort = arg + be_port = arg elif opt in ("-u", "--user"): - adminUser = arg + admin_user = arg elif opt in ("-s", "--scheme"): scheme = arg elif opt in ("-d", "--debug"): print arg - debugf = bool(arg.lower() == "true" or arg.lower() == "yes") + debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") elif opt in ("-v", "--updateversion"): print arg - if (arg.lower() == "false" or arg.lower() == "no"): - updateversion = 'false' + if arg.lower() == "false" or arg.lower() == "no": + update_version = 'false' - print 'scheme =', scheme, ', be host =', beHost, ', be port =', bePort, ', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion + print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version - if (debugf != None): - print 'set debug mode to ' + str(debugf) - importCommon.debugFlag = debugf + if debug_f is not None: + print 'set debug mode to ' + str(debug_f) + importCommon.debugFlag = debug_f - if (beHost == None): + if be_host is None: usage() sys.exit(3) print sys.argv[0] - pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + pathdir) + path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) + debug("path dir =" + path_dir) - baseFileLocation = pathdir + "/../../../import/tosca/" + base_file_location = path_dir + "/../../../import/tosca/" - fileLocation = baseFileLocation + "data-types/" - importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "data-types/" + importDataTypes(scheme, be_host, be_port, admin_user, False, file_location) print 'sleep until data type cache is updated' time.sleep(70) - fileLocation = baseFileLocation + "capability-types/" - importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "capability-types/" + importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "relationship-types/" - importNormativeRelationships(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "relationship-types/" + importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "interface-lifecycle-types/" - importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "interface-lifecycle-types/" + importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "categories/" - importCategories(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "categories/" + importCategories(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "normative-types/" - results = importNormativeTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion) - handleResults(results, updateversion) + file_location = base_file_location + "normative-types/" + results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version) + handleResults(results, update_version) - fileLocation = baseFileLocation + "heat-types/" - resultsHeat = importHeatTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion) - handleResults(resultsHeat, updateversion) + file_location = base_file_location + "heat-types/" + results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version) + handleResults(results_heat, update_version) - fileLocation = baseFileLocation + "group-types/" - importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "group-types/" + importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "policy-types/" - importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "policy-types/" + importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location) - import_annotation_types(scheme, beHost, bePort, adminUser, False) + import_annotation_types(scheme, be_host, be_port, admin_user, False) error_and_exit(0, None) |