-
Notifications
You must be signed in to change notification settings - Fork 3
major refactor #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
major refactor #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "file_identifier": { | ||
| "csv_field_name": "file_identifier", | ||
| "language": null, | ||
| "delimiter": "" | ||
| }, | ||
| "dc.title": { | ||
| "csv_field_name": "title", | ||
| "language": "en_US", | ||
| "delimiter": "" | ||
| }, | ||
| "dc.relation.isversionof": { | ||
| "csv_field_name": "uri", | ||
| "language": null, | ||
| "delimiter": "" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,30 +2,49 @@ | |
| import glob | ||
| import os | ||
|
|
||
| from dsaps import models | ||
| import structlog | ||
|
|
||
|
|
||
| logger = structlog.get_logger() | ||
|
|
||
|
|
||
| def create_csv_from_list(list_name, output): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's go ahead and delete all the helper functions that aren't being used anymore. We always have old code to go back and look at if we need the logic.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's left are functions related to the reconcile command which I will clean up in the next PR as I refactor that process |
||
| """Creates CSV file from list content.""" | ||
| with open(f'{output}.csv', 'w') as csvfile: | ||
| writer = csv.writer(csvfile) | ||
| writer.writerow(['id']) | ||
| for item in list_name: | ||
| writer.writerow([item]) | ||
|
|
||
|
|
||
| def create_file_dict(file_path, file_type): | ||
| """Creates a dict of file IDs and file paths.""" | ||
| if file_path.startswith('http'): | ||
| file_dict = models.build_file_dict_remote(file_path, file_type, {}) | ||
| else: | ||
| files = glob.glob(f'{file_path}/**/*.{file_type}', recursive=True) | ||
| file_dict = {} | ||
| for file in files: | ||
| file_name = os.path.splitext(os.path.basename(file))[0] | ||
| file_dict[file_name] = file | ||
| files = glob.glob(f'{file_path}/**/*.{file_type}', recursive=True) | ||
| file_dict = {} | ||
| for file in files: | ||
| file_name = os.path.splitext(os.path.basename(file))[0] | ||
| file_dict[file_name] = file | ||
| return file_dict | ||
|
|
||
|
|
||
| def create_ingest_report(items, file_name): | ||
| """Creates ingest report of other systems' identifiers with a newly created | ||
| DSpace handle.""" | ||
| with open(f'{file_name}', 'w') as writecsv: | ||
| writer = csv.writer(writecsv) | ||
| writer.writerow(['uri', 'link']) | ||
| for item in items: | ||
| writer.writerow([item.source_system_identifier] | ||
| + [f'https://hdl.handle.net/{item.handle}']) | ||
|
|
||
|
|
||
| def create_metadata_id_list(metadata_csv): | ||
| """Creates a list of IDs from a metadata CSV""" | ||
| metadata_ids = [] | ||
| with open(metadata_csv) as csvfile: | ||
| reader = csv.DictReader(csvfile) | ||
| for row in reader: | ||
| value = row['file_identifier'] | ||
| metadata_ids.append(value) | ||
| for row in [r for r in reader if r['file_identifier'] != '']: | ||
| metadata_ids.append(row['file_identifier']) | ||
| return metadata_ids | ||
|
|
||
|
|
||
|
|
@@ -49,23 +68,6 @@ def match_metadata_to_files(file_dict, metadata_ids): | |
| return metadata_matches | ||
|
|
||
|
|
||
| def reconcile_files_and_metadata(metadata_csv, output_path, file_path, | ||
| file_type): | ||
| """Runs a reconciliation of files and metadata.""" | ||
| file_dict = create_file_dict(file_path, file_type) | ||
| file_ids = file_dict.keys() | ||
| metadata_ids = create_metadata_id_list(metadata_csv) | ||
| metadata_matches = match_metadata_to_files(file_dict, metadata_ids) | ||
| file_matches = match_files_to_metadata(file_dict, metadata_ids) | ||
| no_files = set(metadata_ids) - set(metadata_matches) | ||
| no_metadata = set(file_ids) - set(file_matches) | ||
| models.create_csv_from_list(no_metadata, f'{output_path}no_metadata') | ||
| models.create_csv_from_list(no_files, f'{output_path}no_files') | ||
| models.create_csv_from_list(metadata_matches, | ||
| f'{output_path}metadata_matches') | ||
| update_metadata_csv(metadata_csv, output_path, metadata_matches) | ||
|
|
||
|
|
||
| def update_metadata_csv(metadata_csv, output_path, metadata_matches): | ||
| """Creates an updated CSV of metadata records with matching files.""" | ||
| with open(metadata_csv) as csvfile: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.