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


Python Repo.tree方法代码示例

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


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

示例1: checkout

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
def checkout(file_path, commit=None):
    """
    Context manager to checkout a Git commit and restore the original state.

    If not commit is supplied, the file will be taken from the current
    working directory.

    :raises: :py:class:`NoSuchFeature` if the specified file does not exist
             at the requested point in time (either a Git commit or in the
             current filesystem state)
    """
    repo = Repo(os.getcwd())

    if commit:
        log.debug('checking out {} @ {}'.format(file_path, commit))
        tree = repo.tree(commit)
        try:
            blob = tree / file_path
            yield blob.data_stream
        except KeyError:
            raise NoSuchFeature
    else:
        log.debug('opening {} as a regular file'.format(file_path))
        try:
            with open(file_path, 'r') as file_content:
                yield file_content
        except IOError:
            raise NoSuchFeature
开发者ID:freshbooks,项目名称:gherkin-diff,代码行数:30,代码来源:gherkin-diff.py

示例2: get_repo_info

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
def get_repo_info(repo_name=''):
    res = []
    path = current_app.config.get('REPO_ROOT', '')

    try:
       repo = Repo(os.path.join(path, repo_name))
       res = repo.tree()
    except (InvalidGitRepositoryError, NoSuchPathError) as e:
            print(e)
    return res
开发者ID:Gloreus,项目名称:projectors,代码行数:12,代码来源:data.py

示例3: fetch

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
    def fetch(self, key, rev):
        """
        fetch revision ``rev`` of entity identified by ``key``.

        """
        repo = Repo(self.repo_path)
        try:
            tree = repo.tree(rev)
            for bit in key.split('/'):
                tree = tree/bit
            return tree.data
        except:
            return ''
开发者ID:jezdez-archive,项目名称:django-rcsfield,代码行数:15,代码来源:gitcore.py

示例4: _delta_dir

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
def _delta_dir():
    """returns the relative path of the current directory to the git
    repository.
    This path will be added the 'filename' path to find the file.
    It current_dir is the git root, this function returns an empty string.

    Keyword Arguments:
        <none>

    Returns:
        str -- relative path of the current dir to git root dir
               empty string if current dir is the git root dir
    """
    repo = Repo()
    current_dir = os.getcwd()
    repo_dir = repo.tree().abspath
    delta_dir = current_dir.replace(repo_dir, '')
    if delta_dir:
        return delta_dir + '/'
    else:
        return ''
开发者ID:ThomasChiroux,项目名称:attowiki,代码行数:23,代码来源:git_tools.py

示例5: format

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
        for tag in repo.tags:
            tags[tag.commit] = tag.tag
        for commit in commits:
            cur_ver.parse_message(commit.message)
            if commit in tags:
                # Tag changeset with release date and version and create new current changeset
                version = tags[commit].tag
                release_date = datetime.datetime.fromtimestamp(tags[commit].tagged_date).strftime('%Y-%m-%d')
                cur_ver.version_header = '## {0} ({1})\n'.format(version, release_date)
                cur_ver.post_header.insert(0, '[all commits](https://github.com/Flexget/Flexget/compare/{0}...{1})\n'.
                                           format(oldestref, commit.hexsha))
                released_vers.insert(0, cur_ver)
                cur_ver = MDChangeSet()
                oldestref = commit.hexsha
            if cur_ver.sections and not cur_ver.version_header:
                verfile = repo.tree('HEAD')['flexget/_version.py'].data_stream.read()
                __version__ = None
                try:
                    exec(verfile)
                except Exception:
                    pass
                cur_ver.version_header = '## {0} (unreleased)\n'.format(__version__)

        with io.open(filename, 'w', encoding='utf-8') as logfile:
            logfile.writelines(pre_lines)
            logfile.write('<!---{0}--->\n'.format(commit.hexsha))
            logfile.writelines(cur_ver.to_md_lines())
            logfile.write('<!---{0}--->\n'.format(oldestref))
            for ver in released_vers:
                logfile.writelines(ver.to_md_lines())
            logfile.writelines(post_lines)
开发者ID:Lukeid,项目名称:Flexget,代码行数:33,代码来源:update-changelog.py

示例6: Repo

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
REPO = '/path/to/repo.git'
CONFIG_FILE = 'settings.conf'

# DEFAULT CONFIG
# ==============
# These are the basic defaults when no settings file is provided in the repo.

DEFAULT_CONFIG = {
    'template': 'template.html',
    'output_format': 'html4',
    'source_extension': 'txt',
    'branch': 'master'
}

repo = Repo(REPO)
tree = repo.tree()


def get_config():
    """ Return config settings. """
    blob = tree/CONFIG_FILE
    config = ConfigParser.SafeConfigParser(DEFAULT_CONFIG)
    if blob:
        config.readfp(StringIO.StringIO(blob.data))
    print "No settings file. Using defaults."
    return config

CONFIG = get_config()

def get_files(refs):
    """ Return a list of changed file names given a list of git refs. """
开发者ID:myprtfl,项目名称:MGPages,代码行数:33,代码来源:mgpages.py

示例7: Project

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
class Project(object):
    def __init__(self, config, projectId):
        self.__repoPath = os.path.join(config.GIT_REPO_DIRECTORY, projectId)
        self.repo = Repo(self.__repoPath )
        self.projectId = projectId
 
    def getFields(self):
        projectInfoBlob = self.__getProjectInfoBlob()
        if projectInfoBlob == None:
            raise Exception("No projectinfo file in repo")
    
        #jsonString = binascii.b2a_qp(projectInfoBlob.data_stream.read())
        jsonString = projectInfoBlob.data_stream.read().decode('utf-8')

        obj = json.loads(jsonString)
        return {"lastAccess": self.repo.head.commit.committed_date,
                "projectName": obj["projectName"],
                "projectId": self.projectId}
                       
    def __getProjectInfoBlob(self):
        for blob in self.repo.tree().blobs:
            if blob.name == ".projectinfo.json":
                return blob
                
        return None
                
    def getFiles(self):
        pass
        
    def getNotes(self):
        try:
            notes = []
            noteTree = self.repo.tree().join("notes")
            for blob in noteTree.blobs:
                notes.append(Note(blob))
            
            return notes
        except KeyError:
            return []
            
        
    def putFile(self, path, contents, binary=True):
        localRepo = self.checkout()
        fullPath = os.path.join(localRepo.working_dir, path)
        fullFolder = os.path.dirname(fullPath)
        
        if not os.path.exists(fullFolder):
            os.makedirs(fullFolder)
        
        if binary:
            with open(fullPath, "w") as outfile:
                outfile.write(contents)
        else:
            with codecs.open(fullPath, "w", "utf-8") as outfile:
                outfile.write(contents)
            
        localRepo.index.add([fullPath])
        localRepo.index.commit("Updated " + os.path.basename(path))
        
        self.checkin(localRepo)
        
    def putNote(self, path, contents):
        self.putFile(os.path.join("notes", path), contents, False)
 
    def checkout(self):
        tmpPath = tempfile.mkdtemp()
        return self.repo.clone(tmpPath)

    def checkin(self, cloned_repo):
        #cloned_repo.remotes.origin.pull()
        cloned_repo.remotes.origin.push()
        
        
    

            
        

        
        
开发者ID:nojan1,项目名称:project-portal,代码行数:73,代码来源:project.py

示例8: GitRepository

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
class GitRepository(Repository):
    class GitSubmodule(object):
        def __init__(self, configuration):
            """
                @param configuration a list of strings, that correspond
                                        to the configuration block for this
                                        submodule
            """

            import re
            modulere = re.compile('\[submodule\s*"(.*?)"\]')
            pathre = re.compile("\s*path\s*=\s*(.*)")
            urlre = re.compile("\s*url\s*=\s*(.*)")

            name = [
                        match[0]
                        for match in [modulere.findall(line) for line in configuration]
                        if len(match) == 1
                    ]
            path = [
                        match[0]
                        for match in [pathre.findall(line) for line in configuration]
                        if len(match) == 1
                    ]
            url = [
                        match[0]
                        for match in [urlre.findall(line) for line in configuration]
                        if len(match) == 1
                    ]

            if len(name) == 0 or len(path) == 0 or len(url) == 0:
                raise RepositoryError("Corrupt submodule")

            self.name = name[0]
            path = path[0].rsplit("/", 1)
            if len(path) == 1:
                self.path_base = ""
                self.path_name = path[0]
            else:
                self.path_base = path[0]
                self.path_name = path[1]
            self.url = url[0]

    class GitBranch:
        """emulating Repository.Branch fields"""
        def __init__(self, branch):
            self.branch = branch
            self.name = branch.name
            self.commit = GitRepository.GitCommit(branch.commit)

    class GitTree:
        """emulating Repository.Tree fields"""
        def __init__(self, tree):
            # emulate id field (has been renamed)
            self.id = tree.hexsha

            # one-to-one copy of fields
            self.name = tree.name

            # additional fields
            self._values = None
            self.is_tree = True
            self.tree = tree

        @property
        def values(self):
            if self._values is None:
                trees = [GitRepository.GitTree(tree) for tree in self.tree.trees]
                blobs = [GitRepository.GitBlob(blob) for blob in self.tree.blobs]
                self._values = trees + blobs
            return self._values

    class GitBlob:
        """emulating Repository.Blob fields"""
        def __init__(self, blob):
            # emulate id field (has been renamed)
            self.id = blob.hexsha

            # one-to-one copy of fields
            self.name = blob.name
            self.size = blob.size
            self.mode = blob.mode
            self.mime_type = blob.mime_type

            # additional fields
            self._data = None
            self.is_tree = False
            self.blob = blob

        @property
        def data(self):
            # only load data once
            if self._data is None:
                self._data = self.blob.data_stream.read()
            return self._data

    class GitCommit:
        """emulating Repository.Commit fields"""
        def __init__(self, commit):
            # id has been renamed
#.........这里部分代码省略.........
开发者ID:mensi,项目名称:pyggi,代码行数:103,代码来源:gitr.py

示例9: PyGitRepo

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import tree [as 别名]
class PyGitRepo(object):
    def __init__(self, repo_path):
        self.repo_obj = Repo(repo_path)
        self.branches = [PyGitHead(branch) for branch in self.repo_obj.branches] 
        
        try:
            self.owner = open(join(repo_path, 'owner')).read().strip()
        except IOError:
            self.owner = ""

    @property
    def last_change(self):
        return self.latest_commits(1)[0]

    def latest_commits(self, count=10):
        try:
            # Get the lastest COUNT commits
            commits = self.repo_obj.git.rev_list(
                    all=True, max_count=count, date_order=True).split('\n')
        except Exception as exc:
            # If we fail, log it and return an empty list
            log.exception(exc)
            return []
        
        # Create commits
        return [self.commit(commit) for commit in commits]
        return [PyGitCommit(Commit(self.repo_obj, commit)) for commit in commits]

    def latest_tags(self, count=10):
        try:
            # Get the latest COUNT tags
            tags = self.repo_obj.git.rev_list(tags=True, max_count=count,
                            no_walk=True, date_order=True).split('\n')
        except Exception as exc:
            log.exception(exc)
            return []
        
        return [PyGitTag(self.repo_obj, Tag(self.repo_obj.git.describe(tag), tag)) for tag in tags]

    def commit(self, id):
        # Get the commit object
        commit_obj = self.repo_obj.commit(id)
        
        # Generate the tags
        tags = {}
        for tag in self.repo_obj.tags:
            if tag.commit.id == id:
                tags[tag.commit.id] = PyGitTag(self.repo_obj, tag)
        
        # Generate the heads
        heads = [head for head in self.repo_obj.heads if head.commit.id == id]
        
        # Return a generated commit
        return PyGitCommit(commit_obj, tags=tags, heads=heads)

    def tree(self, id):
        # Get the tree object
        tree_obj = self.repo_obj.tree(id)
        return PyGitTree(tree_obj)

    def blob(self, id):
        # Get the blob object
        blob_obj = Blob(self.repo_obj, id)
        return PyGitBlob(blob_obj)
    
    def archive_tar_gz(self, id):
        return "application/x-compressed", self.repo_obj.archive_tar_gz(id)
    def archive_tar_bz2(self, id):
        from bz2 import compress
        return "application/bzip2", compress(self.repo_obj.archive_tar(id))
    def archive_zip(self, id):
        return "application/zip", self.repo_obj.git.archive(id, format="zip")
    
    @property
    def description(self):
        return self.repo_obj.description

    def __repr__(self):
        return "<PyGitRepo path='%s'>" % self.repo_obj.path
开发者ID:amcfague,项目名称:pygitweb,代码行数:81,代码来源:repo.py


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