diff --git a/src/registrar/management/commands/load_transition_domain.py b/src/registrar/management/commands/load_transition_domain.py index 9496789f1..7edf22457 100644 --- a/src/registrar/management/commands/load_transition_domain.py +++ b/src/registrar/management/commands/load_transition_domain.py @@ -1,3 +1,4 @@ +import json import sys import csv import logging @@ -41,7 +42,7 @@ class Command(BaseCommand): for testing purposes, but USE WITH CAUTION """ parser.add_argument( - "migration_Json_filename", + "migration_json_filename", help=( "A JSON file that holds the location and filenames" "of all the data files used for migrations" @@ -319,10 +320,32 @@ class Command(BaseCommand): def handle( # noqa: C901 self, - migration_Json_filename, + migration_json_filename, **options, ): """Parse the data files and create TransitionDomains.""" + ### Process JSON file ### + # If a JSON was provided, use its values instead of defaults. + # TODO: there is no way to discern user overrides from those arg’s defaults. + with open(migration_json_filename, "r") as jsonFile: + # load JSON object as a dictionary + try: + data = json.load(jsonFile) + # Create an instance of TransitionDomainArguments + args = TransitionDomainArguments() + # Iterate over the data from the JSON file + for key, value in data.items(): + # Check if the key exists in TransitionDomainArguments + if hasattr(args, key): + # If it does, update the options + options[key] = value + except Exception as err: + logger.error(f"""{TerminalColors.FAIL}There was an error loading the JSON responsible + for providing filepaths. + {TerminalColors.ENDC} + """) + raise err + sep = options.get("sep") # If --resetTable was used, prompt user to confirm @@ -346,9 +369,9 @@ class Command(BaseCommand): # Main script filenames # TODO: @ZANDER to replace this with new TransitionDomainArgument object - domain_contacts_filename = directory+ options.get("domain_contacts_filename") - contacts_filename = directory+ options.get("contacts_filename") - domain_statuses_filename = directory+ options.get("domain_statuses_filename") + domain_contacts_filename = directory + "/" + options.get("domain_contacts_filename") + contacts_filename = directory + "/" + options.get("contacts_filename") + domain_statuses_filename = directory + "/" + options.get("domain_statuses_filename") # Agency information agency_adhoc_filename = options.get("agency_adhoc_filename") diff --git a/src/registrar/management/commands/master_domain_migrations.py b/src/registrar/management/commands/master_domain_migrations.py index 673345b8a..58124157f 100644 --- a/src/registrar/management/commands/master_domain_migrations.py +++ b/src/registrar/management/commands/master_domain_migrations.py @@ -99,7 +99,7 @@ class Command(BaseCommand): # TODO: make this a mandatory argument (if/when we strip out defaults, it will be mandatory) # TODO: use the migration directory arg or force user to type FULL filepath? parser.add_argument( - "migration_Json_filename", + "migration_json_filename", help=( "A JSON file that holds the location and filenames" "of all the data files used for migrations" @@ -281,11 +281,8 @@ class Command(BaseCommand): # ====================================================== def run_load_transition_domain_script( self, - migration_Json_filename: str, + migration_json_filename: str, file_location: str, - domain_contacts_filename: str, - contacts_filename: str, - domain_statuses_filename: str, sep: str, reset_table: bool, debug_on: bool, @@ -297,7 +294,7 @@ class Command(BaseCommand): command_script = "load_transition_domain" command_string = ( f"./manage.py {command_script} " - f"{file_location+migration_Json_filename}" + f"{file_location+migration_json_filename}" ) if sep is not None and sep != "|": command_string += f"--sep {sep} " @@ -321,7 +318,7 @@ class Command(BaseCommand): if proceed: call_command( command_script, - f"{file_location+migration_Json_filename}", + f"{file_location+migration_json_filename}", sep=sep, resetTable=reset_table, debug=debug_on, @@ -368,7 +365,7 @@ class Command(BaseCommand): def run_migration_scripts( self, - migration_Json_filename, + migration_json_filename, file_location, domain_contacts_filename, contacts_filename, @@ -420,11 +417,8 @@ class Command(BaseCommand): # Proceed executing the migration scripts self.run_load_transition_domain_script( - migration_Json_filename, + migration_json_filename, file_location, - domain_contacts_filename, - contacts_filename, - domain_statuses_filename, sep, reset_table, debug_on, @@ -435,7 +429,7 @@ class Command(BaseCommand): def handle( self, - migration_Json_filename, + migration_json_filename, **options, ): """ @@ -530,7 +524,7 @@ class Command(BaseCommand): # Run migration scripts self.run_migration_scripts( - migration_Json_filename, + migration_json_filename, file_location, domain_contacts_filename, contacts_filename, diff --git a/src/registrar/management/commands/utility/transition_domain_arguments.py b/src/registrar/management/commands/utility/transition_domain_arguments.py index 70f13cfb5..335f74cd9 100644 --- a/src/registrar/management/commands/utility/transition_domain_arguments.py +++ b/src/registrar/management/commands/utility/transition_domain_arguments.py @@ -46,6 +46,7 @@ class TransitionDomainArguments: domain_additional_filename: Optional[str] = field(default=EnumFilenames.DOMAIN_ADDITIONAL.value[1], repr=True) domain_contacts_filename: Optional[str] = field(default=None, repr=True) domain_statuses_filename: Optional[str] = field(default=None, repr=True) + contacts_filename: Optional[str] = field(default=None, repr=True) # Flags # debug: Optional[bool] = field(default=False, repr=True)