Ejemplo n.º 1
0
def main_daemon(argv):
    parser = argparse.ArgumentParser(prog='minion-daemon')
    parser.add_argument('--workdir', default=os.environ.get('MINION_WORKDIR', '.'),
                        help='minion working directory')
    args = parser.parse_args(argv)
    try:
        d = MinionDaemon(args.workdir)
        d.run()
    except KeyboardInterrupt:
        sys.exit(0)
    except MinionException as e:
        print(e)
        sys.exit(1)
Ejemplo n.º 2
0
def main_tool(argv):
    sock_default = os.environ.get('MINION_SOCKET', './minion.sock')
    parser = argparse.ArgumentParser(prog='minion')
    parser.add_argument('--socket', type=str, default=sock_default,
                        help='socket to talk to minion daemon (default: %s)' % sock_default)
    subparsers = parser.add_subparsers(help='command-line tools')
    minion.cmd.update_heads(subparsers.add_parser('update-heads', help='fetch the latest sources'))
    minion.cmd.new_target(subparsers.add_parser('new-target', help='create a new build target'))
    minion.cmd.del_target(subparsers.add_parser('del-target', help='remove an existing build target'))
    minion.cmd.sync_target(subparsers.add_parser('sync-target', help="synchronize a target's sources with the heads"))
    minion.cmd.set_target_refspec(subparsers.add_parser('set-target-refspec', help='manually set the HEAD for a target/source pair'))
    minion.cmd.run_build_process(subparsers.add_parser('run-build-process', help='run the build process for a target (async)'))
    minion.cmd.build_status(subparsers.add_parser('build-status', help='check the status of a build'))
    minion.cmd.forget_build_failure(subparsers.add_parser('forget-build-failure', help='remove a cached process result for a given build target'))
    minion.cmd.add_blob(subparsers.add_parser('add-blob', help='manually add a blob'))

    # run it
    if not argv:
        parser.print_help()
    else:
        args = parser.parse_args(argv)
        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_PASSCRED, 1)
        s.connect(args.socket)
        cmd = ' '.join([shlex.quote(arg) for arg in argv]) + '\n'
        s.sendall(cmd.encode('utf8'))
        s.shutdown(socket.SHUT_WR)
        data = b''
        while True:
            x = s.recv(512)
            if not x:
                break
            data += x
        output = json.loads(data.decode('utf8'))
        if 'output' in output:
            stdout = output['output']
            stdout = stdout.strip()
            stdout += '\n'
            sys.stdout.write(stdout)
        if output['status'] == 'success':
            sys.exit(0)
        else:
            sys.exit(1)