Skip to content

Commit

Permalink
refactor to use explicit style
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjiang committed Aug 16, 2023
1 parent 685f514 commit 90a8d69
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions ezidapp/management/commands/migrate-minters-to-mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def add_arguments(self, parser):
'--dry-run', '-d',
dest='dry_run',
action='store_true',
help='Do not write to disk',
help='Dry run without updating MySQL database',
)
parser.add_argument(
'--output-file', '-o',
dest='output_file',
help='Output filename for minters in JSON',
help='Filename to save minters in JSON',
)
# Misc
parser.add_argument(
Expand All @@ -71,8 +71,8 @@ def handle(self, *_, **opt):
output_filename = opt.output_file

if not dry_run:
answer = input("Dry run without updating MySQL database: enter yes or no: ")
if answer == "yes":
answer = input('Dry run without updating MySQL database: enter yes or no: ')
if answer == 'yes':
dry_run = True

try:
Expand All @@ -91,13 +91,13 @@ def migrate_minters(self, output_filename, dry_run):
validation_err_count = 0
outfile = None

if output_filename:
if output_filename is not None:
outfile = open(output_filename, "w")

for s in ezidapp.models.shoulder.Shoulder.objects.all():
total_count += 1
minter_flag = ""
if not s.minter.strip():
if s.minter.strip() == '':
minter_flag = ', '.join(
[
'{}={}'.format(k, 'yes' if v is True else 'no' if v is False else v)
Expand Down Expand Up @@ -143,16 +143,17 @@ def migrate_minters(self, output_filename, dry_run):
log.warning(f'Minter without DBD file: prefix="{s.prefix}" name="{s.name}"')
missing_bdb_count += 1

if outfile:
if outfile is not None:
outfile.close()
log.info(f"Total number of shoulders: {total_count}")
log.info(f"Shoulders with unspecified minters: {unspecified_count}")
log.info(f"Minters with BDB file: {minter_count}")
log.info(f"Minters without BDB file: {missing_bdb_count}")
log.info(f"Minters with missing required keys: {missing_key_count}")
log.info(f"Minter validation errors: {validation_err_count}")
log.info(f"Dry run without updating MySQL: {'yes' if dry_run else 'no'}")
log.info(f"JSON minters file: {output_filename}")

log.info(f'Total number of shoulders: {total_count}')
log.info(f'Shoulders with unspecified minters: {unspecified_count}')
log.info(f'Minters with BDB file: {minter_count}')
log.info(f'Minters without BDB file: {missing_bdb_count}')
log.info(f'Minters with missing required keys: {missing_key_count}')
log.info(f'Minter validation errors: {validation_err_count}')
log.info(f'Dry run without updating MySQL: {"yes" if dry_run else "no"}')
log.info(f'JSON minters file: {output_filename}')

def minter_to_json(self, bdb_path):
bdb_obj = impl.nog.bdb.open_bdb(bdb_path)
Expand Down

0 comments on commit 90a8d69

Please sign in to comment.