Example #1
0
    def clone(self, depth=1):
        """Clone the self.remote_url into self.local_path

        Args:
          depth: --depth argument to git clone. If None, clone the whole history.
        """
        if os.path.exists(self.local_path) and os.listdir(self.local_path):
            raise IOError("Directory {0} already exists and is non-empty".
                          format(self.local_path))

        logger.info("Cloning {remote} into {local}".
                    format(remote=self.remote_url,
                           local=self.local_path))
        cmd = ["git", "clone"]
        if depth is not None:
            cmd.append("--depth={0}".format(depth))
        cmd.append(self.remote_url)
        cmd.append(self.local_path)
        subprocess.call(cmd,
                        env=dict(os.environ, GIT_LFS_SKIP_SMUDGE="1"))
        self._pulled = True

        if os.path.exists(os.path.join(self.local_path, ".gitattributes")):
            if not self.use_lfs:
                logger.info(".gitattributes detected in {}. Using git-lfs".format(self.local_path))
            self.use_lfs = True
            lfs_installed(raise_exception=True)
Example #2
0
    def _pull_component(self, component, which="model"):
        if not self._pulled and self.auto_update:
            self.pull_source()

        component_dir = self.local_source._get_component_dir(component, which)

        if self.use_lfs:
            # the only call to git-lfs -> pulling specific sub-files

            lfs_installed(raise_exception=True)
            # get a list of directories to source (relative to the local_path)
            softlink_dirs = list(
                list_softlink_dependencies(component_dir, self.local_path))
            # pull these softlinks
            for pull_dir in [
                    component,
                    relative_path(component_dir, self.local_path)
            ] + softlink_dirs:
                cmd = ["git-lfs", "pull", "-I {0}/**".format(pull_dir)]
                logger.info(" ".join(cmd))
                subprocess.call(cmd,
                                cwd=self.local_path,
                                env=dict(os.environ, GIT_LFS_SKIP_SMUDGE="1"))

        return self.local_source._pull_component(component, which)
Example #3
0
    def __init__(self, remote_url, local_path, auto_update=True, use_lfs=False, name=None):
        """Git Source
        """
        self.name = name
        self.remote_url = remote_url
        self.local_path = os.path.join(os.path.realpath(local_path), '')  # add trailing slash
        self.local_source = LocalSource(self.local_path, name=name)

        self.auto_update = auto_update
        self._pulled = False
        self.use_lfs = use_lfs
        if self.use_lfs:
            lfs_installed(raise_exception=False)
Example #4
0
    def pull_source(self):
        """Pull/update the source
        """
        if not os.path.exists(self.local_path) or not os.listdir(self.local_path):
            return self.clone()

        if not self.auto_update:
            logger.warning("Pulling source even though auto_update=False")

        logger.info("Update {0}".
                    format(self.local_path))
        subprocess.call(["git",
                         "pull"],
                        cwd=self.local_path,
                        env=dict(os.environ, GIT_LFS_SKIP_SMUDGE="1"))

        if os.path.exists(os.path.join(self.local_path, ".gitattributes")):
            if not self.use_lfs:
                logger.info(".gitattributes detected in {}. Using git-lfs".format(self.local_path))
            self.use_lfs = True
            lfs_installed(raise_exception=True)

        self._pulled = True