def get_option_parser():
    """
    Create the option parser for the script
    """
    usage = '%prog [options] -s syndrome [forms] (use \\? for a list)'
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)
    cmdcommon.opt_outfile(optp)
    cmdcommon.opt_syndrome(optp)
    optp.set_defaults(export_scheme="classic", 
                      deleted='n', strip_newlines=False)
    optp.add_option("-x", "--exclude-deleted", dest="deleted",
            action="store_const", const='n',
            help="exclude deleted records from output")
    optp.add_option("-d", "--include-deleted", dest="deleted",
            action="store_const", const="both", 
            help="include deleted records in output")
    optp.add_option("--only-deleted", dest="deleted",
            action="store_const", const='y',
            help="include deleted records in output")
    optp.add_option("-l", "--strip-newlines", dest="strip_newlines",
            action="store_true",
            help="replace newlines embedded in fields with spaces")
    optp.add_option("-S", "--scheme", dest="export_scheme",
            help="export using EXPORTSCHEME, default 'classic'. Use '\\?' "
                 "to see a list of available schemes.", metavar="EXPORTSCHEME")
    return optp
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')
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 get_option_parser():
    """
    Create the option parser for the script
    """
    usage = '%prog [options] <form_id> <form_id> ... (use ? for a list)'
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)

    optg = OptionGroup(optp, 'Queue options')
    optg.add_option('--queue-field', metavar='FIELD',
            help='field containing the destination task queue name')
    optg.add_option('-Q', '--queue-mapping', metavar='VALUE::QUEUE',
            help='a mapping from a queue field value to a task queue name')
    optg.add_option('-T', '--default-queue', metavar='QUEUE',
            help='the default task queue name') 
    optp.add_option_group(optg)

    optg = OptionGroup(optp, 'Cache options')
    optg.add_option('-S', '--state-file', default=None, metavar='FILENAME',
            help='keep state in FILENAME') 
    optg.add_option('-m', '--monitor-field', dest='monitored_fields',
            default=[], action='append', metavar='FIELD',
            help='field to watch (may be specified multiple times)') 
    optp.add_option_group(optg)

    optg = OptionGroup(optp, 'Export options')
    cmdcommon.opt_syndrome(optg)
    optg.add_option('--exclude-deleted', dest='include_deleted',
            action='store_false',
            help='exclude deleted records from output (default)')
    optg.add_option('--include-deleted', dest='include_deleted',
            default=False, action='store_const', const='', 
            help='include deleted records in output')
    optg.add_option('--only-deleted', dest='include_deleted',
            action='store_true',
            help='include only deleted records in output')
    optg.add_option('--scheme', dest='export_scheme',
            default='classic', metavar='SCHEME',
            help='export using SCHEME [default: %default]. Use "?" '
                 'to see a list of available schemes.') 
    optp.add_option_group(optg)

    return optp
Beispiel #6
0
def get_option_parser():
    """
    Create the option parser for the script
    """
    usage = '%prog [options] -s syndrome [forms] (use \\? for a list)'
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)
    cmdcommon.opt_outfile(optp)
    cmdcommon.opt_syndrome(optp)
    optp.set_defaults(export_scheme="classic",
                      deleted='n',
                      strip_newlines=False)
    optp.add_option("-x",
                    "--exclude-deleted",
                    dest="deleted",
                    action="store_const",
                    const='n',
                    help="exclude deleted records from output")
    optp.add_option("-d",
                    "--include-deleted",
                    dest="deleted",
                    action="store_const",
                    const="both",
                    help="include deleted records in output")
    optp.add_option("--only-deleted",
                    dest="deleted",
                    action="store_const",
                    const='y',
                    help="include deleted records in output")
    optp.add_option("-l",
                    "--strip-newlines",
                    dest="strip_newlines",
                    action="store_true",
                    help="replace newlines embedded in fields with spaces")
    optp.add_option(
        "-S",
        "--scheme",
        dest="export_scheme",
        help="export using EXPORTSCHEME, default 'classic'. Use '\\?' "
        "to see a list of available schemes.",
        metavar="EXPORTSCHEME")
    return optp
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))
Beispiel #9
0
def get_option_parser():
    """
    Create the option parser for the script
    """
    usage = '%prog [options] <form_id> <form_id> ... (use ? for a list)'
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)

    optg = OptionGroup(optp, 'Queue options')
    optg.add_option('--queue-field',
                    metavar='FIELD',
                    help='field containing the destination task queue name')
    optg.add_option(
        '-Q',
        '--queue-mapping',
        metavar='VALUE::QUEUE',
        help='a mapping from a queue field value to a task queue name')
    optg.add_option('-T',
                    '--default-queue',
                    metavar='QUEUE',
                    help='the default task queue name')
    optp.add_option_group(optg)

    optg = OptionGroup(optp, 'Cache options')
    optg.add_option('-S',
                    '--state-file',
                    default=None,
                    metavar='FILENAME',
                    help='keep state in FILENAME')
    optg.add_option('-m',
                    '--monitor-field',
                    dest='monitored_fields',
                    default=[],
                    action='append',
                    metavar='FIELD',
                    help='field to watch (may be specified multiple times)')
    optp.add_option_group(optg)

    optg = OptionGroup(optp, 'Export options')
    cmdcommon.opt_syndrome(optg)
    optg.add_option('--exclude-deleted',
                    dest='include_deleted',
                    action='store_false',
                    help='exclude deleted records from output (default)')
    optg.add_option('--include-deleted',
                    dest='include_deleted',
                    default=False,
                    action='store_const',
                    const='',
                    help='include deleted records in output')
    optg.add_option('--only-deleted',
                    dest='include_deleted',
                    action='store_true',
                    help='include only deleted records in output')
    optg.add_option('--scheme',
                    dest='export_scheme',
                    default='classic',
                    metavar='SCHEME',
                    help='export using SCHEME [default: %default]. Use "?" '
                    'to see a list of available schemes.')
    optp.add_option_group(optg)

    return optp