mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-20 03:19:24 +02:00
Update script
This commit is contained in:
parent
eca8852d00
commit
ba9ba10131
4 changed files with 59 additions and 17 deletions
|
@ -324,6 +324,7 @@ class Command(BaseCommand):
|
||||||
**options,
|
**options,
|
||||||
):
|
):
|
||||||
"""Parse the data files and create TransitionDomains."""
|
"""Parse the data files and create TransitionDomains."""
|
||||||
|
args = TransitionDomainArguments(**options)
|
||||||
### Process JSON file ###
|
### Process JSON file ###
|
||||||
# If a JSON was provided, use its values instead of defaults.
|
# 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.
|
# TODO: there is no way to discern user overrides from those arg’s defaults.
|
||||||
|
@ -332,7 +333,7 @@ class Command(BaseCommand):
|
||||||
try:
|
try:
|
||||||
data = json.load(jsonFile)
|
data = json.load(jsonFile)
|
||||||
# Create an instance of TransitionDomainArguments
|
# Create an instance of TransitionDomainArguments
|
||||||
args = TransitionDomainArguments()
|
|
||||||
# Iterate over the data from the JSON file
|
# Iterate over the data from the JSON file
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
# Check if the key exists in TransitionDomainArguments
|
# Check if the key exists in TransitionDomainArguments
|
||||||
|
@ -346,32 +347,57 @@ class Command(BaseCommand):
|
||||||
""")
|
""")
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
sep = options.get("sep")
|
sep = args.sep
|
||||||
|
|
||||||
# If --resetTable was used, prompt user to confirm
|
# If --resetTable was used, prompt user to confirm
|
||||||
# deletion of table data
|
# deletion of table data
|
||||||
if options.get("resetTable"):
|
if args.resetTable:
|
||||||
self.prompt_table_reset()
|
self.prompt_table_reset()
|
||||||
|
|
||||||
# Get --debug argument
|
# Get --debug argument
|
||||||
debug_on = options.get("debug")
|
debug_on = args.debug
|
||||||
|
|
||||||
# Get --LimitParse argument
|
# Get --LimitParse argument
|
||||||
debug_max_entries_to_parse = int(
|
debug_max_entries_to_parse = int(
|
||||||
options.get("limitParse")
|
args.limitParse
|
||||||
) # set to 0 to parse all entries
|
) # set to 0 to parse all entries
|
||||||
|
|
||||||
## Variables for Additional TransitionDomain Information ##
|
## Variables for Additional TransitionDomain Information ##
|
||||||
|
|
||||||
# Desired directory for additional TransitionDomain data
|
# Desired directory for additional TransitionDomain data
|
||||||
# (In the event they are stored seperately)
|
# (In the event they are stored seperately)
|
||||||
directory = options.get("directory")
|
directory = args.directory
|
||||||
|
# Add a slash if the last character isn't one
|
||||||
|
if directory and directory[-1] != "/":
|
||||||
|
directory += "/"
|
||||||
|
|
||||||
# Main script filenames
|
# Main script filenames - these do not have defaults
|
||||||
# TODO: @ZANDER to replace this with new TransitionDomainArgument object
|
domain_contacts_filename = None
|
||||||
domain_contacts_filename = directory + "/" + options.get("domain_contacts_filename")
|
try:
|
||||||
contacts_filename = directory + "/" + options.get("contacts_filename")
|
domain_contacts_filename = directory + options.get("domain_contacts_filename")
|
||||||
domain_statuses_filename = directory + "/" + options.get("domain_statuses_filename")
|
except TypeError as err:
|
||||||
|
logger.error(
|
||||||
|
f"Invalid filename of '{args.domain_contacts_filename}'"
|
||||||
|
" was provided for domain_contacts_filename"
|
||||||
|
)
|
||||||
|
|
||||||
|
contacts_filename = None
|
||||||
|
try:
|
||||||
|
contacts_filename = directory + options.get("contacts_filename")
|
||||||
|
except TypeError as err:
|
||||||
|
logger.error(
|
||||||
|
f"Invalid filename of '{args.contacts_filename}'"
|
||||||
|
" was provided for contacts_filename"
|
||||||
|
)
|
||||||
|
|
||||||
|
domain_statuses_filename = None
|
||||||
|
try:
|
||||||
|
domain_statuses_filename = directory + options.get("domain_statuses_filename")
|
||||||
|
except TypeError as err:
|
||||||
|
logger.error(
|
||||||
|
f"Invalid filename of '{args.domain_statuses_filename}'"
|
||||||
|
" was provided for domain_statuses_filename"
|
||||||
|
)
|
||||||
|
|
||||||
# Agency information
|
# Agency information
|
||||||
agency_adhoc_filename = options.get("agency_adhoc_filename")
|
agency_adhoc_filename = options.get("agency_adhoc_filename")
|
||||||
|
@ -593,7 +619,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# Prompt the user if they want to load additional data on the domains
|
# Prompt the user if they want to load additional data on the domains
|
||||||
title = "Do you wish to load additional data for TransitionDomains?"
|
title = "Do you wish to load additional data for TransitionDomains?"
|
||||||
do_parse_extra = TerminalHelper.prompt_for_execution(
|
proceed = TerminalHelper.prompt_for_execution(
|
||||||
system_exit_on_terminate=False,
|
system_exit_on_terminate=False,
|
||||||
info_to_inspect=f"""
|
info_to_inspect=f"""
|
||||||
!!! ENSURE THAT ALL FILENAMES ARE CORRECT BEFORE PROCEEDING
|
!!! ENSURE THAT ALL FILENAMES ARE CORRECT BEFORE PROCEEDING
|
||||||
|
@ -617,6 +643,6 @@ class Command(BaseCommand):
|
||||||
""",
|
""",
|
||||||
prompt_title=title,
|
prompt_title=title,
|
||||||
)
|
)
|
||||||
if do_parse_extra:
|
if proceed:
|
||||||
arguments = TransitionDomainArguments(**options)
|
arguments = TransitionDomainArguments(**options)
|
||||||
self.parse_extra(arguments)
|
self.parse_extra(arguments)
|
||||||
|
|
|
@ -294,7 +294,7 @@ class Command(BaseCommand):
|
||||||
command_script = "load_transition_domain"
|
command_script = "load_transition_domain"
|
||||||
command_string = (
|
command_string = (
|
||||||
f"./manage.py {command_script} "
|
f"./manage.py {command_script} "
|
||||||
f"{file_location+migration_json_filename}"
|
f"{file_location+migration_json_filename} "
|
||||||
)
|
)
|
||||||
if sep is not None and sep != "|":
|
if sep is not None and sep != "|":
|
||||||
command_string += f"--sep {sep} "
|
command_string += f"--sep {sep} "
|
||||||
|
|
|
@ -176,6 +176,7 @@ class LoadExtraTransitionDomain:
|
||||||
|
|
||||||
# Check if the instance has changed before saving
|
# Check if the instance has changed before saving
|
||||||
#if updated_transition_domain.__dict__ != transition_domain.__dict__:
|
#if updated_transition_domain.__dict__ != transition_domain.__dict__:
|
||||||
|
|
||||||
updated_transition_domain.save()
|
updated_transition_domain.save()
|
||||||
updated_transition_domains.append(updated_transition_domain)
|
updated_transition_domains.append(updated_transition_domain)
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
@ -214,6 +215,7 @@ class LoadExtraTransitionDomain:
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# TODO - update
|
||||||
logger.error(
|
logger.error(
|
||||||
f"""{TerminalColors.FAIL}
|
f"""{TerminalColors.FAIL}
|
||||||
============= FINISHED WITH ERRORS ===============
|
============= FINISHED WITH ERRORS ===============
|
||||||
|
@ -222,6 +224,9 @@ class LoadExtraTransitionDomain:
|
||||||
{TerminalColors.ENDC}
|
{TerminalColors.ENDC}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
# TODO
|
||||||
|
if TransitionDomain.objects.all().count() != len(updated_transition_domains):
|
||||||
|
logger.error("Something bad happened")
|
||||||
|
|
||||||
def parse_creation_expiration_data(self, domain_name, transition_domain):
|
def parse_creation_expiration_data(self, domain_name, transition_domain):
|
||||||
"""Grabs expiration_date from the parsed files and associates it
|
"""Grabs expiration_date from the parsed files and associates it
|
||||||
|
@ -517,7 +522,6 @@ class LoadExtraTransitionDomain:
|
||||||
def get_domain_data(self, desired_id) -> DomainAdditionalData:
|
def get_domain_data(self, desired_id) -> DomainAdditionalData:
|
||||||
"""Grabs a corresponding row within the DOMAIN_ADDITIONAL file,
|
"""Grabs a corresponding row within the DOMAIN_ADDITIONAL file,
|
||||||
based off a desired_id"""
|
based off a desired_id"""
|
||||||
l = self.get_object_by_id(EnumFilenames.DOMAIN_ADDITIONAL, desired_id.lower())
|
|
||||||
return self.get_object_by_id(EnumFilenames.DOMAIN_ADDITIONAL, desired_id)
|
return self.get_object_by_id(EnumFilenames.DOMAIN_ADDITIONAL, desired_id)
|
||||||
|
|
||||||
def get_organization_adhoc(self, desired_id) -> OrganizationAdhoc:
|
def get_organization_adhoc(self, desired_id) -> OrganizationAdhoc:
|
||||||
|
@ -545,6 +549,7 @@ class LoadExtraTransitionDomain:
|
||||||
based off a desired_id"""
|
based off a desired_id"""
|
||||||
return self.get_object_by_id(EnumFilenames.DOMAIN_ESCROW, desired_id)
|
return self.get_object_by_id(EnumFilenames.DOMAIN_ESCROW, desired_id)
|
||||||
|
|
||||||
|
# TODO - renamed / needs a return section
|
||||||
def get_object_by_id(self, file_type: EnumFilenames, desired_id):
|
def get_object_by_id(self, file_type: EnumFilenames, desired_id):
|
||||||
"""Returns a field in a dictionary based off the type and id.
|
"""Returns a field in a dictionary based off the type and id.
|
||||||
|
|
||||||
|
@ -591,7 +596,7 @@ class LoadExtraTransitionDomain:
|
||||||
)
|
)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
# TODO - change name
|
||||||
@dataclass
|
@dataclass
|
||||||
class PatternMap:
|
class PatternMap:
|
||||||
"""Helper class that holds data and metadata about a requested file.
|
"""Helper class that holds data and metadata about a requested file.
|
||||||
|
@ -612,7 +617,6 @@ class PatternMap:
|
||||||
id_field: data_type(...),
|
id_field: data_type(...),
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -635,6 +639,7 @@ class PatternMap:
|
||||||
self.data_type = data_type
|
self.data_type = data_type
|
||||||
|
|
||||||
### What the id should be in the holding dict ###
|
### What the id should be in the holding dict ###
|
||||||
|
# TODO - rename to id_field_name
|
||||||
self.id_field = id_field
|
self.id_field = id_field
|
||||||
|
|
||||||
# Object data #
|
# Object data #
|
||||||
|
@ -743,9 +748,17 @@ class ExtraTransitionDomain:
|
||||||
AuthorityAdhoc,
|
AuthorityAdhoc,
|
||||||
"authorityid",
|
"authorityid",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
EnumFilenames.AUTHORITY_ADHOC,
|
||||||
|
options.authority_adhoc_filename,
|
||||||
|
AuthorityAdhoc,
|
||||||
|
"authorityid",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
self.file_data = self.populate_file_data(pattern_map_params)
|
self.file_data = self.populate_file_data(pattern_map_params)
|
||||||
|
|
||||||
|
# TODO - revise comment
|
||||||
def populate_file_data(
|
def populate_file_data(
|
||||||
self, pattern_map_params: List[Tuple[EnumFilenames, str, type, str]]
|
self, pattern_map_params: List[Tuple[EnumFilenames, str, type, str]]
|
||||||
):
|
):
|
||||||
|
|
|
@ -352,6 +352,8 @@ class TestMigrations(TestCase):
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
#TransitionDomain.objects.filter(domain_name = "fakewebsite3.gov")
|
||||||
# Afterwards, their values should be what we expect
|
# Afterwards, their values should be what we expect
|
||||||
all_transition_domains = TransitionDomain.objects.all()
|
all_transition_domains = TransitionDomain.objects.all()
|
||||||
for domain in all_transition_domains:
|
for domain in all_transition_domains:
|
||||||
|
@ -433,6 +435,7 @@ class TestMigrations(TestCase):
|
||||||
expected.id = domain.id
|
expected.id = domain.id
|
||||||
expected.created_at = domain.created_at
|
expected.created_at = domain.created_at
|
||||||
expected.updated_at = domain.updated_at
|
expected.updated_at = domain.updated_at
|
||||||
|
|
||||||
self.assertEqual(domain, expected)
|
self.assertEqual(domain, expected)
|
||||||
|
|
||||||
def test_transfer_transition_domains_to_domains(self):
|
def test_transfer_transition_domains_to_domains(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue