Exemplo n.º 1
0
def main():
    cli = BundleCLI(CodaLabManager())
    try:
        cli.do_command(sys.argv[1:])
    except KeyboardInterrupt:
        print('Terminated by Ctrl-C')
        sys.exit(130)
Exemplo n.º 2
0
def main():
    cli = BundleCLI(CodaLabManager())
    try:
        cli.do_command(sys.argv[1:])
    except KeyboardInterrupt:
        print('Terminated by Ctrl-C')
        sys.exit(130)
Exemplo n.º 3
0
def run_cli():
    from codalab.lib.bundle_cli import BundleCLI
    cli = BundleCLI(manager)
    cli.do_command(sys.argv[1:])
def run_command(
    args,
    expected_exit_code=0,
    max_output_chars=1024,
    env=None,
    include_stderr=False,
    binary=False,
    force_subprocess=False,
    cwd=None,
):
    # We import the following imports here because codalab_service.py imports TestModule from
    # this file. If we kept the imports at the top, then anyone who ran codalab_service.py
    # would also have to install all the dependencies that BundleCLI and CodaLabManager use.
    from codalab.lib.bundle_cli import BundleCLI
    from codalab.lib.codalab_manager import CodaLabManager

    def sanitize(string, max_chars=256):
        # Sanitize and truncate output so it can be printed on the command line.
        # Don't print out binary.
        if isinstance(string, bytes):
            string = '<binary>'
        if len(string) > max_chars:
            string = string[:max_chars] + ' (...more...)'
        return string

    # If we don't care about the exit code, set `expected_exit_code` to None.
    print(">>", *map(str, args), sep=" ")
    sys.stdout.flush()

    try:
        kwargs = dict(env=env)
        if not binary:
            kwargs = dict(kwargs, encoding="utf-8")
        if include_stderr:
            kwargs = dict(kwargs, stderr=subprocess.STDOUT)
        if cwd:
            kwargs = dict(kwargs, cwd=cwd)
        if not force_subprocess:
            # In this case, run the Codalab CLI directly, which is much faster
            # than opening a new subprocess to do so.
            stderr = io.StringIO()  # Not used; we just don't want to redirect cli.stderr to stdout.
            stdout = FakeStdout()
            cli = BundleCLI(CodaLabManager(), stdout=stdout, stderr=stderr)
            try:
                cli.do_command(args[1:])
                exitcode = 0
            except SystemExit as e:
                exitcode = e.code
            output = stdout.getvalue()
        else:
            output = subprocess.check_output([a.encode() for a in args], **kwargs)
            exitcode = 0
    except subprocess.CalledProcessError as e:
        output = e.output
        exitcode = e.returncode
    except Exception:
        output = traceback.format_exc()
        exitcode = 'test-cli exception'

    if expected_exit_code is not None and exitcode != expected_exit_code:
        colorize = Colorizer.red
        extra = ' BAD'
    else:
        colorize = Colorizer.cyan
        extra = ''
    print(colorize(" (exit code %s, expected %s%s)" % (exitcode, expected_exit_code, extra)))
    sys.stdout.flush()
    print(sanitize(output, max_output_chars))
    sys.stdout.flush()
    assert expected_exit_code == exitcode, 'Exit codes don\'t match'
    return output.rstrip()
Exemplo n.º 5
0
                 'use more than 1 process to make the best use of multiple '
                 'CPUs.',
            type=int, default=1),
        Commands.Argument(
            '-t', '--threads',
            help='Number of threads to use. The server will be able to handle '
                 '(--processes) x (--threads) requests at the same time.',
            type=int, default=50),
        Commands.Argument(
            '-d', '--debug', help='Run the development server for debugging.',
            action='store_true')
    ),
)
def do_rest_server_command(bundle_cli, args):
    # Force initialization of the bundle store, so that the misc_temp directory is created
    bundle_cli.manager.bundle_store()
    if args.watch:
        run_server_with_watch()
    else:
        from codalab.server.rest_server import run_rest_server
        run_rest_server(bundle_cli.manager, args.debug, args.processes, args.threads)


if __name__ == '__main__':
    cli = BundleCLI(CodaLabManager())
    try:
        cli.do_command(sys.argv[1:])
    except KeyboardInterrupt:
        print 'Terminated by Ctrl-C'
        sys.exit(130)
Exemplo n.º 6
0

@Commands.command(
    'bundle-manager',
    help='Start the bundle manager that executes run and make bundles.',
    arguments=(Commands.Argument(
        '--sleep-time',
        help='Number of seconds to wait between successive actions.',
        type=int,
        default=0.5), ),
)
def do_bundle_manager_command(bundle_cli, args):
    bundle_cli._fail_if_headless(args)
    from codalab.worker.bundle_manager import BundleManager
    manager = BundleManager.create(bundle_cli.manager)

    # Register a signal handler to ensure safe shutdown.
    for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP]:
        signal.signal(sig, lambda signup, frame: manager.signal())

    manager.run(args.sleep_time)


if __name__ == '__main__':
    cli = BundleCLI(CodaLabManager())
    try:
        cli.do_command(sys.argv[1:])
    except KeyboardInterrupt:
        print 'Terminated by Ctrl-C'
        sys.exit(130)