Refactoring the sdc-BE-init python scripts
[sdc.git] / catalog-be / src / main / resources / scripts / sdcBePy / tosca / imports / run.py
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5
6 import sdcBePy.common.logger as logger
7 from sdcBePy.common.normative.main import process_element_list, process_type_list
8 from sdcBePy.common.sdcBeProxy import SdcBeProxy
9 from sdcBePy.tosca.main import get_args, usage
10 from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
11     get_normative_element_with_metadata_list
12 from sdcBePy.tosca.models.normativeTypesList import get_normative_type_candidate_list
13
14
15 def main():
16     scheme, be_host, be_port, admin_user, update_version, debug = get_args()
17
18     if debug is False:
19         print('Disabling debug mode')
20         logger.debugFlag = debug
21
22     try:
23         sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug)
24     except AttributeError:
25         usage()
26         sys.exit(3)
27
28     # use to run script form this dir (not like the command)
29     # base_file_location = os.getcwd() + "/../../../../import/tosca/"
30     base_file_location = os.getcwd() + os.path.sep
31     logger.debug("working directory =" + base_file_location)
32
33     process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy)
34     process_type_list(get_normative_type_candidate_list(base_file_location), sdc_be_proxy, update_version)
35     process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
36
37     logger.log("Script end ->", "All normatives imported successfully!")
38     logger.error_and_exit(0, None)
39
40
41 if __name__ == "__main__":
42     main()