def main(argv): """ Pokes at a DataONE object's system metadata Usage: poke.py pid <pid> poke.py file <file> poke.py defaults Arguments: pid Pid of object to poke file File containing pid(s) (one per line) of objects to poke defaults Print default properties to stdout """ args = docopt(str(main.__doc__)) if args['defaults']: properties.dump() return 0 pids = [] if args['pid']: pids.append(args['<pid>']) elif args['file']: with open(args['<file>'], 'r') as fn: pid_list = [_.strip() for _ in fn.readlines()] for pid in pid_list: pids.append(pid) base_url = properties.BASE_URL cert_pem_path = properties.CERT_PEM cert_key_path = properties.CERT_KEY client = MemberNodeClient_2_0( base_url=base_url, cert_pem_path=cert_pem_path, cert_key_path=cert_key_path, verify_tls=properties.VERIFY_TLS, ) for pid in pids: sysmeta = client.getSystemMetadata(pid=pid) mod_sysmeta = mod_system_metadata(sysmeta=sysmeta) client.updateSystemMetadata(pid=pid, sysmeta_pyxb=mod_sysmeta) return 0
def dump(self): """ Show the object content """ global _createdDirs print '### Created Dir Objects' print ' ', '\n '.join(_createdDirs.keys()) for (a, go), d in _createdDirs.items(): print '### Dir: ', a print ' Rules: ', d.executed_rules print ' Prev dir: ', d.previous_dir print ' Given dict: ', go print ' Options:\n ', properties.dump(self.options, ' ')
def main(argv): """ Peeks at a DataONE Member Node object's system metadata Usage: peek.py pid <pid> [--v1] [-n | --node <node>] [-c | --cert <cert>] [-k | --key <key>] [-a | --attr <attr>] [--header] [--to_xml] peek.py file <file> [--v1] [-n | --node <node>] [-c | --cert <cert>] [-k | --key <key>] [-a | --attr <attr>] [--header] [--to_xml] peek.py defaults peek.py -h | --help Arguments: pid Pid of object to peek file File containing pid(s) (one per line) of objects to peek defaults Print default properties to stdout Options: -h --help This page -n --node Target node (either member or coordinating) -c --cert Client certificate -k --key Client certificate key -a --attr Comma separated list of sysmeta attributes to display (none for all) --v1 Version 1 client (defaults to version 2) --header Add header line --to_xml Export as XML """ args = docopt(str(main.__doc__)) if args['defaults']: properties.dump() return 0 pids = {} if args['pid']: pids[args['<pid>']] = {'pid': args['<pid>']} elif args['file']: with open(args['<file>'], 'r') as fn: pid_list = [_.strip() for _ in fn.readlines()] for pid in pid_list: pids[pid] = {'pid': pid} if args['--node']: base_url = args['<node>'] else: base_url = properties.BASE_URL if args['--cert']: cert_pem_path = args['<cert>'] if cert_pem_path == 'None': cert_pem_path = None else: cert_pem_path = properties.CERT_PEM if args['--key']: cert_key_path = args['<key>'] if cert_key_path == 'None': cert_key_path = None else: cert_key_path = properties.CERT_KEY add_header_line = False if args['--header']: add_header_line = True attributes = () if args['--attr']: attributes = [ _.strip() for _ in args['<attr>'].split(',')] else: attributes = ['checksum', 'size', 'replica', 'archived', 'rights_holder'] to_xml = False if args['--to_xml']: to_xml = True if args['--v1']: client = MemberNodeClient_1_1(base_url=base_url, cert_pem_path=cert_pem_path, cert_key_path=cert_key_path, verify_tls=properties.VERIFY_TLS, ) else: client = MemberNodeClient_2_0(base_url=base_url, cert_pem_path=cert_pem_path, cert_key_path=cert_key_path, verify_tls=properties.VERIFY_TLS, ) dead_pids = [] for pid in pids: try: sm = client.getSystemMetadata(pid=pid) pids[pid]['xml'] = sm.toxml() except Exception as e: logger.error('{pid}: {e}'.format(pid=pid, e=e)) dead_pids.append(pid) if 'checksum' in attributes: pids[pid]['checksum'] = sm.checksum.algorithm + ',' + sm.checksum.value() if 'size' in attributes: pids[pid]['size'] = sm.size if 'replica' in attributes: try: pids[pid]['replica'] = replicas(sm.replica) except Exception as e: pids[pid]['replica'] = '' if 'archived' in attributes: try: pids[pid]['archived'] = sm.archived except Exception as e: pids[pid]['archived'] = '' if 'rights_holder' in attributes: pids[pid]['rights_holder'] = '\'' + sm.rightsHolder.value() + '\'' clean_pids(pids, dead_pids) for pid in pids: if to_xml: xml = pretty_xml(pids[pid]['xml']) print('{xml}'.format(xml=xml)) else: print('{pid}'.format(pid=pid), end=',') if 'checksum' in attributes: checksum = pids[pid]['checksum'] print('{checksum}'.format(checksum=checksum), end=',') if 'size' in attributes: size = pids[pid]['size'] print('{size}'.format(size=size), end=',') if 'replica' in attributes: replica = pids[pid]['replica'] print('{replica}'.format(replica=replica), end=',') if 'archived' in attributes: archived = pids[pid]['archived'] print('{archived}'.format(archived=archived), end=',') if 'rights_holder' in attributes: rights_holder = pids[pid]['rights_holder'] print('{rights_holder}'.format(rights_holder=rights_holder), end=', ') print() return 0
def main(argv): """ Lists obsolescence chain of a DataONE object. Usage: chains.py pid <pid> [-n | --node <node>] [-c | --cert <cert>] [-k | --key <key>] chains.py defaults chains.py (-h | --help) Arguments: pid Persistent identifier of object defaults Print default properties to stdout Options: -h --help This page -n --node Target node (either member or coordinating) -c --cert Client certificate -k --key Client certificate key """ args = docopt(str(main.__doc__)) if args['defaults']: properties.dump() return 0 pid = args['<pid>'] if args['--node']: base_url = args['<node>'] else: base_url = properties.BASE_URL if args['--cert']: cert_pem_path = args['<cert>'] if cert_pem_path == 'None': cert_pem_path = None else: cert_pem_path = properties.CERT_PEM if args['--key']: cert_key_path = args['<key>'] if cert_key_path == 'None': cert_key_path = None else: cert_key_path = properties.CERT_KEY mn_client = MemberNodeClient_2_0( base_url=base_url, cert_pem_path=cert_pem_path, cert_key_path=cert_key_path, verify_tls=properties.VERIFY_TLS, ) # Find oldest pid current_pid = None while pid is not None: current_pid = pid pid = predecessor(pid, mn_client) pid = current_pid # Walk obsolescence chain from oldest pid to newest pid pids = [] while pid is not None: pids.append(pid) pid = successor(pid, mn_client) for pid in pids: print(pid) return 0
def main(argv): """A DataONE tool to manually replicate content from one node to another Replicates objects, including system metadata, from one DataONE member node to another member node, with the option of modifying system metadata attributes. It is assumed that the destination member node base URL, certificate, and private key are specified in the properties. Usage: replicator.py pid <pid> <src_mn> [-c | --cert <cert>] [-k | --key <key>] replicator.py file <file> <src_mn> [-c | --cert <cert>] [-k | --key <key>] replicator.py defaults replicator.py -h | --help Arguments: pid Pid of object to replicate file File of pids of objects to replicate one per line src_mn Base URL of the source member node (or path on local file system from / where objects reside) defaults Prints default properties to stdout Options: -h --help This page -c --cert Client certificate of source member node (if needed to access private content) -k --key Client private key of source member node (if needed to access private content) """ args = docopt(str(main.__doc__)) if args['defaults']: properties.dump() return 0 pids = [] if args['pid']: pids.append(args['<pid>']) else: try: with open(args['<file>'], 'rt') as f: for pid in f: pids.append(pid.strip()) except IOError as e: logger.error(e) return 1 src_mn = args['<src_mn>'] if args['--cert'] and args['--key']: src_cert = args['<cert>'] src_key = args['<key>'] else: src_cert = None src_key = None src = {'src_mn': src_mn, 'src_cert': src_cert, 'src_key': src_key} logger.info(len(pids)) cnt = 0 for pid in pids: cnt += 1 information = '{cnt}: {pid}'.format(cnt=cnt, pid=pid) logger.info(information) obj = get_object(pid=pid, src=src) sys_meta = get_sys_meta(pid=pid, src=src) modify_sys_meta(sys_meta=sys_meta) try: replicate_object(pid=pid, obj=obj, sys_meta=sys_meta) except d1_common.types.exceptions.DataONEException as e: logger.error(e) return 0
def main(): """ List objects at a DataONE Member Node Usage: list_objects.py [--v1] [-n | --node <node>] [-c | --cert <cert>] [-k | --key <key>] list_objects.py defaults list_objects.py -h | --help Arguments: defaults Print default properties to stdout Options: -h --help This page -n --node Target node (either member or coordinating) -c --cert Client certificate -k --key Client certificate key """ args = docopt(str(main.__doc__)) if args['defaults']: properties.dump() return 0 if args['--node']: base_url = args['<node>'] else: base_url = properties.BASE_URL if args['--cert']: cert_pem_path = args['<cert>'] if cert_pem_path == 'None': cert_pem_path = None else: cert_pem_path = properties.CERT_PEM if args['--key']: cert_key_path = args['<key>'] if cert_key_path == 'None': cert_key_path = None else: cert_key_path = properties.CERT_KEY if args['--v1']: client = MemberNodeClient_1_1( base_url=base_url, cert_pem_path=cert_pem_path, cert_key_path=cert_key_path, verify_tls=properties.VERIFY_TLS, ) else: client = MemberNodeClient_2_0( base_url=base_url, cert_pem_path=cert_pem_path, cert_key_path=cert_key_path, verify_tls=properties.VERIFY_TLS, ) objects = ObjectListIterator(client=client) for obj in objects: print('{pid}'.format(pid=obj.identifier.value())) return 0