当前位置: 首页>>代码示例>>Python>>正文


Python Repo.iter_commits方法代码示例

本文整理汇总了Python中git.repo.Repo.iter_commits方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.iter_commits方法的具体用法?Python Repo.iter_commits怎么用?Python Repo.iter_commits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.repo.Repo的用法示例。


在下文中一共展示了Repo.iter_commits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DLLearnerRepo

# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import iter_commits [as 别名]
class DLLearnerRepo(Iterator):
    """
    TODO:
        - add progress bar for repo download
        - find out automatically whether the repo is already cloned and in case
          it is, just run a pull (after having set the branch)
    """
    _commits_get_url = 'https://api.github.com/repos/AKSW/DL-Learner/commits' +\
                       '?per_page=10000&since=%s&sha=%s'
    _github_repo_url = 'https://github.com/AKSW/DL-Learner.git'

    def __init__(self, repo_dir_path, since=None, branch='develop',
                 already_cloned=False):

        # strip off trailing directory separator
        if repo_dir_path.endswith(os.path.sep):
            self.repo_dir_path = repo_dir_path[:-1]
        else:
            self.repo_dir_path = repo_dir_path

        if since is None:
            self.since = datetime.now() - timedelta(default_time_delta_in_days)
        else:
            self.since = since

        self.branch = branch
        self.commit_sha1s = None
        self.next_idx = None

        self._setup_repo(already_cloned)

    def __len__(self):
        if self.commit_sha1s is None:
            self._init_commit_sha1s()

        return len(self.commit_sha1s)

    def _setup_repo(self, already_cloned):
        if already_cloned:
            self._git_repo = Repo(self.repo_dir_path)
        else:
            _log.info('Cloning repo from %s into %s' % (
                self._github_repo_url, self.repo_dir_path))
            self._git_repo = Repo.clone_from(
                self._github_repo_url, self.repo_dir_path)
            _log.info('-Done-')

        if self.branch:
            self._git_repo.git.checkout(self.branch)
            # self._git_repo.active_branch = self.branch

    def __iter__(self):
        return self

    def __next__(self):
        if self.commit_sha1s is None:
            self._init_commit_sha1s()

        self.next_idx += 1
        if self.next_idx >= len(self.commit_sha1s):
            raise StopIteration

        return DLLearnerCommit(self.commit_sha1s[self.next_idx], self)

    def _init_commit_sha1s(self):
        commit_sha1s = []

        for c in self._git_repo.iter_commits():
            """Iters the commits backwards in time, i.e. the latest commit
            comes first and the oldest comes last
            """
            c_date = datetime.fromtimestamp(c.committed_date)

            if c_date < self.since:
                break

            commit_sha1s.append(c.hexsha)

        commit_sha1s.reverse()

        self.commit_sha1s = \
            [c for c in commit_sha1s if c not in commits_to_skip]
        self.next_idx = -1

    def get_checkout_cmd(self):
        return self._git_repo.git.checkout
开发者ID:patrickwestphal,项目名称:dl-learner-regression-stats,代码行数:88,代码来源:dllearnerrepo.py

示例2: GitSync

# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import iter_commits [as 别名]

#.........这里部分代码省略.........
                self.repo.git.reset('--hard', 'origin/master')

                if synced_head != self.repo.head.ref.commit:
                    yield self.sync()
                    synced_head = self.repo.head.ref.commit

            except:
                logging.exception("Failed to pull repository.")

            yield sleep(5)

    @coroutine
    def sync(self):
        logging.info("Syncing '%s'.", REPO_DIRECTORY)

        charts = yield Query(self.database, "Charts", manipulate=True).find()
        for chart in charts:
            path = chart["path"]
            self.charts[path] = chart

        discovered_charts = dict()
        for subdir, _, files in os.walk(REPO_DIRECTORY):
            for chart_file in files:
                if chart_file == "Chart.yaml":
                    try:
                        discovered_charts[subdir] = yield self.import_chart(subdir)
                    except Exception:
                        logging.exception("Failed to import chart at '%s'", subdir)

        for path, existing in self.charts.iteritems():
            discovered = discovered_charts.get(path, None)

            if discovered is None:
                logging.debug("Deleting chart %(name)s", existing)
                yield Query(self.database, 'Charts').remove(existing)
            else:
                discovered["_id"] = existing["_id"]
                discovered["metadata"] = existing["metadata"]

                if discovered["commit"] != existing["commit"]:
                    logging.debug("Updating existing chart %(name)s", discovered)
                    yield Query(self.database, "Charts", manipulate=True).update(discovered)

        for path, discovered in discovered_charts.iteritems():
            if discovered and "_id" not in discovered:
                logging.debug("Inserting new chart %(name)s", discovered)
                try:
                    yield Query(self.database, "Charts", manipulate=True).insert(discovered)
                except:
                    logging.error("Failed to insert chart %(name)s", discovered)

        self.charts = discovered_charts

    @coroutine
    def import_chart(self, directory):
        chart_path = os.path.join(directory, "Chart.yaml")

        with open(chart_path, "r") as stream:
            chart = load(stream)
            chart["path"] = directory

            commit = self.repo.iter_commits(paths=chart_path).next()
            chart["commit"] = binascii.hexlify(commit.binsha)
            chart["committed_date"] = commit.committed_date
            chart["resources"] = []

            manifests = yield self.import_manifests(directory)
            for _, manifest in manifests.iteritems():
                if commit.committed_date < manifest["commit"].committed_date:
                    chart["commit"] = binascii.hexlify(manifest["commit"].binsha)
                    chart["committed_date"] = manifest["commit"].committed_date

                for resource in manifest["resources"]:
                    chart["resources"].append(resource)

            raise Return(chart)

    @coroutine
    def import_manifests(self, directory):
        manifests = dict()

        manifests_path = os.path.join(directory, "manifests", "*.yaml")
        for manifest in glob.glob(manifests_path):
            with open(manifest, "r") as stream:
                manifests[manifest] = dict(
                    resources=[resource for resource in load_all(stream)],
                    commit=self.repo.iter_commits(paths=manifest).next()
                )

        manifests_path = os.path.join(directory, "templates", "*.yaml")
        for manifest in glob.glob(manifests_path):
            manifest_filename = ntpath.basename(manifest)
            rendered_manifest = check_output(["tide", "view", "-f", "templates/" + manifest_filename, directory])
            with io.TextIOWrapper(io.BytesIO(rendered_manifest)) as stream:
                manifests[manifest] = dict(
                    resources=[resource for resource in load_all(stream)],
                    commit=self.repo.iter_commits(paths=manifest).next()
                )

        raise Return(manifests)
开发者ID:harbur,项目名称:elastickube,代码行数:104,代码来源:repo.py


注:本文中的git.repo.Repo.iter_commits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。