Logging updates

This commit is contained in:
CocoByte 2023-11-08 13:30:44 -06:00
parent a2f0be72ce
commit a19f2dde3a
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
4 changed files with 61 additions and 17 deletions

View file

@ -273,7 +273,7 @@ class Command(BaseCommand):
-------------------------------------------- --------------------------------------------
Found {total_outlier_statuses} unaccounted Found {total_outlier_statuses} unaccounted
for statuses- for statuses
-------------------------------------------- --------------------------------------------
No mappings found for the following statuses No mappings found for the following statuses
@ -601,15 +601,6 @@ class Command(BaseCommand):
TransitionDomain.objects.bulk_create(to_create) TransitionDomain.objects.bulk_create(to_create)
logger.info(
f"""{TerminalColors.OKGREEN}
============= FINISHED ===============
Created {total_new_entries} transition domain entries,
updated {total_updated_domain_entries} transition domain entries
{TerminalColors.ENDC}
"""
)
# Print a summary of findings (duplicate entries, # Print a summary of findings (duplicate entries,
# missing data..etc.) # missing data..etc.)
self.print_summary_duplications( self.print_summary_duplications(
@ -617,10 +608,32 @@ class Command(BaseCommand):
) )
self.print_summary_status_findings(domains_without_status, outlier_statuses) self.print_summary_status_findings(domains_without_status, outlier_statuses)
logger.info(
f"""{TerminalColors.OKGREEN}
============= FINISHED ===============
Created {total_new_entries} transition domain entries,
Updated {total_updated_domain_entries} transition domain entries
{TerminalColors.YELLOW}
----- DUPLICATES FOUND -----
{len(duplicate_domain_user_combos)} DOMAIN - USER pairs
were NOT unique in the supplied data files.
{len(duplicate_domains)} DOMAINS were NOT unique in
the supplied data files.
----- STATUSES -----
{len(domains_without_status)} DOMAINS had NO status (defaulted to READY).
{len(outlier_statuses)} Statuses were invalid (defaulted to READY).
{TerminalColors.ENDC}
"""
)
# 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?"
proceed = TerminalHelper.prompt_for_execution( proceed = TerminalHelper.prompt_for_execution(
system_exit_on_terminate=False, system_exit_on_terminate=True,
info_to_inspect=f""" info_to_inspect=f"""
!!! ENSURE THAT ALL FILENAMES ARE CORRECT BEFORE PROCEEDING !!! ENSURE THAT ALL FILENAMES ARE CORRECT BEFORE PROCEEDING
==Master data file== ==Master data file==

View file

@ -309,7 +309,7 @@ class Command(BaseCommand):
proceed = False proceed = False
if prompts_enabled: if prompts_enabled:
proceed = TerminalHelper.prompt_for_execution( proceed = TerminalHelper.prompt_for_execution(
False, True,
command_string, command_string,
"Running load_transition_domain script", "Running load_transition_domain script",
) )
@ -337,7 +337,7 @@ class Command(BaseCommand):
proceed = False proceed = False
if prompts_enabled: if prompts_enabled:
proceed = TerminalHelper.prompt_for_execution( proceed = TerminalHelper.prompt_for_execution(
False, True,
command_string, command_string,
"Running transfer_transition_domains_to_domains script", "Running transfer_transition_domains_to_domains script",
) )

View file

@ -8,6 +8,7 @@ import re
import logging import logging
import os import os
import sys
from typing import List, Tuple from typing import List, Tuple
from registrar.models.transition_domain import TransitionDomain from registrar.models.transition_domain import TransitionDomain
@ -232,9 +233,25 @@ class LoadExtraTransitionDomain:
{TerminalColors.ENDC} {TerminalColors.ENDC}
""" """
) )
# TODO
if TransitionDomain.objects.all().count() != len(updated_transition_domains): # DATA INTEGRITY CHECK
logger.error("Something bad happened") # Make sure every Transition Domain got updated
total_transition_domains = TransitionDomain.objects.all().count()
total_updates_made = TransitionDomain.objects.all().count()
if total_transition_domains != total_updates_made:
logger.error(f"""{TerminalColors.Fail}
WARNING: something went wrong processing domain information data.
Total Transition Domains expecting a data update: {total_transition_domains}
Total updates made: {total_updates_made}
^ These totals should match, but they don't. This
error should never occur, but could indicate
corrupt data. Please check logs to diagnose.
----- TERMINATING ----
""")
sys.exit()
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

View file

@ -185,9 +185,23 @@ class TerminalHelper:
li = file.readlines() li = file.readlines()
total_line = len(li) total_line = len(li)
return total_line return total_line
@staticmethod
def print_to_file_conditional(print_condition: bool, filename: str, file_directory: str, file_contents: str):
"""Sometimes logger outputs get insanely huge.
"""
if (print_condition):
# Add a slash if the last character isn't one
if file_directory and file_directory[-1] != "/":
file_directory += "/"
# Assemble filepath
filepath = f"{file_directory}{filename}.txt"
# Write to file
logger.info(f"{TerminalColors.MAGENTA}Writing to file {filepath}...{TerminalColors.ENDC}")
with open(f"{filepath}", "w+") as f:
f.write(file_contents)
@staticmethod @staticmethod
def printProgressBar (iteration, total, prefix = 'Progress:', suffix = 'Complete', decimals = 1, length = 100, fill = '', printEnd = "\r"): def printProgressBar (iteration, total, prefix = 'Progress:', suffix = 'Complete', decimals = 1, length = 100, fill = '', printEnd = "\r"):
""" """