Beispiel #1
0
def main():
    extensions = {(URL_MLR_EXT, 'vcard_uuid'): utils.vcard_uuid}
    converterExtract = XMLTransform(STYLESHEET_EXTRACT, extensions)
    converterDup = XMLTransform(STYLESHEET_DUP)
    parser = argparse.ArgumentParser(
        description='Extend the vcard of a lom into a xcard')
    parser.add_argument('-f', '--format', default='rawxml',
                        help="output format: one of 'rawxml', 'xml', 'n3',"
                             " 'turtle', 'nt', 'pretty-xml', trix'")
    parser.add_argument('-o', '--output', help="Output file",
                        type=argparse.FileType('w'), default=sys.stdout)
    parser.add_argument('infile', help="input file or url", nargs="?")
    converterExtract.populate_argparser(parser)
    #converterDup.populate_argparser(parser)
    args = parser.parse_args()
    converterExtract.set_options_from_dict(vars(args))
    #converterDup.set_options_from_dict(vars(args))
    
    if (urlparse(args.infile).scheme):
        opener = urlopen
    else:
        opener = open

    with opener(args.infile) as infile:
        xml = converterExtract.convertfile(infile)
    if xml:
        xml = converterDup.convertxml(xml)
    if xml:
        if args.format == "rawxml":
            args.output.write(etree.tounicode(xml, pretty_print=True).encode('utf-8'))
        else:
            rdf = Graph().parse(data=etree.tounicode(xml), format="xml")
            if rdf:
                args.output.write(rdf.serialize(format=args.format, encoding='utf-8'))
    args.output.close()
Beispiel #2
0
 def __init__(self):
     extensions = {(VCARDC_NS, 'convert'): convert}
     XMLTransform.__init__(self, STYLESHEET, extensions)