mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 19:20:47 +02:00
Linting
This commit is contained in:
parent
f7c82ac957
commit
5b4a357069
8 changed files with 50 additions and 33 deletions
|
@ -66,7 +66,7 @@ class Command(BaseCommand):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--infer_filenames",
|
"--infer_filenames",
|
||||||
action=argparse.BooleanOptionalAction,
|
action=argparse.BooleanOptionalAction,
|
||||||
help="Determines if we should infer filenames or not."
|
help="Determines if we should infer filenames or not."
|
||||||
"Recommended to be enabled only in a development or testing setting.",
|
"Recommended to be enabled only in a development or testing setting.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# The following file arguments have default values for running in the sandbox
|
# The following file arguments have default values for running in the sandbox
|
||||||
|
|
||||||
# TODO: make this a mandatory argument
|
# TODO: make this a mandatory argument
|
||||||
# (if/when we strip out defaults, it will be mandatory)
|
# (if/when we strip out defaults, it will be mandatory)
|
||||||
# TODO: use the migration directory arg or force user to type FULL filepath?
|
# TODO: use the migration directory arg or force user to type FULL filepath?
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
|
@ -114,7 +114,7 @@ class Command(BaseCommand):
|
||||||
Created {total_domain_invitation_entries} domain invitation entries
|
Created {total_domain_invitation_entries} domain invitation entries
|
||||||
(NOTE: no invitations are SENT in this script)
|
(NOTE: no invitations are SENT in this script)
|
||||||
{TerminalColors.ENDC}
|
{TerminalColors.ENDC}
|
||||||
""" # noqa
|
""" # noqa
|
||||||
)
|
)
|
||||||
if len(skipped_domain_entries) > 0:
|
if len(skipped_domain_entries) > 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -192,16 +192,15 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# ---- UPDATE THE DOMAIN
|
# ---- UPDATE THE DOMAIN
|
||||||
# update the status
|
# update the status
|
||||||
self.update_domain_status(
|
self.update_domain_status(transition_domain, target_domain, debug_on)
|
||||||
transition_domain, target_domain, debug_on
|
# TODO: not all domains need to be updated
|
||||||
)
|
# (the information is the same).
|
||||||
# TODO: not all domains need to be updated (the information is the same).
|
|
||||||
# Need to bubble this up to the final report.
|
# Need to bubble this up to the final report.
|
||||||
|
|
||||||
# update dates (creation and expiration)
|
# update dates (creation and expiration)
|
||||||
if transition_domain_creation_date is not None:
|
if transition_domain_creation_date is not None:
|
||||||
# TODO: added this because I ran into a situation where
|
# TODO: added this because I ran into a situation where
|
||||||
# the created_at date was null (violated a key constraint).
|
# the created_at date was null (violated a key constraint).
|
||||||
# How do we want to handle this case?
|
# How do we want to handle this case?
|
||||||
target_domain.created_at = transition_domain_creation_date
|
target_domain.created_at = transition_domain_creation_date
|
||||||
|
|
||||||
|
@ -493,7 +492,9 @@ class Command(BaseCommand):
|
||||||
self.update_domain_information(
|
self.update_domain_information(
|
||||||
target_domain_information, template_domain_information, debug_on
|
target_domain_information, template_domain_information, debug_on
|
||||||
)
|
)
|
||||||
# TODO: not all domains need to be updated (the information is the same). Need to bubble this up to the final report.
|
# TODO: not all domains need to be updated
|
||||||
|
# (the information is the same).
|
||||||
|
# Need to bubble this up to the final report.
|
||||||
|
|
||||||
return (target_domain_information, domain, False)
|
return (target_domain_information, domain, False)
|
||||||
except DomainInformation.MultipleObjectsReturned:
|
except DomainInformation.MultipleObjectsReturned:
|
||||||
|
@ -594,8 +595,11 @@ class Command(BaseCommand):
|
||||||
debug_on,
|
debug_on,
|
||||||
f"{TerminalColors.OKCYAN}"
|
f"{TerminalColors.OKCYAN}"
|
||||||
"Processing Transition Domain: "
|
"Processing Transition Domain: "
|
||||||
f"{transition_domain_name}, {transition_domain_status}, {transition_domain_email}"
|
f"{transition_domain_name},"
|
||||||
f", {transition_domain_creation_date}, {transition_domain_expiration_date}"
|
f" {transition_domain_status},"
|
||||||
|
f" {transition_domain_email}"
|
||||||
|
f", {transition_domain_creation_date}, "
|
||||||
|
f"{transition_domain_expiration_date}"
|
||||||
f"{TerminalColors.ENDC}", # noqa
|
f"{TerminalColors.ENDC}", # noqa
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -680,7 +684,8 @@ class Command(BaseCommand):
|
||||||
else:
|
else:
|
||||||
# Raise an err for now
|
# Raise an err for now
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Domain {existing_domain} wants to be added but doesn't exist in the DB"
|
f"Domain {existing_domain} wants to be added"
|
||||||
|
"but doesn't exist in the DB"
|
||||||
)
|
)
|
||||||
invitation.save()
|
invitation.save()
|
||||||
|
|
||||||
|
@ -740,7 +745,9 @@ class Command(BaseCommand):
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
# TODO: this is redundant. Currently debugging....running into unique key constraint error....
|
# TODO: this is redundant.
|
||||||
|
# Currently debugging....
|
||||||
|
# running into unique key constraint error....
|
||||||
existing_domain_info = DomainInformation.objects.filter(
|
existing_domain_info = DomainInformation.objects.filter(
|
||||||
domain__name=target_domain_information.domain.name
|
domain__name=target_domain_information.domain.name
|
||||||
).exists()
|
).exists()
|
||||||
|
@ -765,7 +772,8 @@ class Command(BaseCommand):
|
||||||
f"updated domain information: {target_domain_information}"
|
f"updated domain information: {target_domain_information}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
debug_string = f"domain information already exists and matches incoming data (NO CHANGES MADE): {target_domain_information}"
|
debug_string = "domain information already exists and "
|
||||||
|
f"matches incoming data (NO CHANGES MADE): {target_domain_information}"
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
TerminalHelper.print_conditional(
|
TerminalHelper.print_conditional(
|
||||||
|
|
|
@ -4,7 +4,7 @@ A list of helper classes to facilitate handling data from verisign data exports.
|
||||||
Regarding our dataclasses:
|
Regarding our dataclasses:
|
||||||
Not intended to be used as models but rather as an alternative to storing as a dictionary.
|
Not intended to be used as models but rather as an alternative to storing as a dictionary.
|
||||||
By keeping it as a dataclass instead of a dictionary, we can maintain data consistency.
|
By keeping it as a dataclass instead of a dictionary, we can maintain data consistency.
|
||||||
"""
|
""" # noqa
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
|
@ -239,6 +239,7 @@ class LoadExtraTransitionDomain:
|
||||||
total_transition_domains = len(updated_transition_domains)
|
total_transition_domains = len(updated_transition_domains)
|
||||||
total_updates_made = TransitionDomain.objects.all().count()
|
total_updates_made = TransitionDomain.objects.all().count()
|
||||||
if total_transition_domains != total_updates_made:
|
if total_transition_domains != total_updates_made:
|
||||||
|
# noqa here for line length
|
||||||
logger.error(
|
logger.error(
|
||||||
f"""{TerminalColors.FAIL}
|
f"""{TerminalColors.FAIL}
|
||||||
WARNING: something went wrong processing domain information data.
|
WARNING: something went wrong processing domain information data.
|
||||||
|
@ -251,7 +252,7 @@ class LoadExtraTransitionDomain:
|
||||||
corrupt data. Please check logs to diagnose.
|
corrupt data. Please check logs to diagnose.
|
||||||
|
|
||||||
----- TERMINATING ----
|
----- TERMINATING ----
|
||||||
"""
|
""" # noqa
|
||||||
)
|
)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
@ -654,7 +655,7 @@ class FileDataHolder:
|
||||||
id_field: data_type(...),
|
id_field: data_type(...),
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
"""
|
""" # noqa
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -664,18 +665,18 @@ class FileDataHolder:
|
||||||
id_field: str,
|
id_field: str,
|
||||||
):
|
):
|
||||||
# Metadata #
|
# Metadata #
|
||||||
## Filename inference metadata ##
|
# = Filename inference metadata =#
|
||||||
self.regex = regex
|
self.regex = regex
|
||||||
self.could_infer = False
|
self.could_infer = False
|
||||||
|
|
||||||
## "data" object metadata ##
|
# = "data" object metadata =#
|
||||||
### Where the data is sourced from ###
|
# == Where the data is sourced from ==#
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
### What type the data is ###
|
# == What type the data is ==#
|
||||||
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
|
# TODO - rename to id_field_name
|
||||||
self.id_field = id_field
|
self.id_field = id_field
|
||||||
|
|
||||||
|
@ -868,8 +869,10 @@ class ExtraTransitionDomain:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Infer filename logic #
|
# Infer filename logic #
|
||||||
# This mode is used for internal development use and testing only. Rather than having
|
# This mode is used for
|
||||||
# to manually define the filename each time, we can infer what the filename
|
# internal development use and testing only.
|
||||||
|
# Rather than havingto manually define the
|
||||||
|
# filename each time, we can infer what the filename
|
||||||
# actually is.
|
# actually is.
|
||||||
|
|
||||||
# Not intended for use outside of that, as it is better to assume
|
# Not intended for use outside of that, as it is better to assume
|
||||||
|
|
|
@ -180,7 +180,7 @@ class TerminalHelper:
|
||||||
|
|
||||||
# If the user decided to proceed return true.
|
# If the user decided to proceed return true.
|
||||||
# Otherwise, either return false or exit this subroutine.
|
# Otherwise, either return false or exit this subroutine.
|
||||||
if proceed_execution == False:
|
if not proceed_execution:
|
||||||
if system_exit_on_terminate:
|
if system_exit_on_terminate:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
return False
|
return False
|
||||||
|
@ -206,7 +206,9 @@ class TerminalHelper:
|
||||||
filepath = f"{file_directory}{filename}.txt"
|
filepath = f"{file_directory}{filename}.txt"
|
||||||
# Write to file
|
# Write to file
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{TerminalColors.MAGENTA}Writing to file {filepath}...{TerminalColors.ENDC}"
|
f"{TerminalColors.MAGENTA}Writing to file "
|
||||||
|
f" {filepath}..."
|
||||||
|
f"{TerminalColors.ENDC}"
|
||||||
)
|
)
|
||||||
with open(f"{filepath}", "w+") as f:
|
with open(f"{filepath}", "w+") as f:
|
||||||
f.write(file_contents)
|
f.write(file_contents)
|
||||||
|
@ -233,7 +235,7 @@ class TerminalHelper:
|
||||||
length - Optional : character length of bar (Int)
|
length - Optional : character length of bar (Int)
|
||||||
fill - Optional : bar fill character (Str)
|
fill - Optional : bar fill character (Str)
|
||||||
printEnd - Optional : end character (e.g. "\r", "\r\n") (Str)
|
printEnd - Optional : end character (e.g. "\r", "\r\n") (Str)
|
||||||
"""
|
""" # noqa
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Initial call to print 0% progress
|
# Initial call to print 0% progress
|
||||||
|
@ -243,7 +245,7 @@ class TerminalHelper:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
# Update Progress Bar
|
# Update Progress Bar
|
||||||
printProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50)
|
printProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50)
|
||||||
"""
|
""" # noqa
|
||||||
|
|
||||||
percent = ("{0:." + str(decimals) + "f}").format(
|
percent = ("{0:." + str(decimals) + "f}").format(
|
||||||
100 * (iteration / float(total))
|
100 * (iteration / float(total))
|
||||||
|
|
|
@ -36,7 +36,7 @@ class TransitionDomainArguments:
|
||||||
limitParse: Optional[int] = field(default=None, repr=True)
|
limitParse: Optional[int] = field(default=None, repr=True)
|
||||||
|
|
||||||
# Filenames #
|
# Filenames #
|
||||||
## Adhocs ##
|
# = Adhocs =#
|
||||||
agency_adhoc_filename: Optional[str] = field(
|
agency_adhoc_filename: Optional[str] = field(
|
||||||
default=EnumFilenames.AGENCY_ADHOC.value[1], repr=True
|
default=EnumFilenames.AGENCY_ADHOC.value[1], repr=True
|
||||||
)
|
)
|
||||||
|
@ -50,7 +50,7 @@ class TransitionDomainArguments:
|
||||||
default=EnumFilenames.AUTHORITY_ADHOC.value[1], repr=True
|
default=EnumFilenames.AUTHORITY_ADHOC.value[1], repr=True
|
||||||
)
|
)
|
||||||
|
|
||||||
## Data files ##
|
# = Data files =#
|
||||||
domain_escrow_filename: Optional[str] = field(
|
domain_escrow_filename: Optional[str] = field(
|
||||||
default=EnumFilenames.DOMAIN_ESCROW.value[1], repr=True
|
default=EnumFilenames.DOMAIN_ESCROW.value[1], repr=True
|
||||||
)
|
)
|
||||||
|
|
|
@ -47,8 +47,10 @@ class TestMigrations(TestCase):
|
||||||
UserDomainRole.objects.all().delete()
|
UserDomainRole.objects.all().delete()
|
||||||
|
|
||||||
def run_load_domains(self):
|
def run_load_domains(self):
|
||||||
|
# noqa here because splitting this up makes it confusing.
|
||||||
|
# ES501
|
||||||
with patch(
|
with patch(
|
||||||
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit",
|
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
|
||||||
return_value=True,
|
return_value=True,
|
||||||
):
|
):
|
||||||
call_command(
|
call_command(
|
||||||
|
@ -61,8 +63,10 @@ class TestMigrations(TestCase):
|
||||||
call_command("transfer_transition_domains_to_domains")
|
call_command("transfer_transition_domains_to_domains")
|
||||||
|
|
||||||
def run_master_script(self):
|
def run_master_script(self):
|
||||||
|
# noqa here (E501) because splitting this up makes it
|
||||||
|
# confusing to read.
|
||||||
with patch(
|
with patch(
|
||||||
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit",
|
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
|
||||||
return_value=True,
|
return_value=True,
|
||||||
):
|
):
|
||||||
call_command(
|
call_command(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue