def main(args):
    global find_syndrome

    optp = optparse.OptionParser(
        usage='usage: %prog xmlimport [options] <xmlfile>')
    cmdcommon.opt_syndrome(optp)
    cmdcommon.opt_user(optp)
    optp.add_option('-d', '--data-src', default='xmlimport',
                    help='Set data source to DATA_SRC')
    options, args = optp.parse_args(args)

    try:
        xmlfile, = args
    except ValueError:
        optp.error('exactly 1 argument needed')

    cred = cmdcommon.user_cred(options)

    find_syndrome = SyndromeCache(options.syndrome).find_syndrome

    context = iter(iterparse(open(xmlfile), events=('start','end')))
    event, root = context.next()

    def yield_nodes(nodename):
        for event, elem in context:
            if event == 'end' and elem.tag == nodename:
                yield elem
                root.clear()

    if root.tag == 'Cases':
        proc_cases(options, cred, yield_nodes('Case'))
    elif root.tag == 'Persons':
        proc_persons(options, cred, yield_nodes('Person'))
    else:
        cmdcommon.abort('Root of XML tree is not a <Cases> tag nor <Persons> tag')
Beispiel #2
0
def main(args):
    """
    Parse arguments and simulate the use of the export page
    """

    optp = get_option_parser()
    options, args = optp.parse_args(args)

    cred = cmdcommon.user_cred(options)

    syndrome_id = cmdcommon.get_syndrome_id(options.syndrome)

    es = get_export_scheme_instance(cred, syndrome_id, optp, options, args)

    # Some simple validity checks
    if not options.queue_field and not options.default_queue:
        optp.error('No queue field specified')
    if not options.monitored_fields:
        optp.error('No fields specified to monitor')

    cache_filter = CacheFilter(es, options)

    # Generate tasks for changed cases
    tasks.workqueues.load()
    queue_ids = {}
    for q in tasks.workqueues:
        queue_ids[q.name] = q.queue_id
    for row, changed_values in cache_filter:
        case_id = row['case_id']
        task = tasks.EditTask(globals.db, cred, case_id=case_id)
        # either queue_field or default_queue must be set
        if options.queue_field:
            queue_name = row[options.queue_field]
            if options.queue_mapping:
                queue_name = options.queue_mapping[queue_name]
            if options.default_queue and not queue_name:
                queue_name = options.default_queue
        else:
            queue_name = options.default_queue
        task.set_queue_id(globals.db, queue_ids[queue_name])
        task.action = tasks.ACTION_UPDATE_CASE
        task.task_description = "Case %s has changed fields: %s" % (
            case_id, ", ".join([v[0] for v in changed_values]))
        task.update(globals.db)
        cache_filter.update_cache(row)

    # Commit the changes to the database
    if not options.dry_run:
        globals.db.commit()

    # Clean up
    cache_filter.commit()
def main(args):
    """
    Parse arguments and simulate the use of the export page
    """

    optp = get_option_parser()
    options, args = optp.parse_args(args)

    cred = cmdcommon.user_cred(options)

    syndrome_id = cmdcommon.get_syndrome_id(options.syndrome)

    es = get_export_scheme_instance(cred, syndrome_id, optp, options, args)

    # Some simple validity checks
    if not options.queue_field and not options.default_queue:
        optp.error('No queue field specified')
    if not options.monitored_fields:
        optp.error('No fields specified to monitor')

    cache_filter = CacheFilter(es, options)

    # Generate tasks for changed cases
    tasks.workqueues.load()
    queue_ids = {}
    for q in tasks.workqueues:
        queue_ids[q.name] = q.queue_id
    for row, changed_values in cache_filter:
        case_id = row['case_id']
        task = tasks.EditTask(globals.db, cred, case_id=case_id)
        # either queue_field or default_queue must be set
        if options.queue_field:
            queue_name = row[options.queue_field]
            if options.queue_mapping:
                queue_name = options.queue_mapping[queue_name]
            if options.default_queue and not queue_name:
                queue_name = options.default_queue
        else:
            queue_name = options.default_queue
        task.set_queue_id(globals.db, queue_ids[queue_name])
        task.action = tasks.ACTION_UPDATE_CASE
        task.task_description = "Case %s has changed fields: %s" % (case_id, ", ".join([v[0] for v in changed_values]))
        task.update(globals.db)
        cache_filter.update_cache(row)

    # Commit the changes to the database
    if not options.dry_run:
        globals.db.commit()

    # Clean up
    cache_filter.commit()
def main(args):
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)
    cmdcommon.opt_outfile(optp)
    options, args = optp.parse_args(args)
    if len(args) != 1:
        optp.usage()

    report_id = cmdcommon.get_report_id(args[0])

    cred = cmdcommon.user_cred(options)

    params = reports.load(report_id, cred)
    cmdcommon.safe_overwrite(options, params.xmlsave, cmdcommon.OUTFILE)
def main(args):
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)
    cmdcommon.opt_outfile(optp)
    options, args = optp.parse_args(args)
    if len(args) != 1:
        optp.usage()

    report_id = cmdcommon.get_report_id(args[0]) 

    cred = cmdcommon.user_cred(options)

    params = reports.load(report_id, cred)
    cmdcommon.safe_overwrite(options, params.xmlsave, cmdcommon.OUTFILE)
def main(args):
    """
    Parse arguments and simulate the use of the export page
    """

    optp = get_option_parser()
    options, args = optp.parse_args(args)


    cred = cmdcommon.user_cred(options)

    syndrome_id = cmdcommon.get_syndrome_id(options.syndrome)

    es = exportselect.ExportSelect(syndrome_id)
    es.deleted = options.deleted
    es.strip_newlines = options.strip_newlines

    # Parse export scheme specification
    schemes = [scheme for scheme, description in es.scheme_options()]
    if options.export_scheme == '?' or options.export_scheme not in schemes:
        print 'Export schemes:'
        print_indexed_list(list(es.scheme_options()))
        sys.exit(1)
    es.export_scheme = options.export_scheme

    es.refresh(cred)
    exporter = es.exporter

    # Parse forms (if any)
    if '?' in args:
        print 'Forms:'
        forms = [(form.label, form.name) for form in exporter.forms]
        print_indexed_list(forms)
        sys.exit(1)
    formnames = [form.label for form in exporter.forms]
    for name in args:
        if name not in formnames:
            optp.error('form %r not found (for this syndrome?)' % name)
    include_forms = args

    # load the data and export
    cmdcommon.safe_overwrite(options, exporter.csv_write, 
                             include_forms, cmdcommon.OUTFILE)
Beispiel #7
0
def main(args):
    """
    Parse arguments and simulate the use of the export page
    """

    optp = get_option_parser()
    options, args = optp.parse_args(args)

    cred = cmdcommon.user_cred(options)

    syndrome_id = cmdcommon.get_syndrome_id(options.syndrome)

    es = exportselect.ExportSelect(syndrome_id)
    es.deleted = options.deleted
    es.strip_newlines = options.strip_newlines

    # Parse export scheme specification
    schemes = [scheme for scheme, description in es.scheme_options()]
    if options.export_scheme == '?' or options.export_scheme not in schemes:
        print 'Export schemes:'
        print_indexed_list(list(es.scheme_options()))
        sys.exit(1)
    es.export_scheme = options.export_scheme

    es.refresh(cred)
    exporter = es.exporter

    # Parse forms (if any)
    if '?' in args:
        print 'Forms:'
        forms = [(form.label, form.name) for form in exporter.forms]
        print_indexed_list(forms)
        sys.exit(1)
    formnames = [form.label for form in exporter.forms]
    for name in args:
        if name not in formnames:
            optp.error('form %r not found (for this syndrome?)' % name)
    include_forms = args

    # load the data and export
    cmdcommon.safe_overwrite(options, exporter.csv_write, include_forms,
                             cmdcommon.OUTFILE)
def main(args):
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)
    cmdcommon.opt_verbose(optp)
    options, args = optp.parse_args(args)

    cred = cmdcommon.user_cred(options)

    globals.notify = notify_connect(config.cgi_target,
                                    config.notification_host,
                                    config.notification_port)

    try:
        mp = persondupe.MatchPersons(globals.db, None)
        mp.save(globals.db)
        if options.verbose:
            print mp.stats()
            mp.report()
        globals.db.commit()
    except persondupe.DupeRunning:
        cmdcommon.abort('Already running')
def main(args):
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)
    cmdcommon.opt_outfile(optp)
    cmdcommon.opt_syndrome(optp)
    optp.add_option('--csv', action='store_true',
            help='For line report, use CSV format (default)')
    optp.add_option('--html', action='store_true',
            help='For line report, use HTML format')
    optp.add_option('-p', '--param-file', metavar='FILENAME',
                    help='Read report parameters from FILENAME')
    options, args = optp.parse_args(args)
    if options.param_file and args:
        optp.error('Specify a parameter file OR report name, not both')

    cred = cmdcommon.user_cred(options)

    if args:
        if len(args) > 1:
            optp.error('Specify only one report name')
        report_id = cmdcommon.get_report_id(args[0]) 
        params = reports.load(report_id, cred)
    elif options.param_file:
        if not options.syndrome:
            optp.error('Specify a syndrome')
        syndrome_id = cmdcommon.get_syndrome_id(options.syndrome)
        try:
            f = open(options.param_file, 'rU')
        except EnvironmentError, (eno, estr):
            cmdcommon.abort('%s: %s' % (options.param_file, estr))
        try:
            try:
                params = reports.parse_file(syndrome_id, f)
            finally:
                f.close()
        except reports.Error, e:
            cmdcommon.abort('%s: %s' % (options.param_file, e))