save anonymized files if not in dry run

This commit is contained in:
Ash Garcia 2024-08-11 17:05:43 -07:00
parent dabc89f588
commit a834932aad
2 changed files with 12 additions and 5 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
testdata/ testdata/
output/

View file

@ -244,7 +244,7 @@ def extract_entries_to_temporary_folder(
copy_dir(zip_fs, zip_path, temp_fs, canonical_filename) copy_dir(zip_fs, zip_path, temp_fs, canonical_filename)
return canonical_filename return canonical_filename
temp_fs = TempFS(identifier="dimocracy-voucher_anonymized", auto_clean=False) temp_fs = TempFS(identifier="dimocracy-voucher_anonymized")
for row in csv_contents: for row in csv_contents:
if row[KnownColumns.IgnoreResubmittedFile]: if row[KnownColumns.IgnoreResubmittedFile]:
@ -376,12 +376,18 @@ def anonymize_entries(
) )
def zip_anonymized_entries( def save_anonymized_files(
args: AnonymizeEntriesArgs, args: AnonymizeEntriesArgs,
csv_contents: CsvContents, csv_contents: CsvContents,
temp_fs: TempFS, temp_fs: TempFS,
): ):
print("STUB - zip_anonymized_entries") if args.dry_run:
print("Dry run - not saving anonymized files")
return
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
output_path = f"./output/anonymized-{timestamp}"
shutil.copytree(temp_fs.root_path, output_path)
print(f"Saved to {os.path.abspath(output_path)}")
############### ###############
@ -404,7 +410,7 @@ def main(argv: list[str]):
temp_fs = extract_entries_to_temporary_folder(args, csv_contents, dynamic_columns) temp_fs = extract_entries_to_temporary_folder(args, csv_contents, dynamic_columns)
anonymize_entries(args, csv_contents, temp_fs) anonymize_entries(args, csv_contents, temp_fs)
zip_anonymized_entries(args, csv_contents, temp_fs) save_anonymized_files(args, csv_contents, temp_fs)
if __name__ == "__main__": if __name__ == "__main__":