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


Python Gittle.diff方法代码示例

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


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

示例1: handle

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import diff [as 别名]
    def handle(self, *args, **options):
        projects = Project.objects.all()

        for project in projects:
            print('Checking {0} for new commits'.format(project))
            if project.git_url:
                repo_path = '/tmp/' + project.slug
                try:
                    repo = Gittle(repo_path, project.git_url)
                    repo.pull()
                except:
                    try:
                        repo = Gittle.clone(project.git_url, repo_path)
                    except:
                        # put some logging here
                        repo = None
                if repo:
                    new_commits = []
                    for commit in repo.commit_info():
                        try:
                            prev_commit = repo.get_previous_commit(commit['sha'])
                            time = (datetime.fromtimestamp(commit['time']) + timedelta(hours=commit['timezone']/(60*60))).replace(tzinfo=pytz.utc)
                            try:
                                user_author = get_user_model().objects.get(email=commit['author']['email'])
                                string_author = None
                            except:
                                string_author = commit['author']['name']
                                user_author = None

                            summary = commit['message'].split('\n')[0][:45]
                            pcommit = ProjectCommit.objects.create(
                                project=project,
                                chash=commit['sha'],
                                message=commit['message'],
                                summary=summary,
                                user_author=user_author,
                                string_author=string_author,
                                created=time,
                                time=time,
                                diff=repo.diff(commit['sha'], prev_commit).next()['diff']
                            )
                            print(pcommit, ' added.')
                            new_commits.append(pcommit)
                        except:
                            pass
开发者ID:Code4Maine,项目名称:beehve,代码行数:47,代码来源:update_project_repos.py

示例2: __init__

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import diff [as 别名]
class GitStat:  
    '''
        print "        This class is for parsed git repository.\n\
        Returns parsed dictionary filled by name of users/commiters which add/modify files.\n\
        Every item has own directory which contains some counters: \
            counter for adding files\n\
            counter for deleting files\n\
            counter for files which has been modify\n\
        Next:\n    \
            all git commits in array\n\
            directory which lines in which files was modify and how many times who\n"
            '''
    def __init__(self,git_path,rskey= None,logger=dg):
        self.User = {}
        self.Commits = {}
        self.__logger = logger
        self.__tmp_repository = "/tmp/temporary_git_repository"
        if(os.path.exists(self.__tmp_repository)):
            self.__tmp_repository = self.__tmp_repository+"_"+datetime.datetime.now().isoformat()
    
        print git_path
        try:
            Gittle.clone(git_path,self.__tmp_repository)
        except:
            pass
            #self.__logger("Error could not clone repository.")
            #return
        self.__repository = Gittle(self.__tmp_repository)
        if rskey != None:
            key_file = open(rskey)
            self.__repository.auth(pkey=key_file)        
        #print self.__tmp_repository
        self.fill_User()
    def parse(self,name,commit,time):
        #print "asd",name, commit
        file_pattern = re.compile("diff --git a/(.*) b/(.*)")
        line_pattern = re.compile("@@ (.*) (.*) @@")
        regex = file_pattern.search(commit)
        file1,file2 = regex.group(1),regex.group(2)
        regex = line_pattern.search(commit)
        line1,line2 = regex.group(1),regex.group(2)
        #self.__logger("Files : ",file1,file2,line1,line2)
       # print self.User[name].has_key(file1)
        if self.User[name].has_key(file1):            
            #self.User[name][file1]['line_str'].append(line1+" "+line2)
            if self.User[name][file1].has_key(line1):
                self.User[name][file1][line1]["counter"] += 1 
                self.User[name][file1][line1]['time'].append(time)  
            else: 
                self.User[name][file1][line1] = {}
                self.User[name][file1][line1]["counter"] = 1
                self.User[name][file1][line1]['time'] = []            
                self.User[name][file1][line1]['time'].append(time)                  
            self.User[name][file1]['modify'] += 1
            self.User[name][file1]['time'].append(time)            
            if os.path.isfile(self.__tmp_repository+'/'+file1):
                self.User[name][file1]['exist'] = True            
            else:
                self.User[name][file1]['exist'] = False 
            self.Commits[name][file1]['array_commits'].append(commit)  
            self.Commits[name][file1]['time'].append(time)                 
        else:
            self.User[name][file1] = {}            
            self.User[name][file1][line1] = {}
            self.User[name][file1][line1]["counter"] = 1
            self.User[name][file1][line1]['time'] = []            
            self.User[name][file1][line1]['time'].append(time)              
            self.User[name][file1]['modify'] = 1
            self.User[name][file1]['time'] = []            
            self.User[name][file1]['time'].append(time)              
            if os.path.isfile(self.__tmp_repository+'/'+file1):
                self.User[name][file1]['exist'] = True            
            else:
                self.User[name][file1]['exist'] = False  
            self.Commits[name][file1] = {}   
            self.Commits[name][file1]['array_commits'] = []
            self.Commits[name][file1]['array_commits'].append(commit)     
            self.Commits[name][file1]['time'] = []            
            self.Commits[name][file1]['time'].append(time)                  
        return file1
    def fill_User(self):
        for commit in self.__repository.commit_info():
            sha = [commit['sha']]
            #print commit
            try:
                if not self.User.has_key(commit['committer']['name']):
                    #print commit#['committer']['name']
                    #print self.__repository.diff(*sha)[0]['diff']
                    self.User[commit['committer']['name']] = {}
                    self.Commits[commit['committer']['name']] = {}
                    self.parse(commit['committer']['name'],self.__repository.diff(*sha)[0]['diff'],commit['time'])                    
                else:
                    self.parse(commit['committer']['name'],self.__repository.diff(*sha)[0]['diff'],commit['time'])                    
                    
            except:
                pass

        #return file1                       
         
    def return_User(self):
#.........这里部分代码省略.........
开发者ID:kejbaly2,项目名称:SWMetric,代码行数:103,代码来源:GitStat.py

示例3: GitData

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import diff [as 别名]
    class GitData(object):
        """
        This class is for getting contribution, users and other data from
        Git repository.
        """
        def __init__(self, uri, branch="master", project_name="project",
                         specific_sha=None, threshold=False, correction=False):
            self._data_frame = None
            self.files = {}
            self.project_name = project_name
            self.git_repository = uri
            git_url = re.compile(GIT_URL)
            _uri_safe = ''.join([c for c in uri if c.isalnum()])
            self.repo_path = os.path.join(TMP_DIR, _uri_safe)
            self.__tmp_repository = self.repo_path
            self.index_sha = 0
            self.size = 0
            self.__first = True
            self.__spec_file = []
            self.specific_sha = specific_sha
            if os.path.exists(self.repo_path):
                #dont use cached repo
                shutil.rmtree(self.repo_path)
            if os.path.exists("diff_{0}.txt".format(self.project_name)):
                os.remove("diff_{0}.txt".format(self.project_name))
            is_url = git_url.search(uri)
            if is_url is None:
                self.__repository = Gittle(self.git_repository)
                self.__tmp_repository = self.git_repository
            else:
                if self.git_repository.find(".git") < 0:
                    LOGGER.info(r"Must end .git i will add manualy")
                    self.git_repository += ".git"
                try:
                    LOGGER.info(r'Cloning git repo: {0}'.format(self.repo_path))
                    Gittle.clone(self.git_repository, self.__tmp_repository)
                except InvalidRemoteUrl as err:
                    raise Exception(r"Could not clone repository! Is not url."
                        " Error: {0}".format(err))
                except ValueError as err:
                    raise Exception(r"Is not url."
                        " Error: {0}".format(err))
                except KeyError as err:
                    raise Exception(r"Could not clone repository."
                        " Error: {0}".format(err))
                except RefFormatError:
                    n_path = "/tmp/{0}".format(_uri_safe)
                    if os.path.exists(n_path):
                        #dont use cached repo
                        shutil.rmtree(n_path)
                    if branch is None:
                        os.system("git clone {0} {1} 2>&1".format(uri, n_path))
                    else:
                        os.system("git clone -b {0} {1} {2} 2>&1"
                                        .format(branch, uri, n_path))
                    self.__tmp_repository = n_path
                self.__repository = Gittle(self.__tmp_repository, origin_uri=uri)
                self.__repository.DEFAULT_BRANCH = branch
            if branch not in self.__repository.branches:
                LOGGER.error("Branch {0} is no in {1}".format(branch, uri))
                raise Exception("Branch {0} is no in {1}".format(branch, uri))
            self.__fill_data(branch, specific_sha)
            self.eval_commit_to_future(threshold, correction)

        def return_repository_path(self):
            """ This method returns path to tmp repository"""
            return self.__tmp_repository

        def __fill_data(self, branch, specific_sha):
            """ This method fill and parsing data to DataFrame."""
            LOGGER.info("Filling data to _data_frame")
            self._data_frame = DataFrame(self.__repository.commit_info(branch=branch))
            try:
                __branch = [sha.id for sha in
                    self.__repository.branch_walker(branch)]
            except ValueError:
                raise Exception(r"This repository dont have {0} branch".format
                                (branch))
            LOGGER.info(r"Go through master branch and using gittle.diff for"
            "getting diff output")
            if specific_sha is None:
                __branch = __branch[::-1]
                self.size = len(__branch)
                self.diff_for_shas(__branch)
            else:
                __branch = __branch[::-1]
                after_comm = [idx for idx, found in enumerate(__branch)
                                        if found.find(specific_sha) >= 0]
                if not any(after_comm):
                    raise Exception("This sha {0} is not in this repo.".format(specific_sha))
                after_sha = __branch[after_comm[0]:]
                self.size = len(after_sha)
                self.diff_for_shas(after_sha)

        def diff_for_shas(self, list_shas):
            """
            Method for itereting through list od shas and call _diff
            method.
            """
            for idx, sha in enumerate(list_shas):
#.........这里部分代码省略.........
开发者ID:Radymus,项目名称:QMetric,代码行数:103,代码来源:QMetric.py

示例4: Gittle

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

repo = Gittle('.')

lastest = [
    info['sha']
    for info in repo.commit_info()[1:3]
]

print(repo.diff(*lastest, diff_type='classic'))

print("""

Last Diff

""")


print(list(repo.diff('HEAD')))
开发者ID:0asa,项目名称:gittle,代码行数:21,代码来源:diff.py


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