Skip to content

Commit

Permalink
Add validate_checksums for entire objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
markpbaggett committed Jan 4, 2020
1 parent b7f13de commit c9b88da
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/moldybread.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
##
Expand All @@ -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 = """
__ __ _ _ ____ _
| \/ | ___ | | __| |_ _ | __ ) _ __ ___ __ _ __| |
Expand All @@ -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="")
Expand Down Expand Up @@ -273,13 +281,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:
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."
of "harvest_datastream_no_pages":
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."
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c9b88da

Please sign in to comment.