-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI tool to import AIP from METS file (#355)
- Loading branch information
Showing
4 changed files
with
166 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
import pathlib | ||
import sys | ||
import uuid | ||
from datetime import datetime | ||
|
||
import click | ||
from app import cli | ||
|
||
from AIPscan import db | ||
from AIPscan.Aggregator import database_helpers | ||
from AIPscan.Aggregator.mets_parse_helpers import import_from_mets | ||
from config import CONFIGS | ||
|
||
|
||
@click.command() | ||
@click.option("--ss-id", "-s", required=True, help="Storage service ID.", type=int) | ||
@click.option( | ||
"--location-id", "-l", required=True, help="Storage location ID.", type=int | ||
) | ||
@click.option("--aip-size", "-a", required=True, help="AIP size.", type=int) | ||
@click.option("--package-uuid", "-u", required=True, help="Package UUID.", type=str) | ||
@click.option( | ||
"--origin-pipeline-id", "-o", required=True, help="Origin pipeline UUID.", type=str | ||
) | ||
@click.argument("filename") | ||
def main(ss_id, location_id, aip_size, package_uuid, origin_pipeline_id, filename): | ||
# Check if METS file exists | ||
if not pathlib.Path(filename).exists(): | ||
cli.raise_click_error("METS file does not exist.") | ||
|
||
# Initialize Flask app context | ||
app = cli.create_app_instance(CONFIGS[cli.config_name], db) | ||
|
||
with app.app_context(): | ||
# Create a fetch_job and take note of its ID | ||
datetime_obj_start = datetime.now().replace(microsecond=0) | ||
session_id = str(uuid.uuid4()) | ||
|
||
fetch_job = database_helpers.create_fetch_job( | ||
datetime_obj_start, session_id, ss_id | ||
) | ||
fetch_job_id = fetch_job.id | ||
|
||
# Log to screen | ||
logger_name = pathlib.PurePosixPath(sys.argv[0]).name | ||
logger = logging.getLogger(logger_name) | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
# Import METS file | ||
logger.info("Importing...") | ||
|
||
import_from_mets( | ||
filename, | ||
aip_size, | ||
package_uuid, | ||
ss_id, | ||
location_id, | ||
fetch_job_id, | ||
origin_pipeline_id, | ||
logger, | ||
delete_file=False, | ||
) | ||
|
||
logger.info("Done.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |