Ejemplo n.º 1
0
 def test_1010(self, cn_client_v1_v2):
     """generate_from_file_path()"""
     sysmeta_path = self.sample.get_path('systemMetadata_v2_0.xml')
     sysmeta_pyxb = sysmeta.generate_from_file_path(cn_client_v1_v2,
                                                    sysmeta_path)
     self.sample.assert_equals(sysmeta_pyxb,
                               'inst_gen_generate_from_file_path',
                               cn_client_v1_v2)
Ejemplo n.º 2
0
def processDoc(fname, options={}):
    """Generate system metadata XML for file fname
  """
    #add script arguments to a comment in the generated metadata
    tnow = datetime.datetime.utcnow().isoformat()
    comment = lxml.etree.Comment(
        "Warning: This file was generated by an automated process. Manual edits may "
        "be overwritten without further warning.\n"
        "timestamp:: %s\n"
        "created_with:: generate_sysmeta.py\n"
        "arguments:: %s\n"
        "command:: generate_sysmeta.py %s\n" %
        (tnow, repr(sys.argv[1:]), " ".join(sys.argv[1:])))
    sysm = system_metadata.generate_from_file_path(fname, options)
    root = lxml.etree.fromstring(sysm.toxml('utf-8'))
    root.insert(0, comment)
    pxml = lxml.etree.tostring(root,
                               pretty_print=True,
                               encoding='utf-8',
                               xml_declaration=True)
    return pxml
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument('path', help='Path to science metadata file')
    parser.add_argument('--debug',
                        action='store_true',
                        help='Debug level logging')

    args = parser.parse_args()

    d1_common.util.log_setup(args.debug)

    cn_client = d1_client.cnclient_2_0.CoordinatingNodeClient_2_0(
        base_url=d1_common.const.URL_DATAONE_ROOT)

    sysmeta_pyxb = gen_sysmeta.generate_from_file_path(
        cn_client,
        args.path,
        {
            'identifier': 'test_pid',
            'formatId': 'http://www.isotc211.org/2005/gmd',
            'accessPolicy': None,
            'replicationPolicy': None,
            'obsoletes': None,
            'obsoletedBy': None,
            'archived': None,
            'replica': None,
            'mediaType': None,
        },
    )

    with open(args.path, 'rb') as f:
        sciobj_str = f.read()

    response = cn_client.echoIndexedObject('solr', sysmeta_pyxb,
                                           StringIO.StringIO(sciobj_str))

    print(d1_common.xml.pretty_xml(response.content))
Ejemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument('--debug',
                        action='store_true',
                        help='Debug level logging')
    parser.add_argument('--env',
                        type=str,
                        default='prod',
                        help='Environment, one of {}'.format(', '.join(
                            d1_common.env.D1_ENV_DICT)))
    parser.add_argument('--cert-pub',
                        dest='cert_pem_path',
                        action='store',
                        help='Path to PEM formatted public key of certificate')
    parser.add_argument(
        '--cert-key',
        dest='cert_key_path',
        action='store',
        help='Path to PEM formatted private key of certificate')
    parser.add_argument(
        '--timeout',
        action='store',
        default=d1_common.const.DEFAULT_HTTP_TIMEOUT,
        help='Amount of time to wait for calls to complete (seconds)')

    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument('path', help='Path to science metadata file')
    parser.add_argument('--debug',
                        action='store_true',
                        help='Debug level logging')

    args = parser.parse_args()

    d1_common.util.log_setup(args.debug)

    cn_client = d1_client.cnclient_2_0.CoordinatingNodeClient_2_0(
        base_url=d1_common.const.URL_DATAONE_ROOT)

    sysmeta_pyxb = gen_sysmeta.generate_from_file_path(
        cn_client,
        args.path,
        {
            'identifier': 'test_pid',
            'formatId': 'http://www.isotc211.org/2005/gmd',
            'accessPolicy': None,
            'replicationPolicy': None,
            'obsoletes': None,
            'obsoletedBy': None,
            'archived': None,
            'replica': None,
            'mediaType': None,
        },
    )

    with open(args.path, 'rb') as f:
        sciobj_bytes = f.read()

    response = cn_client.echoIndexedObject('solr', sysmeta_pyxb,
                                           io.BytesIO(sciobj_bytes))

    print(d1_common.xml.format_pretty_xml(response.content))