Exemplo n.º 1
0
def _Main(argv):
    result = 0

    opt = optparse.OptionParser(usage="repo wrapperinfo -- ...")
    opt.add_option("--repo-dir", dest="repodir", help="path to .repo/")
    opt.add_option("--wrapper-version",
                   dest="wrapper_version",
                   help="version of the wrapper script")
    opt.add_option("--wrapper-path",
                   dest="wrapper_path",
                   help="location of the wrapper script")
    _PruneOptions(argv, opt)
    opt, argv = opt.parse_args(argv)

    _CheckWrapperVersion(opt.wrapper_version, opt.wrapper_path)
    _CheckRepoDir(opt.repodir)

    Version.wrapper_version = opt.wrapper_version
    Version.wrapper_path = opt.wrapper_path

    repo = _Repo(opt.repodir)
    try:
        try:
            init_ssh()
            init_http()
            name, gopts, argv = repo._ParseArgs(argv)
            run = lambda: repo._Run(name, gopts, argv) or 0
            if gopts.trace_python:
                import trace
                tracer = trace.Trace(count=False,
                                     trace=True,
                                     timing=True,
                                     ignoredirs=set(sys.path[1:]))
                result = tracer.runfunc(run)
            else:
                result = run()
        finally:
            close_ssh()
    except KeyboardInterrupt:
        print('aborted by user', file=sys.stderr)
        result = 1
    except ManifestParseError as mpe:
        print('fatal: %s' % mpe, file=sys.stderr)
        result = 1
    except RepoChangedException as rce:
        # If repo changed, re-exec ourselves.
        #
        argv = list(sys.argv)
        argv.extend(rce.extra_args)
        try:
            os.execv(__file__, argv)
        except OSError as e:
            print('fatal: cannot restart repo after upgrade', file=sys.stderr)
            print('fatal: %s' % e, file=sys.stderr)
            result = 128

    TerminatePager()
    sys.exit(result)
Exemplo n.º 2
0
def _Main(argv):
    result = 0

    opt = optparse.OptionParser(usage="repo wrapperinfo -- ...")
    opt.add_option("--repo-dir", dest="repodir", help="path to .repo/")
    opt.add_option("--wrapper-version",
                   dest="wrapper_version",
                   help="version of the wrapper script")
    opt.add_option("--wrapper-path",
                   dest="wrapper_path",
                   help="location of the wrapper script")
    _PruneOptions(argv, opt)
    opt, argv = opt.parse_args(argv)

    _CheckWrapperVersion(opt.wrapper_version, opt.wrapper_path)
    _CheckRepoDir(opt.repodir)

    Version.wrapper_version = opt.wrapper_version
    Version.wrapper_path = opt.wrapper_path

    repo = _Repo(opt.repodir)
    try:
        try:
            init_ssh()
            init_http()
            result = repo._Run(argv) or 0
        finally:
            close_ssh()
    except KeyboardInterrupt:
        print('aborted by user', file=sys.stderr)
        result = 1
    except ManifestParseError as mpe:
        print('fatal: %s' % mpe, file=sys.stderr)
        result = 1
    except RepoChangedException as rce:
        # If repo changed, re-exec ourselves.
        #
        argv = list(sys.argv)
        argv.extend(rce.extra_args)
        try:
            os.execv(__file__, argv)
        except OSError as e:
            print('fatal: cannot restart repo after upgrade', file=sys.stderr)
            print('fatal: %s' % e, file=sys.stderr)
            result = 128

    TerminatePager()
    sys.exit(result)