From c9b88da359fabeee6f7027613e8f27e097274ade Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Sat, 4 Jan 2020 14:59:00 -0500 Subject: [PATCH] Add validate_checksums for entire objects. --- src/moldybread.nim | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/moldybread.nim b/src/moldybread.nim index e51799a..c942691 100644 --- a/src/moldybread.nim +++ b/src/moldybread.nim @@ -220,8 +220,8 @@ when isMainModule: ## ## moldybread -o get_datastream_at_date -n test -d RELS-EXT -dt 2019-12-19 -y /full/path/to/my/yaml/file.yml ## - ## Validate Checksums for Datastream - ## ================================= + ## Validate Checksums + ## ================== ## ## You can check whether the current checksum of a datastream for an object matches the original checksum. If not, the objects with bad datastreams are listed: ## @@ -231,6 +231,14 @@ when isMainModule: ## ## moldybread -o validate_checksums -n test -d OBJ -y /full/path/to/my/yaml/file.yml ## + ## Or, you can check whether the current checksum for all current versions of datastreams belonging to an object match the checksum of that datastream on ingest. + ## + ## Example command: + ## + ## .. code-block:: sh + ## + ## moldybread -o validate_checksums -n test -y /full/path/to/my/yaml/file.yml + ## const banner = """ __ __ _ _ ____ _ | \/ | ___ | | __| |_ _ | __ ) _ __ ___ __ _ __| | @@ -243,7 +251,7 @@ when isMainModule: var p = newParser(fmt"Moldy Bread: See https://markpbaggett.github.io/moldybread/moldybread.html for documentation and examples on how to use this package.{'\n'}{'\n'}"): help(banner) option("-o", "--operation", help="Specify operation", choices = @["harvest_datastream", "harvest_datastream_no_pages", "update_metadata", "update_metadata_and_delete_old_versions", "download_foxml", "version_datastream", "change_object_state", "purge_old_versions", "find_objs_missing_dsid", "get_datastream_history", "get_datastream_at_date", "validate_checksums"]) - option("-d", "--dsid", help="Specify datastream id.", default="MODS") + option("-d", "--dsid", help="Specify datastream id.", default="") option("-n", "--namespaceorpid", help="Populate results based on namespace or PID.", default="") option("-dc", "--dcsearch", help="Populate results based on dc field and strings. See docs for formatting info.", default="") option("-p", "--path", help="Specify a directory path.", default="") @@ -273,6 +281,8 @@ when isMainModule: if opts.namespaceorpid == "" and opts.dcsearch == "" and opts.terms == "": echo "Must specify how you want to populated results: -p for Pid or Namespace, -dc for dc fields and strings, or -t for keyword terms." else: + if opts.dsid == "": + opts.dsid = "MODS" fedora_connection.results = fedora_connection.populate_results() let test = fedora_connection.harvest_datastream(opts.dsid) echo fmt"{'\n'}Successfully downloaded {len(test.successes)} record(s). {len(test.errors)} error(s) occurred." @@ -280,6 +290,8 @@ when isMainModule: if opts.namespaceorpid == "" and opts.dcsearch == "" and opts.terms == "": echo "Must specify how you want to populated results: -p for Pid or Namespace, -dc for dc fields and strings, or -t for keyword terms." else: + if opts.dsid == "": + opts.dsid = "MODS" fedora_connection.results = fedora_connection.populate_results() let test = fedora_connection.harvest_datastream_no_pages(opts.dsid) echo fmt"{'\n'}Successfully downloaded {len(test.successes)} record(s). {len(test.errors)} error(s) occurred." @@ -358,14 +370,17 @@ when isMainModule: if opts.namespaceorpid == "" and opts.dcsearch == "" and opts.terms == "": echo "Must specify how you want to populated results: -p for Pid or Namespace, -dc for dc fields and strings, or -t for keyword terms." else: - try: fedora_connection.results = fedora_connection.populate_results() - let test = fedora_connection.validate_checksums(opts.dsid) - echo fmt"{'\n'}{len(test.successes)} objects had valid checksums for their {opts.dsid} datastream. {len(test.errors)} objects had invalid checksums on their {opts.dsid} datastream." - if len(test.errors) > 0: - echo test.errors - except ValueError: - echo "Must set -d or --dsid to select datastream." + if opts.dsid != "": + let test = fedora_connection.validate_checksums(opts.dsid) + echo fmt"{'\n'}{len(test.successes)} objects had valid checksums for their {opts.dsid} datastream. {len(test.errors)} objects had invalid checksums on their {opts.dsid} datastream." + if len(test.errors) > 0: + echo test.errors + else: + let test = fedora_connection.validate_checksums() + echo fmt"{'\n'}{len(test.successes)} objects had valid checksums for their {opts.dsid} datastream. {len(test.errors)} objects had invalid checksums on their {opts.dsid} datastream." + if len(test.errors) > 0: + echo test.errors of "update_metadata": if opts.path != "": yaml_settings.directory_path = opts.path