From 92615b9d93f7f04c394ced39973616392fbdc9e3 Mon Sep 17 00:00:00 2001 From: Simeon Warner Date: Sun, 13 Dec 2020 10:18:28 -0500 Subject: [PATCH] Change from optparse to argparse, part 3 --- .travis.yml | 4 +- CHANGES.md | 3 + bin/resync => resync-build | 110 ++++-------- bin/resync-explorer => resync-explorer | 55 +++--- resync-sync | 162 ++++++++++++++++++ ...options.py => test_resync-build_script.py} | 9 +- ...ient.py => test_resync-explorer_script.py} | 6 +- 7 files changed, 228 insertions(+), 121 deletions(-) rename bin/resync => resync-build (62%) rename bin/resync-explorer => resync-explorer (54%) create mode 100755 resync-sync rename tests/{test_client_link_options.py => test_resync-build_script.py} (91%) rename tests/{test_explorer_client.py => test_resync-explorer_script.py} (77%) diff --git a/.travis.yml b/.travis.yml index 79151b8..95cb634 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,8 @@ install: - python setup.py install script: - python setup.py test - - pycodestyle --ignore=E501,W503 resync bin tests - - pep257 resync bin tests + - pycodestyle --ignore=E501,W503 resync tests resync-sync resync-build resync-explorer + - pep257 resync bin tests resync-sync resync-build resync-explorer - coverage run --source=resync setup.py test after_success: - coveralls \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md index 04e5397..c8d848f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ The current ResourceSync specification is standardized as ANSI/NISO Z39.99-2017 , the prior version was ANSI/NISO Z39.99-2014 . v2.0.0 ??? + * Split old `resync` script into `resync-sync` and `resync-build` + * Move scripts from `bin` dir to base dir for easier testing/development + * Switch from optparse to argparse, use exclusive argument group for commands * Add --access_token option to pass bearer token with web requests * Add --delay option to pause between successive web requests * Drop Python 2.7, 3.3 & 3.4 from tests, add 3.7 & 3.8 diff --git a/bin/resync b/resync-build similarity index 62% rename from bin/resync rename to resync-build index 044a143..9e721c6 100755 --- a/bin/resync +++ b/resync-build @@ -1,5 +1,5 @@ #!/usr/bin/env python -"""resync: The ResourceSync command line client. +"""resync-build: The ResourceSync command line list builder. Copyright 2012-2020 Simeon Warner @@ -33,28 +33,16 @@ def main(): # Options and arguments parser = argparse.ArgumentParser( - description="ResourceSync command line client (v" + __version__ + ")\n\n" - "MODES - REMOTE and LOCAL - one must be specified\n" - "These modes use a remote source that is specified in a " - "set of uri=path mappings and potentially also using an " - "explicit --sitemap location.", + description="ResourceSync build script (v" + __version__ + ")", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser._optionals = parser.add_argument_group( - 'MODES OF OPERATION (must specify one only). The REMOTE modes use a ' - 'remote source that is specified in a set of uri=path mappings and ' - 'potentially also using an explicit --sitemap location. The LOCAL ' - 'modes operate only to create ResourceSync descriptions on the local ' - 'filesystem based on local content') + 'MODES OF OPERATION (must specify one only). The REMOTE modes use a ' + 'remote source that is specified in a set of uri=path mappings and ' + 'potentially also using an explicit --sitemap location. The LOCAL ' + 'modes operate only to create ResourceSync descriptions on the local ' + 'filesystem based on local content') rem = parser.add_mutually_exclusive_group(required=True) - rem.add_argument('--baseline', '-b', action='store_true', - help='REMOTE: baseline sync of resources from remote source (src) to local filesystem (dst)') - rem.add_argument('--incremental', '--inc', '-i', action='store_true', - help='REMOTE: incremental sync of resources from remote source (src) to local filesystem (dst). Uses either timestamp recorded from last baseline or incremental sync for this source, or explicit --from parameter, to determine the earlier update timestamp to act on.') - rem.add_argument('--audit', '-a', action='store_true', - help="REMOTE: audit sync state of destination wrt source") - rem.add_argument('--parse', '-p', action='store_true', - help="REMOTE: parse a remote sitemap/sitemapindex (from mapping or explicit --sitemap) and show summary information including document type and number of entries") rem.add_argument('--write-resourcelist', '--write-resource-list', action='store_true', help="LOCAL: write a resource list based on files on disk using uri=path mappings " "in reverse to calculate URIs from the local paths. Scans local disk " @@ -83,82 +71,61 @@ def main(): "options as for --write-changelist") # Positional arguments - map=parser.add_argument_group('URI MAPPING TO FILESYSTEM for REMOTE modes') + map = parser.add_argument_group('URI MAPPING TO FILESYSTEM for REMOTE modes') map.add_argument(metavar='uri=path | uri path', dest='map', type=str, nargs='*', help="remote URI of source for remote synchronization operations (may " "also combine uri=local path)") - # Specification of map between remote URI and local file paths, and remote - # sitemap nam = parser.add_argument_group('FILE/URI NAMING OPTIONS') nam.add_argument('--outfile', type=str, action='store', - help="write output to specified file rather than STDOUT or default") + help="write output to specified file rather than STDOUT or default") nam.add_argument('--paths', type=str, action='store', - help="explicit set of paths for disk scan --resourceslist or --changelist " - "generation") + help="explicit set of paths for disk scan --resourceslist or --changelist " + "generation") nam.add_argument('--sitemap', type=str, action='store', - help="explicitly set sitemap name, overriding default sitemap.xml " - "appended to first source URI specified in the mappings") + help="explicitly set sitemap name, overriding default sitemap.xml " + "appended to first source URI specified in the mappings") nam.add_argument('--capabilitylist', '--capability-list', type=str, action='store', - help="explicitly set capability list URI to search for instead of " - "looking for the source description") + help="explicitly set capability list URI to search for instead of " + "looking for the source description") nam.add_argument('--reference', type=str, action='store', - help="reference sitemap name for --write-changelist calculation") + help="reference sitemap name for --write-changelist calculation") nam.add_argument('--newreference', type=str, action='store', - help="updated reference sitemap name for --write-changelist calculation") - nam.add_argument('--changelist-uri', '--change-list-uri', type=str, action='store', - help="explicitly set the changelist URI that will be use in --inc mode, " - "overrides process of getting this from the sitemap") + help="updated reference sitemap name for --write-changelist calculation") lks = parser.add_argument_group("LINK GENERATION") lks.add_argument('--link', type=str, action='append', - help="add discovery links to the output sitemap, " - "format: rel,href[,att1=val1,att2=val2] " - "(repeat option for multiple links)") + help="add discovery links to the output sitemap, " + "format: rel,href[,att1=val1,att2=val2] " + "(repeat option for multiple links)") lks.add_argument('--describedby-link', type=str, action='store', - help="add an