Example #1
0
File: Caf.py Project: azag0/caf
def append(caf, targets: 'TARGET', queue: 'URL', maxdepth: ('--maxdepth', int)):
    """
    Append the list of prepared tasks to a given queue.

    Usage:
        caf append URL [TARGET...] [--maxdepth N]

    Options:
        --maxdepth N             Maximum depth.
    """
    from urllib.request import urlopen
    url = caf.get_queue_url(queue, 'append') or queue
    roots = [caf.out/t for t in targets] \
        if targets else (caf.out).glob('*')
    tasks = OrderedDict()
    for path in find_tasks(*roots, unsealed=True, maxdepth=maxdepth):
        cellarid = get_stored(path)
        if cellarid not in tasks:
            tasks[cellarid] = path
    if not tasks:
        error('No tasks to submit')
    data = '\n'.join('{} {}'.format(label, h)
                     for h, label in reversed(tasks.items())).encode()
    with urlopen(url, data=data) as r:
        queue_url = r.read().decode()
        print('./caf work --queue {}'.format(queue_url))
    with open('.caf/LAST_QUEUE', 'w') as f:
        f.write(queue_url)
Example #2
0
File: Caf.py Project: azag0/caf
def work(caf, profile: '--profile', n: ('-j', int), targets: 'TARGET',
         limit: ('--limit', int), queue: '--queue', myid: '--id',
         dry: '--dry', do_init: 'init', do_build: 'build', verbose: '--verbose',
         last_queue: '--last', maxdepth: ('--maxdepth', int)):
    """
    Execute all prepared build tasks.

    Usage:
        caf [[init] build] work [-v] [--limit N]
                                [--profile PROFILE [-j N] | [--id ID] [--dry]]
                                [--last | --queue URL | [TARGET...] [--maxdepth N]]

    Options:
        -n, --dry                  Dry run (do not write to disk).
        --id ID                    ID of worker [default: 1].
        -p, --profile PROFILE      Run worker via ~/.config/caf/worker_PROFILE.
        -q, --queue URL            Take tasks from web queue.
        --last                     As above, but use the last submitted queue.
        -j N                       Number of launched workers [default: 1].
        -l, --limit N              Limit number of tasks to N.
        -v, --verbose              Be more verbose.
        --maxdepth N               Maximal depth.
    """
    import subprocess
    if do_init:
        build(['caf', 'init', 'build'], caf)
    elif do_build:
        build(['caf', 'build'], caf)
    if profile:
        for _ in range(n):
            cmd = ['{}/.config/caf/worker_{}'.format(os.environ['HOME'], profile),
                   '-v' if verbose else None, ('--limit', limit),
                   ('--queue', queue), targets, ('--maxdepth', maxdepth)]
            try:
                subprocess.check_call(filter_cmd(cmd))
            except subprocess.CalledProcessError:
                error('Running ~/.config/caf/worker_{} did not succeed.'
                      .format(profile))
    else:
        if queue or last_queue:
            if last_queue:
                with open('.caf/LAST_QUEUE') as f:
                    queue = f.read().strip()
            url = caf.get_queue_url(queue, 'get') or queue
            worker = QueueWorker(myid, caf.cache, url,
                                 dry=dry, limit=limit, debug=verbose)
        else:
            roots = [caf.out/t for t in targets] \
                if targets else (caf.out).glob('*')
            tasks = OrderedDict()
            for path in find_tasks(*roots, unsealed=True, maxdepth=maxdepth):
                cellarid = get_stored(path)
                if cellarid not in tasks:
                    tasks[cellarid] = str(path)
            worker = LocalWorker(myid, caf.cache,
                                 list(reversed(tasks.items())),
                                 dry=dry, limit=limit, debug=verbose)
        worker.work()
Example #3
0
File: Caf.py Project: azag0/caf
def list_tasks(caf, _, do_finished: '--finished', do_stored: '--stored',
               do_error: '--error', do_unfinished: '--unfinished',
               in_cellar: '--cellar', both_paths: '--both',
               maxdepth: ('--maxdepth', int), targets: 'TARGET'):
    """
    List tasks.

    Usage:
        caf list tasks [TARGET...] [--finished | --stored | --error | --unfinished]
                       [--cellar | --both] [--maxdepth N]

    Options:
        --finished                 List finished tasks.
        --unfinished               List unfinished tasks.
        --stored                   List stored tasks.
        --error                    List tasks in error.
        --cellar                   Print path in cellar.
        --both                     Print path in build and cellar.
        --maxdepth N               Specify maximum depth.
    """
    roots = [caf.out/t for t in targets] if targets else (caf.out).glob('*')
    if do_finished:
        paths = find_tasks(*roots, sealed=True, maxdepth=maxdepth)
    elif do_unfinished:
        paths = find_tasks(*roots, unsealed=True, maxdepth=maxdepth)
    elif do_stored:
        paths = find_tasks(*roots, stored=True, maxdepth=maxdepth)
    elif do_error:
        paths = find_tasks(*roots, error=True, maxdepth=maxdepth)
    else:
        paths = find_tasks(*roots, maxdepth=maxdepth)
    if in_cellar:
        for path in paths:
            print(get_stored(path, require=False))
    elif both_paths:
        for path in paths:
            print(path, get_stored(path, require=False))
    else:
        for path in paths:
            print(path)
Example #4
0
File: Caf.py Project: azag0/caf
def reset(caf, targets: 'TARGET'):
    """
    Remove working lock and error on tasks.

    Usage:
        caf reset [TARGET...]
    """
    roots = [caf.out/t for t in targets] if targets else (caf.out).glob('*')
    for path in find_tasks(*roots):
        if (path/'.lock').is_dir():
            (path/'.lock').rmdir()
        if (path/'.caf/error').is_file():
            (path/'.caf/error').unlink()