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


Python Gittle.get_commit_files方法代码示例

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


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

示例1: Wiki

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import get_commit_files [as 别名]

#.........这里部分代码省略.........
        return ret

    def rename_page(self, old_name, new_name, user=None):
        old_filename, new_filename = map(cname_to_filename, [old_name, new_name])
        if old_filename not in self.gittle.index:
            # old doesn't exist
            return None

        if new_filename in self.gittle.index:
            # file is being overwritten, but that is ok, it's git!
            pass

        os.rename(os.path.join(self.path, old_filename), os.path.join(self.path, new_filename))

        self.gittle.add(new_filename)
        self.gittle.rm(old_filename)

        self.gittle.commit(name=getattr(user, 'username', self.default_committer_name),
                           email=getattr(user, 'email', self.default_committer_email),
                           message="Moved %s to %s" % (old_name, new_name),
                           files=[old_filename, new_filename])

        cache.delete_many(old_filename, new_filename)

    def get_page(self, name, sha='HEAD'):
        cached = cache.get(name)
        if cached:
            return cached

        # commit = gittle.utils.git.commit_info(self.repo[sha])
        filename = cname_to_filename(name).encode('latin-1')
        sha = sha.encode('latin-1')

        try:
            data = self.gittle.get_commit_files(sha, paths=[filename]).get(filename)
            if not data:
                return None
            partials = {}
            if data.get('data'):
                meta = self.get_meta(data['data'])
                if meta and 'import' in meta:
                    for partial_name in meta['import']:
                        partials[partial_name] = self.get_page(partial_name)
            data['partials'] = partials
            data['info'] = self.get_history(name, limit=1)[0]
            return data

        except KeyError:
            # HEAD doesn't exist yet
            return None

    def get_meta(self, content):
        if not content.startswith("---"):
            return None
        meta_end = re.search("\n(\.{3}|\-{3})", content)
        if not meta_end:
            return None
        try:
            return yaml.safe_load(content[0:meta_end.start()])
        except Exception as e:
            return {'error': e.message}

    def compare(self, name, old_sha, new_sha):
        old = self.get_page(name, sha=old_sha)
        new = self.get_page(name, sha=new_sha)
        return ghdiff.diff(old['data'], new['data'])

    def get_index(self):
        rv = []
        index = self.repo.open_index()
        for name in index:
            rv.append(dict(name=filename_to_cname(name),
                           filename=name,
                           ctime=index[name].ctime[0],
                           mtime=index[name].mtime[0],
                           sha=index[name].sha,
                           size=index[name].size))

        return rv

    def get_history(self, name, limit=100):
        file_path = cname_to_filename(name)
        versions = []
        walker = self.repo.get_walker(paths=[file_path], max_entries=limit)
        for entry in walker:
            change_type = None
            for change in entry.changes():
                if change.old.path == file_path:
                    change_type = change.type
                elif change.new.path == file_path:
                    change_type = change.type
            author_name, author_email = entry.commit.author.split('<')
            versions.append(dict(
                author=author_name.strip(),
                time=entry.commit.author_time,
                message=entry.commit.message,
                sha=entry.commit.id,
                type=change_type))

        return versions
开发者ID:tobegit3hub,项目名称:realms-wiki,代码行数:104,代码来源:models.py

示例2: Wiki

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import get_commit_files [as 别名]

#.........这里部分代码省略.........
        filename = cname_to_filename(name)
        self.gittle.rm(filename)
        commit = self.gittle.commit(name=username,
                                    email=email,
                                    message=message,
                                    files=[str(filename)])
        cache.delete_many(name)
        return commit

    def get_page(self, name, sha='HEAD'):
        """Get page data, partials, commit info.

        :param name: Name of page.
        :param sha: Commit sha.
        :return: dict

        """
        cached = cache.get(name)
        if cached:
            return cached

        # commit = gittle.utils.git.commit_info(self.repo[sha])
        filename = cname_to_filename(name).encode('latin-1')
        sha = sha.encode('latin-1')

        namespace_path = os.path.join(self.path, os.path.splitext(filename)[0])
        namespace_cname = to_canonical(os.path.splitext(filename)[0])
        if not os.path.exists(os.path.join(self.path, filename)) and os.path.isdir(namespace_path):
            files = ["[%s](%s_%s)" % (x, namespace_cname, filename_to_cname(x)) for x in os.listdir(namespace_path)]
            print(files)
            return {'data': "# Namespace %s \n\n This is an automatically generated list of pages in this namespace.\n\n %s" % (os.path.splitext(filename)[0], '\n'.join(files))}

        try:
            data = self.gittle.get_commit_files(sha, paths=[filename]).get(filename)
            if not data:
                return None
            partials = {}
            if data.get('data'):
                meta = self.get_meta(data['data'])
                if meta and 'import' in meta:
                    for partial_name in meta['import']:
                        partials[partial_name] = self.get_page(partial_name)
            data['partials'] = partials
            data['info'] = self.get_history(name, limit=1)[0]

            return data

        except KeyError:
            # HEAD doesn't exist yet
            return None

    def get_meta(self, content):
        """Get metadata from page if any.

        :param content: Page content
        :return: dict

        """
        if not content.startswith("---"):
            return None

        meta_end = re.search("\n(\.{3}|\-{3})", content)

        if not meta_end:
            return None
开发者ID:goodotcom,项目名称:realms-wiki,代码行数:69,代码来源:models.py


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