#!/usr/bin/env python """resync-build: The ResourceSync command line list builder. Copyright 2012-2020 Simeon Warner Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License """ import argparse import sys from resync import __version__ from resync.client import Client, ClientFatalError from resync.client_utils import init_logging, count_true_args, parse_links, parse_capabilities, parse_capability_lists, add_shared_misc_options, process_shared_misc_options DEFAULT_LOGFILE = 'resync-client.log' def main(): """Main function to implement command line script.""" if (sys.version_info < (3, 5)): sys.exit("This program requires python version 3.5 or later") # Options and arguments parser = argparse.ArgumentParser( description="ResourceSync build script (v" + __version__ + ")", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser._optionals = parser.add_argument_group( 'MODES OF OPERATION (must specify one only). This script operates only ' 'to create ResourceSync descriptions on the local filesystem based on ' 'local content') rem = parser.add_mutually_exclusive_group(required=True) rem.add_argument('--write-resourcelist', '--write-resource-list', action='store_true', help="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 " "based either on explicit --paths setting, else starting from all local " "paths specified in the mappings. Writes to STDOUT by default, override " "with --outfile") rem.add_argument('--write-changelist', '--write-change-list', action='store_true', help="write a change list based on comparison of a reference sitemap " "(specify file with --reference) and either files on disk (using " "the mapping provided) or a second sitemap (specify file with " "--newreference). Otherwise follows --write-resourcelist options. Also accepts " "the --empty option (with no mapping) to write and empty changelist.") rem.add_argument('--write-capabilitylist', '--write-capability-list', type=str, action='store', help="write a capability list based on the set of capabilities and " "URIs supplied in cap_name=URI,cap_name=URI format. Otherwise " "follows --write-resourcelist options.") rem.add_argument('--write-sourcedescription', '--write-source-description', type=str, action='store', help="write a Source Description document based on the set of capability " "list URIs supplied as a comma separated list. Otherwise " "follows --write-resourcelist options.") rem.add_argument('--write-resourcedump', '--write-resource-dump', '-d', action='store_true', help="write a Resource Dump. Specify output file with --outfile and use other " "options as for --write-resourcelist") rem.add_argument('--write-changedump', '--write-change-dump', action='store_true', help="write a Resource Dump. Specify output file with --outfile and use other " "options as for --write-changelist") # Positional arguments 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)") 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") nam.add_argument('--paths', type=str, action='store', help="explicit set of paths for disk scan --resourceslist or --changelist " "generation") nam.add_argument('--reference', type=str, action='store', 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") 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)") lks.add_argument('--describedby-link', type=str, action='store', help="add an