def parse_arguments(): """Parse command line arguments.""" parser = argparse.ArgumentParser( description='Manipulate an OCFL object or inventory.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--srcdir', '--src', action='store', help='source directory path') parser.add_argument('--digest', default='sha512', help='digest type to use') parser.add_argument('--fixity', action='append', help='add fixity type to add') parser.add_argument('--id', default=None, help='identifier of object') parser.add_argument('--dstdir', '--dst', action='store', default='/tmp', help='destination directory path') commands = parser.add_mutually_exclusive_group(required=True) commands.add_argument( '--create', action='store_true', help='Create a new object with version 1 files in srcdir') commands.add_argument( '--build', action='store_true', help='Build a new object from version directories in srcdir') commands.add_argument('--show', action='store_true', help='Show versions and files in an OCFL object') commands.add_argument('--validate', action='store_true', help='Validate an OCFL object') commands.add_argument( '--extract', action='store', default=None, help='Extract a specific version (or "head") into dstdir') # Version metadata and object settings ocfl.add_version_metadata_args(parser) ocfl.add_object_args(parser) parser.add_argument('--verbose', '-v', action='store_true', help="be more verbose") return parser.parse_args()
def parse_arguments(): """Parse command line arguments.""" parser = argparse.ArgumentParser( description='Manipulate or validate an OCFL object or inventory.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) # This should really be done with add_mutually_exclusive_group() but # the current argparse doesn't support grouping and a title for that # so use a plain group instead and will check later commands = parser.add_argument_group( title="Commands (exactly one required)") commands.add_argument( '--create', action='store_true', help= 'Create a new object with version 1 files in --srcdir or from --srcbag' ) commands.add_argument( '--build', action='store_true', help='Build a new object from version directories in --srcdir') commands.add_argument( '--update', action='store_true', help= 'Update an object by adding a new version from files in --srcdir or from --srcbag' ) commands.add_argument('--show', action='store_true', help='Show versions and files in an OCFL object') commands.add_argument( '--validate', action='store_true', help='Validate an OCFL object (use ocfl-validate.py for more control)') commands.add_argument( '--extract', action='store', default=None, help='Extract a specific version (or "head") into --dstdir') src_params = parser.add_argument_group(title="Source files") src_params.add_argument('--srcdir', '--src', action='store', help='Source directory path') src_params.add_argument( '--srcbag', action='store', help='Source Bagit bag path (alternative to --srcdir)') obj_params = parser.add_argument_group(title="OCFL object parameters") obj_params.add_argument('--digest', default='sha512', help='Digest algorithm to use') obj_params.add_argument('--fixity', action='append', help='Add fixity type to add') obj_params.add_argument('--id', default=None, help='Identifier of object') obj_params.add_argument('--dstdir', '--dst', action='store', default='/tmp/ocfl-out', help='Destination directory path') obj_params.add_argument( '--dstbag', action='store', help='Destination Bagit bag path (alternative to --dstdir)') # Version metadata and object settings ocfl.add_version_metadata_args(obj_params) ocfl.add_object_args(obj_params) ocfl.add_shared_args(parser) args = parser.parse_args() ocfl.check_shared_args(args) # Require command and only one command cmds = ['create', 'build', 'update', 'show', 'validate', 'extract'] num_cmds = 0 for cmd in cmds: if getattr(args, cmd): num_cmds += 1 if num_cmds != 1: raise FatalError("Exactly one command (%s) must be specified" % ', '.join(cmds)) # Must not specify both srcdir and srcbag if args.srcdir and args.srcbag: raise FatalError("Must not specify both --srcdir and --srcbag") return args
help='Show versions and files in an OCFL object') commands.add_argument('--validate-object', action='store_true', help='Validate an OCFL object') # Object property settings parser.add_argument('--id', default=None, help='identifier of object') parser.add_argument('--src', default=None, help='source path of object or version') parser.add_argument('--digest', default='sha512', help='digest type to use') parser.add_argument('--fixity', action='append', help='add fixity type to add') # Version metadata and object settings ocfl.add_version_metadata_args(parser) ocfl.add_object_args(parser) ocfl.add_shared_args(parser) args = parser.parse_args() ocfl.check_shared_args(args) logging.basicConfig(level=logging.INFO if args.verbose else logging.WARN) try: store = ocfl.Store(root=args.root, disposition=args.disposition, lax_digests=args.lax_digests) if args.init: store.initialize() elif args.list: store.list() elif args.validate: