1- import logging
1+ """
2+ Tool to migrate a given cedar template from one version to another.
3+
4+ Requites an env variable "CEDAR_PROPERTIES" to be set. see ./tests/test_resources/cedar_config_file.properties
5+ The env variable would be the absolute path to the location of that properties file
6+
7+ run parameters
8+
9+ -r - the url copied from CEDAR for the instance
10+ -s - source version, e.g. 1_5_0
11+ -t - target version, e.g. 1_5_1
12+
13+ restored = https://repo.metadatacenter.org/folders/f71236e0-fa24-42eb-bb98-a9bd8f6b2586
14+
15+ """
16+ import json
217import logging
318import os
419import sys
520from optparse import OptionParser
621
7- from pcor_cedar .loader_cedar import LoaderCedar
8- from pcor_ingest . ingest_context import PcorIngestConfiguration
22+ from pcor_cedar .cedar_access import CedarAccess
23+ from pcor_cedar . migration import CedarMigrate
924
1025logging .basicConfig (
1126 level = logging .DEBUG ,
1429)
1530logger = logging .getLogger (__name__ )
1631
17-
1832def setup_arguments ():
1933 parser = OptionParser ()
20- parser .add_option ('-r' , "--resource_url" , action = 'store' , dest = 'resource_url' , default = None )
21- parser .add_option ('-d' , "--directory" , action = 'store' , dest = 'directory' , default = None )
22- parser .add_option ('-v' , "--cedar_version" , action = 'store' , dest = 'cedar_version' , default = "1_5_1" )
34+ parser .add_option ('-f' , "--resource_file" , action = 'store' , dest = 'resource_file' , default = None )
35+ parser .add_option ('-t' , "--target_folder_id" , action = 'store' , dest = 'target_folder_id' , default = None )
2336
2437 return parser .parse_args ()[0 ]
2538
26-
2739def main ():
28- logger .info ('Main function execution started.' )
40+ logger .info ('Main function execution started. Load a backup json into CEDAR ' )
2941 global args
3042 args = setup_arguments ()
3143
3244 if "CEDAR_PROPERTIES" not in os .environ :
3345 logger .error ("CEDAR_PROPERTIES not found in env. System exiting..." )
3446 sys .exit ()
3547
36- if "PCOR_GEN3_CONFIG_LOCATION" not in os .environ :
37- logger .error ("PCOR_GEN3_CONFIG_LOCATION not found in env. System exiting..." )
38- sys .exit ()
48+ cedar_config_file = os .environ .get ("CEDAR_PROPERTIES" )
49+ cedar_access = CedarAccess (cedar_config_file )
50+
51+ resource_file = args .resource_file
52+ target_folder_id = args .target_folder_id
53+
54+ if not resource_file :
55+ logger .error ("no resource_file, specify this parameter with -f" )
56+ raise Exception ("no -s parameter specified" )
57+
58+ if not target_folder_id :
59+ logger .error ("no target_folder_id, specify this parameter with -t" )
60+ raise Exception ("no -t parameter specified" )
61+
62+ cedar_config_file = os .environ .get ("CEDAR_PROPERTIES" )
63+ logger .info ('resource to load :: %s' % resource_file )
64+ logger .info ('target_folder_id :: %s' % target_folder_id )
65+
66+ with open (resource_file , 'r' ) as f :
67+ contents_json = json .loads (f .read ())
3968
40- resource_url = args .resource_url
41- directory = args .directory
42- cedar_version = args .cedar_version
69+ id = cedar_access .create_resource (json .dumps (contents_json ), target_folder_id )
70+ logger .info ("complete..id: {id}" .format (id = id ))
4371
44- pcor_ingest_configuration = PcorIngestConfiguration (os .environ .get ("PCOR_GEN3_CONFIG_LOCATION" ))
45- cedar_loader = LoaderCedar (pcor_ingest_configuration , cedar_version )
46- logger .info ("loading..." )
47- cedar_loader .main_load_process (resource_url , directory )
48- logger .info ("loading complete" )
4972
5073if __name__ == "__main__" :
51- main ()
74+ main ()
0 commit comments