Esempio n. 1
0
def main(argv, cfg):
    descr = 'show setup.json, dataset list, etc for jobs'
    parser = ArgumentParser(
        prog=argv.pop(0),
        description=descr,
        formatter_class=RawTextHelpFormatter,
    )
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-o',
                       '--output',
                       action='store_true',
                       help='show job output')
    group.add_argument('-O',
                       '--just-output',
                       action='store_true',
                       help='show only job output')
    group.add_argument('-P',
                       '--just-path',
                       action='store_true',
                       help='show only job path')
    parser.add_argument(
        'jobid',
        nargs='+',
        metavar='jobid/jobspec',
        help='jobid is just a jobid.\n' +
        'you can also use path, method or :urdlist:[entry].\n' +
        'path is to a jobdir (with setup.json in it).\n' +
        'method is the latest (current) job with that method (i.e\n' +
        'the latest finished job with current source code).\n' +
        ':urdlist:[entry] looks up jobs in urd. details are in the\n' +
        'urd help, except here entry defaults to -1 and you can\'t\n' +
        'list things (no .../ or .../since/x).\n' +
        'you can use spec~ or spec~N to go back N current jobs\n' +
        'with that method or spec^ or spec^N to follow .previous')
    args = parser.parse_intermixed_args(argv)
    res = 0
    for path in args.jobid:
        try:
            job = name2job(cfg, path)
            if args.just_output:
                out = job.output()
                if out:
                    print(out, end='' if out.endswith('\n') else '\n')
            elif args.just_path:
                print(job.path)
            else:
                show(cfg.url, job, args.output)
        except JobNotFound as e:
            print(e)
            res = 1
        except Exception as e:
            if isinstance(e, OSError) and e.errno == errno.EPIPE:
                raise
            print_exc(file=sys.stderr)
            print("Failed to show %r" % (path, ), file=sys.stderr)
            res = 1
    return res
Esempio n. 2
0
def main(argv, cfg):
    descr = 'show setup.json, dataset list, etc for jobs'
    parser = ArgumentParser(prog=argv.pop(0), description=descr)
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-o',
                       '--output',
                       action='store_true',
                       help='show job output')
    group.add_argument('-O',
                       '--just-output',
                       action='store_true',
                       help='show only job output')
    group.add_argument('-P',
                       '--just-path',
                       action='store_true',
                       help='show only job path')
    parser.add_argument(
        'jobid',
        nargs='+',
        metavar='jobid/path/method',
        help='method shows the latest (current) job with that method\n' +
        '(i.e. the latest finished job with current source code)\n' +
        'you can use spec~ or spec~N to go back N current jobs\n' +
        'with that method or spec^ or spec^N to follow .previous')
    args = parser.parse_intermixed_args(argv)
    res = 0
    for path in args.jobid:
        try:
            job = name2job(cfg, path)
            if args.just_output:
                out = job.output()
                if out:
                    print(out, end='' if out.endswith('\n') else '\n')
            elif args.just_path:
                print(job.path)
            else:
                show(cfg.url, job, args.output)
        except JobNotFound as e:
            print(e)
            res = 1
        except Exception as e:
            if isinstance(e, IOError) and e.errno == errno.EPIPE:
                raise
            print_exc()
            print("Failed to show %r" % (path, ))
            res = 1
    return res