Exemplo n.º 1
0
def repolist(format):
    cfg = RepoListConfig()
    for info in cfg.find_all():
        vars_ = dict(repoid=info.repoid,
                     localpath=info.localrepo.repo_path,
                     canonical=(info.canonicalrepo.repo_path
                                if info.canonicalrepo else ''))
        print(format % vars_)
Exemplo n.º 2
0
def update(identifiers, nopull, only):
    '''
    Performs a `git pull` in each of the repositories registered with
    `homely add`, runs all of their HOMELY.py scripts, and then performs
    automatic cleanup as necessary.

    REPO
        This should be the path to a local dotfiles repository that has already
        been registered using `homely add`. If you specify one or more `REPO`s
        then only the HOMELY.py scripts from those repositories will be run,
        and automatic cleanup will not be performed (automatic cleanup is only
        possible when homely has done an update of all repositories in one go).
        If you do not specify a REPO, all repositories' HOMELY.py scripts will
        be run.

    The --nopull and --only options are useful when you are working on your
    HOMELY.py script - the --nopull option stops you from wasting time checking
    the internet for the same updates on every run, and the --only option
    allows you to execute only the section you are working on.
    '''
    mkcfgdir()
    setallowpull(not nopull)

    cfg = RepoListConfig()
    if len(identifiers):
        updatedict = {}
        for identifier in identifiers:
            repo = cfg.find_by_any(identifier, "ilc")
            if repo is None:
                hint = "Try running %s add /path/to/this/repo first" % CMD
                raise Fatal("Unrecognised repo %s (%s)" % (identifier, hint))
            updatedict[repo.repoid] = repo
        updatelist = updatedict.values()
        cleanup = len(updatelist) == cfg.repo_count()
    else:
        updatelist = list(cfg.find_all())
        cleanup = True
    success = run_update(updatelist,
                         pullfirst=not nopull,
                         only=only,
                         cancleanup=cleanup)
    if not success:
        sys.exit(1)
Exemplo n.º 3
0
def autoupdate(**kwargs):
    options = ('pause', 'unpause', 'outfile', 'daemon', 'clear')
    action = None
    for name in options:
        if kwargs[name]:
            if action is not None:
                raise UsageError("--%s and --%s options cannot be combined" %
                                 (action, name))
            action = name

    if action is None:
        raise UsageError("Either %s must be used" %
                         (" or ".join("--{}".format(o) for o in options)))

    mkcfgdir()
    if action == "pause":
        with open(PAUSEFILE, 'w'):
            pass
        return

    if action == "unpause":
        if os.path.exists(PAUSEFILE):
            os.unlink(PAUSEFILE)
        return

    if action == "clear":
        if os.path.exists(FAILFILE):
            os.unlink(FAILFILE)
        return

    if action == "outfile":
        print(OUTFILE)
        return

    # is an update necessary?
    assert action == "daemon"

    # check if we're allowed to start an update
    status, mtime, _ = getstatus()
    if status == UpdateStatus.FAILED:
        print("Can't start daemon - previous update failed")
        sys.exit(1)
    if status == UpdateStatus.PAUSED:
        print("Can't start daemon - updates are paused")
        sys.exit(1)
    if status == UpdateStatus.RUNNING:
        print("Can't start daemon - an update is already running")
        sys.exit(1)

    # abort the update if it hasn't been long enough
    interval = 20 * 60 * 60
    if mtime is not None and (time.time() - mtime) < interval:
        print("Can't start daemon - too soon to start another update")
        sys.exit(1)

    assert status in (UpdateStatus.OK, UpdateStatus.NEVER, UpdateStatus.NOCONN)

    oldcwd = os.getcwd()
    import daemon
    with daemon.DaemonContext(), open(OUTFILE, 'w') as f:
        try:
            from homely._ui import setstreams
            setstreams(f, f)

            # we need to chdir back to the old working directory or  imports
            # will be broken!
            if sys.version_info[0] < 3:
                os.chdir(oldcwd)

            cfg = RepoListConfig()
            run_update(list(cfg.find_all()), pullfirst=True, cancleanup=True)
        except Exception:
            import traceback
            f.write(traceback.format_exc())
            raise