Esempio n. 1
0
    def __enter__(self):
        log.debug("About to lock {}".format(self.lockfile))

        if not self._acquire(block=False):
            log.warning("Retrying lock acquisition on {}.".format(
                self.lockfile))
            self._acquire(block=True)

        log.debug("Received lock on {}".format(self.lockfile))
Esempio n. 2
0
 def __commit_exists(self):
     try:
         cmd(self.__bare_path(), [
             "git", "cat-file", "-e", "{}^{{commit}}".format(self.revision)
         ])
         return True
     except subprocess.CalledProcessError as e:
         log.debug(
             "Did not find commit {} and instead got output: {}".format(
                 self.revision, e.output))
         return False
Esempio n. 3
0
def cmd(cwd, command):
    log.debug("Running {} in {}".format(
        " ".join(command),
        cwd
        ))

    result = subprocess.run(command,
                            cwd=cwd,
                            stdout=subprocess.PIPE,
                            universal_newlines=True,
                            check=True)
    log.debug("command output: {}".format(result.stdout))
    return result
Esempio n. 4
0
    def make_archive(self):
        if not self.__exists():
            log.warning("Fetching tag '{}' from {}".format(
                self.tag, self.cache.repository))
            with self.cache.lock():
                bare_path = self.__bare_path()
                ref = "refs/tags/{}".format(self.tag)
                setup_bare(bare_path)

                try:
                    cmd(bare_path, [
                        "git", "fetch", "--depth=1", self.cache.repository, ref
                    ])
                except subprocess.CalledProcessError as e:
                    log.debug(
                        "Did not find tag {}, instead got output: {}".format(
                            self.tag, e.output))

                    raise NixError("tag-not-found",
                                   "Tag {} not found".format(self.tag))

                archive_ref(bare_path, "FETCH_HEAD", self.__archive_path())

        return self.__archive_path()
Esempio n. 5
0
def setup_bare(path):
    if not os.path.isdir(path):
        log.debug("About to init a bare repository at {}".format(path))
        cmd(None, ["git", "init", "--bare", path])
Esempio n. 6
0
 def __exit__(self, *args):
     log.debug("Releasing lock {}".format(self.lockfile))
     self._release()