Exemple #1
0
def _proc_evt_result(cmd, args):
    """Return a result."""
    global result_opts
    cmd = cmd.lower()
    text_result = {'warning':'warn', 'error':'fail'}.get(cmd, cmd)
    evt_result = __TEXT_RESULT_TO_BEAH.get(text_result[:4])
    if not result_opts:
        result_opts = OptionParser(usage="%prog [OPTIONS] MESSAGE",
                description="Return a %prog result.")
        result_opts.disable_interspersed_args()
        result_opts.add_option("-H", "--handle", action="store",
                dest="handle", help="result handle", type="string",
                default="")
        result_opts.add_option("-s", "--score", action="store",
                dest="score", help="result score", default="0.0", type="float")
        result_opts.add_option("-f", "--file", action="append",
                dest="files", help="Attach a file.")
    result_opts.prog = text_result
    opts, args = result_opts.parse_args(args)
    statistics = {}
    if opts.score:
        statistics["score"] = opts.score
    s = AppendingSender()
    r = beahlib.get_task(s).result(evt_result, handle=opts.handle,
            message=" ".join(args), statistics=statistics)
    attach(r, opts.files)
    return s.get_events()
Exemple #2
0
def proc_evt_upload(cmd, args):
    """Upload a file."""
    global upload_opts
    if not upload_opts:
        upload_opts = OptionParser(usage="%prog FILES",
                description="Attach FILES to the current task.")
        upload_opts.prog = "upload"
    opts, args = upload_opts.parse_args(args)
    s = AppendingSender()
    t = beahlib.get_task(s)
    attach(t, args)
    return s.get_events()
Exemple #3
0
def proc_evt_upload(cmd, args):
    """Upload a file."""
    global upload_opts
    if not upload_opts:
        upload_opts = OptionParser(
            usage="%prog FILES",
            description="Attach FILES to the current task.")
        upload_opts.prog = "upload"
    opts, args = upload_opts.parse_args(args)
    s = AppendingSender()
    t = beahlib.get_task(s)
    attach(t, args)
    return s.get_events()
Exemple #4
0
def _main(args, default_sender='socket'):
    errs = 0
    main_opts = OptionParser(
            usage="%prog [OPTIONS] COMMAND [COMMAND-OPTIONS] [COMMAND-ARGS]",
            description="""Create events to be consumed by the harness.""")
    main_opts.disable_interspersed_args()
#If there is no COMMAND specified, stdin is processed line by line.
    main_opts.add_option("-c", "--command", action="append", dest="commands",
            help="Run COMMAND. This option could be specified multiple times.",
            metavar="COMMAND", nargs=1, type="string")
    main_opts.add_option("-x", "--nostdin", action="store_true", dest="nostdin",
            help="Do not process stdin if there is no COMMAND", default=False)
    main_opts.add_option("--help-commands", action="callback", nargs=0,
            callback=help_commands, callback_kwargs={'help':True},
            help="Print short help on available commands.")
    main_opts.add_option("--list-commands", action="callback", nargs=0,
            callback=help_commands,
            help="Print list of available commands.")
    main_opts.add_option("-i", "--print-id", action="store_true",
            dest="print_id", help="Print event id on stderr.")
    main_opts.add_option("-I", "--print-all-ids", action="store_true",
            dest="print_all_ids", help="Print all event ids on stderr.")
    main_opts.add_option("-S", "--use-socket", action="store_const",
            const="socket", dest="sender",
            help="Use socket for communication with server.")
    main_opts.add_option("--use-stdout", action="store_const",
            const="stdout", dest="sender",
            help="""Use stdout for communication with server.
                NOTE: Don't use this unless you know what you are doing.""")
    opts, args = main_opts.parse_args(args)
    the_task = beahlib.get_task(make_sender(opts.sender or default_sender, opts))
    if opts.commands:
        for line in opts.commands:
            if not _run(shlex.split(line, True), the_task.send, opts.print_all_ids):
                errs += 1
    if not args:
        if not opts.nostdin:
            # FIXME: process stdin
            pass
    else:
        if not _run(args, the_task.send, opts.print_id or opts.print_all_ids):
            errs += 1
    return errs
Exemple #5
0
def _proc_evt_result(cmd, args):
    """Return a result."""
    global result_opts
    cmd = cmd.lower()
    text_result = {'warning': 'warn', 'error': 'fail'}.get(cmd, cmd)
    evt_result = __TEXT_RESULT_TO_BEAH.get(text_result[:4])
    if not result_opts:
        result_opts = OptionParser(usage="%prog [OPTIONS] MESSAGE",
                                   description="Return a %prog result.")
        result_opts.disable_interspersed_args()
        result_opts.add_option("-H",
                               "--handle",
                               action="store",
                               dest="handle",
                               help="result handle",
                               type="string",
                               default="")
        result_opts.add_option("-s",
                               "--score",
                               action="store",
                               dest="score",
                               help="result score",
                               default="0.0",
                               type="float")
        result_opts.add_option("-f",
                               "--file",
                               action="append",
                               dest="files",
                               help="Attach a file.")
    result_opts.prog = text_result
    opts, args = result_opts.parse_args(args)
    statistics = {}
    if opts.score:
        statistics["score"] = opts.score
    s = AppendingSender()
    r = beahlib.get_task(s).result(evt_result,
                                   handle=opts.handle,
                                   message=" ".join(args),
                                   statistics=statistics)
    attach(r, opts.files)
    return s.get_events()
Exemple #6
0
def _main(args, default_sender='socket'):
    errs = 0
    main_opts = OptionParser(
        usage="%prog [OPTIONS] COMMAND [COMMAND-OPTIONS] [COMMAND-ARGS]",
        description="""Create events to be consumed by the harness.""")
    main_opts.disable_interspersed_args()
    #If there is no COMMAND specified, stdin is processed line by line.
    main_opts.add_option(
        "-c",
        "--command",
        action="append",
        dest="commands",
        help="Run COMMAND. This option could be specified multiple times.",
        metavar="COMMAND",
        nargs=1,
        type="string")
    main_opts.add_option("-x",
                         "--nostdin",
                         action="store_true",
                         dest="nostdin",
                         help="Do not process stdin if there is no COMMAND",
                         default=False)
    main_opts.add_option("--help-commands",
                         action="callback",
                         nargs=0,
                         callback=help_commands,
                         callback_kwargs={'help': True},
                         help="Print short help on available commands.")
    main_opts.add_option("--list-commands",
                         action="callback",
                         nargs=0,
                         callback=help_commands,
                         help="Print list of available commands.")
    main_opts.add_option("-i",
                         "--print-id",
                         action="store_true",
                         dest="print_id",
                         help="Print event id on stderr.")
    main_opts.add_option("-I",
                         "--print-all-ids",
                         action="store_true",
                         dest="print_all_ids",
                         help="Print all event ids on stderr.")
    main_opts.add_option("-S",
                         "--use-socket",
                         action="store_const",
                         const="socket",
                         dest="sender",
                         help="Use socket for communication with server.")
    main_opts.add_option("--use-stdout",
                         action="store_const",
                         const="stdout",
                         dest="sender",
                         help="""Use stdout for communication with server.
                NOTE: Don't use this unless you know what you are doing.""")
    opts, args = main_opts.parse_args(args)
    the_task = beahlib.get_task(
        make_sender(opts.sender or default_sender, opts))
    if opts.commands:
        for line in opts.commands:
            if not _run(shlex.split(line, True), the_task.send,
                        opts.print_all_ids):
                errs += 1
    if not args:
        if not opts.nostdin:
            # FIXME: process stdin
            pass
    else:
        if not _run(args, the_task.send, opts.print_id or opts.print_all_ids):
            errs += 1
    return errs