def process_instance(context, xfinst, xform_path): inst = util.strip_namespaces(et.fromstring(xfinst)) return convert_odm(context, util.xmlfile(xfinst), load_source(xform_path=xform_path)) def load_source(xform_path=None, crf_path=None): if not xform_path and not crf_path: return None with open(xform_path or crf_path) as f: if xform_path: return et.parse(f).getroot() else: return convert_xform(f) if __name__ == "__main__": parser = OptionParser() parser.add_option("-x", "--xform", dest="xform", help="source xform", metavar="FILE") parser.add_option("-f", "--crf", dest="crf", help="source CRF", metavar="FILE") (options, args) = parser.parse_args() inst = (sys.stdin if args[0] == '-' else open(args[0])) submission = convert_odm(inst, load_source(options.xform, options.crf)) print util.dump_xml(submission['odm'], pretty=True) del submission['odm'] util.pprint(submission)
'study_events': parsed_info['events'], 'crfs': list(build_all()), 'errors': errors, } if __name__ == "__main__": parser = OptionParser() parser.add_option("-t", "--translations", dest="translations", help="load translations from FILE", metavar="FILE") parser.add_option("-d", "--dumptext", action="store_true", dest="dumptx", default=False, help="dump english text to csv for translation") parser.add_option("-o", "--opts", dest="options", default='{}', help="custom options as json string") (options, args) = parser.parse_args() opts = options.__dict__ opts.update(json.loads(options.options)) crf = (sys.stdin if args[0] == '-' else open(args[0])) print util.dump_xml(convert_xform(crf, opts), pretty=True)
def submit(conn, instnode): odm_raw = util.dump_xml(util.strip_namespaces(instnode)) resp = getattr(conn.service, 'import')(Raw(odm_raw)) if resp.result.lower() != 'success': raise Exception([str(e) for e in resp.error])