コード例 #1
0
ファイル: tops.py プロジェクト: sniperkit/repoxplorer
    def gby(self, ci, pi, query_kwargs, inc_repos_detail, f1, f2):
        repos = f1(**query_kwargs)[1]
        projects = utils.get_projects_from_references(pi, repos)
        if inc_repos_detail:
            repos_contributed = [(p, ca) for p, ca in repos.items()]
        else:
            repos_contributed = []
            for pname in projects:
                p_repos = pi.get_projects()[pname]
                p_filter = utils.get_references_filter(p_repos)
                _query_kwargs = copy.deepcopy(query_kwargs)
                _query_kwargs['repos'] = p_filter
                ca = int(f2(**_query_kwargs) or 0)
                if ca:
                    repos_contributed.append((pname, ca))

        sorted_rc = sorted(repos_contributed, key=lambda i: i[1], reverse=True)
        ret = []
        for item in sorted_rc:
            ret.append({"amount": int(item[1])})
            if inc_repos_detail:
                ret[-1]["projects"] = utils.get_projects_from_references(
                    pi, [item[0]])
            ret[-1]["name"] = ":".join(item[0].split(':')[-2:])

        return ret
コード例 #2
0
ファイル: infos.py プロジェクト: morucci/repoxplorer
    def get_generic_infos(
            self, projects_index, commits_index, idents, pid, query_kwargs):
        infos = {}
        infos['commits_amount'] = commits_index.get_commits_amount(
            **query_kwargs)
        if not infos['commits_amount']:
            infos['line_modifieds_amount'] = 0
            return infos
        authors = commits_index.get_authors(**query_kwargs)[1]
        infos['authors_amount'] = len(utils.authors_sanitize(idents, authors))
        first, last, duration = commits_index.get_commits_time_delta(
            **query_kwargs)
        infos['first'] = first
        infos['last'] = last
        infos['duration'] = duration
        ttl_average = commits_index.get_ttl_stats(**query_kwargs)[1]['avg']
        infos['ttl_average'] = \
            timedelta(seconds=int(ttl_average)) - timedelta(seconds=0)
        infos['ttl_average'] = int(infos['ttl_average'].total_seconds())

        infos['line_modifieds_amount'] = int(
            commits_index.get_line_modifieds_stats(**query_kwargs)[1]['sum'])

        repos = [r for r in commits_index.get_repos(**query_kwargs)[1]
                 if not r.startswith('meta_ref: ')]
        if pid:
            projects = (pid,)
        else:
            projects = utils.get_projects_from_references(
                projects_index, repos)
        infos['repos_amount'] = len(repos)
        infos['projects_amount'] = len(projects)
        return infos
コード例 #3
0
    def get_generic_infos(self, projects_index, commits_index, idents, pid,
                          query_kwargs):
        infos = {}
        infos['commits_amount'] = commits_index.get_commits_amount(
            **query_kwargs)
        if not infos['commits_amount']:
            infos['line_modifieds_amount'] = 0
            return infos
        authors = commits_index.get_authors(**query_kwargs)[1]
        infos['authors_amount'] = len(utils.authors_sanitize(idents, authors))
        first, last, duration = commits_index.get_commits_time_delta(
            **query_kwargs)
        infos['first'] = first
        infos['last'] = last
        infos['duration'] = duration
        ttl_average = commits_index.get_ttl_stats(**query_kwargs)[1]['avg']
        infos['ttl_average'] = \
            timedelta(seconds=int(ttl_average)) - timedelta(seconds=0)
        infos['ttl_average'] = int(infos['ttl_average'].total_seconds())

        infos['line_modifieds_amount'] = int(
            commits_index.get_line_modifieds_stats(**query_kwargs)[1]['sum'])

        repos = [
            r for r in commits_index.get_repos(**query_kwargs)[1]
            if not r.startswith('meta_ref: ')
        ]
        if pid:
            projects = (pid, )
        else:
            projects = utils.get_projects_from_references(
                projects_index, repos)
        infos['repos_amount'] = len(repos)
        infos['projects_amount'] = len(projects)
        return infos
コード例 #4
0
ファイル: commits.py プロジェクト: sloppycoder/repoxplorer
    def commits(self, pid=None, tid=None, cid=None, gid=None,
                start=0, limit=10,
                dfrom=None, dto=None, inc_merge_commit=None,
                inc_repos=None, metadata=None, exc_groups=None,
                inc_groups=None):

        c = Commits(index.Connector())
        projects_index = Projects()
        idents = Contributors()

        query_kwargs = utils.resolv_filters(
            projects_index, idents, pid, tid, cid, gid,
            dfrom, dto, inc_repos, inc_merge_commit,
            metadata, exc_groups, inc_groups)
        query_kwargs.update(
            {'start': start, 'limit': limit})

        resp = c.get_commits(**query_kwargs)

        for cmt in resp[2]:
            # Get extra metadata keys
            extra = set(cmt.keys()) - set(PROPERTIES.keys())
            cmt['metadata'] = list(extra)
            cmt['repos'] = [r for r in cmt['repos']
                            if not r.startswith('meta_ref: ')]
            # Compute link to access commit diff based on the
            # URL template provided in projects.yaml
            cmt['gitwebs'] = [
                projects_index.get_gitweb_link(r) %
                {'sha': cmt['sha']} for r in cmt['repos']]
            cmt['projects'] = utils.get_projects_from_references(
                projects_index, cmt['repos'])
            # Also remove the URI part
            cmt['repos'] = [":".join(p.split(':')[-2:]) for
                            p in cmt['repos']]
            # Request the ident index to fetch author/committer name/email
            for elm in ('author', 'committer'):
                ident = list(idents.get_idents_by_emails(
                    cmt['%s_email' % elm]).values())[0]
                cmt['%s_email' % elm] = ident['default-email']
                if ident['name']:
                    cmt['%s_name' % elm] = ident['name']
            # Convert the TTL to something human readable
            cmt['ttl'] = str((datetime.fromtimestamp(cmt['ttl']) -
                              datetime.fromtimestamp(0)))
            cmt['author_gravatar'] = \
                hashlib.md5(cmt['author_email'].encode(
                    errors='ignore')).hexdigest()
            cmt['committer_gravatar'] = \
                hashlib.md5(cmt['committer_email'].encode(
                    errors='ignore')).hexdigest()
            if len(cmt['commit_msg']) > 80:
                cmt['commit_msg'] = cmt['commit_msg'][0:76] + '...'
            # Add cid and ccid
            cmt['cid'] = utils.encrypt(xorkey, cmt['author_email'])
            cmt['ccid'] = utils.encrypt(xorkey, cmt['committer_email'])
            # Remove email details
            del cmt['author_email']
            del cmt['committer_email']
        return resp
コード例 #5
0
ファイル: groups.py プロジェクト: morucci/repoxplorer
    def index(self, prefix=None, nameonly='false', withstats='false',
              pid=None, dfrom=None, dto=None, inc_merge_commit=None):
        ci = Commits(index.Connector())
        contributors_index = Contributors()
        groups = contributors_index.get_groups()
        if withstats == 'true':
            projects_index = Projects()
        if nameonly == 'true':
            ret = dict([(k, None) for k in groups.keys()])
            if prefix:
                ret = dict([(k, None) for k in ret.keys() if
                            k.lower().startswith(prefix)])
            return ret
        ret_groups = {}
        for group, data in groups.items():
            if prefix and not group.lower().startswith(prefix.lower()):
                continue
            rg = {'members': {},
                  'description': data.get('description', ''),
                  'domains': data.get('domains', [])}
            emails = list(data['emails'].keys())
            members = contributors_index.get_idents_by_emails(emails)
            for id, member in members.items():
                member['gravatar'] = hashlib.md5(
                    member['default-email'].encode(
                        errors='ignore')).hexdigest()
                # TODO(fbo): bounces should be a list of bounce
                # Let's deactivate that for now
                # member['bounces'] = bounces
                del member['emails']
                if not member['name']:
                    # Try to find it among commits
                    suggested = ci.get_commits_author_name_by_emails(
                        [member['default-email']])
                    name = suggested.get(member['default-email'],
                                         'Unnamed')
                    member['name'] = name
                del member['default-email']
                rg['members'][utils.encrypt(xorkey, id)] = member

            if withstats == 'true':
                # Fetch the number of projects and repos contributed to
                query_kwargs = utils.resolv_filters(
                    projects_index, contributors_index, pid, None, None, group,
                    dfrom, dto, None, inc_merge_commit, None, None, None)

                repos = [r for r in ci.get_repos(**query_kwargs)[1]
                         if not r.startswith('meta_ref: ')]
                projects = utils.get_projects_from_references(
                    projects_index, repos)
                rg['repos_amount'] = len(repos)
                rg['projects_amount'] = len(projects)

            ret_groups[group] = rg

        return ret_groups
コード例 #6
0
ファイル: tops.py プロジェクト: morucci/repoxplorer
    def gby(self, ci, pi, query_kwargs,
            inc_repos_detail, f1, f2, limit):
        repos = f1(**query_kwargs)[1]
        if inc_repos_detail:
            repos_contributed = [
                (p, ca) for p, ca in repos.items()
                if not p.startswith('meta_ref: ')]
        else:
            repos_contributed = []
            projects = utils.get_projects_from_references(
                pi, [r for r in repos.keys()
                     if not r.startswith('meta_ref: ')])
            for pname in projects:
                project = pi.get(pname, source=['name', 'meta-ref', 'refs'])
                p_filter = utils.get_references_filter(project)
                _query_kwargs = copy.deepcopy(query_kwargs)
                _query_kwargs['repos'] = p_filter
                ca = int(f2(**_query_kwargs) or 0)
                if ca:
                    repos_contributed.append((pname, ca))

        sorted_rc = sorted(repos_contributed,
                           key=lambda i: i[1],
                           reverse=True)
        ret = []
        for item in sorted_rc:
            ret.append({"amount": int(item[1])})
            if inc_repos_detail:
                ret[-1]["projects"] = utils.get_projects_from_references(
                    pi, [item[0]])
            ret[-1]["name"] = ":".join(item[0].split(':')[-2:])

        if limit is None:
            limit = 10
        else:
            limit = int(limit)
        # If limit set to a negative value all results will be returned
        if limit >= 0:
            ret = ret[:limit]
        return ret
コード例 #7
0
ファイル: tops.py プロジェクト: ohe/repoxplorer
    def gby(self, ci, pi, query_kwargs,
            inc_repos_detail, f1, f2, limit):
        repos = f1(**query_kwargs)[1]
        if inc_repos_detail:
            repos_contributed = [
                (p, ca) for p, ca in repos.items()
                if not p.startswith('meta_ref: ')]
        else:
            repos_contributed = []
            projects = utils.get_projects_from_references(
                pi, [r for r in repos.keys()
                     if not r.startswith('meta_ref: ')])
            for pname in projects:
                project = pi.get(pname, source=['name', 'meta-ref', 'refs'])
                p_filter = utils.get_references_filter(project)
                _query_kwargs = copy.deepcopy(query_kwargs)
                _query_kwargs['repos'] = p_filter
                ca = int(f2(**_query_kwargs) or 0)
                if ca:
                    repos_contributed.append((pname, ca))

        sorted_rc = sorted(repos_contributed,
                           key=lambda i: i[1],
                           reverse=True)
        ret = []
        for item in sorted_rc:
            ret.append({"amount": int(item[1])})
            if inc_repos_detail:
                ret[-1]["projects"] = utils.get_projects_from_references(
                    pi, [item[0]])
            ret[-1]["name"] = ":".join(item[0].split(':')[-2:])

        if limit is None:
            limit = 10
        else:
            limit = int(limit)
        # If limit set to a negative value all results will be returned
        if limit >= 0:
            ret = ret[:limit]
        return ret
コード例 #8
0
ファイル: groups.py プロジェクト: sloppycoder/repoxplorer
    def index(self,
              prefix=None,
              nameonly='false',
              withstats='false',
              pid=None,
              dfrom=None,
              dto=None,
              inc_merge_commit=None):
        ci = Commits(index.Connector())
        contributors_index = Contributors()
        groups = contributors_index.get_groups()
        if withstats == 'true':
            projects_index = Projects()
        if nameonly == 'true':
            ret = dict([(k, None) for k in groups.keys()])
            if prefix:
                ret = dict([(k, None) for k in ret.keys()
                            if k.lower().startswith(prefix)])
            return ret
        ret_groups = {}
        for group, data in groups.items():
            if prefix and not group.lower().startswith(prefix.lower()):
                continue
            rg = {
                'members': {},
                'description': data.get('description', ''),
                'domains': data.get('domains', [])
            }
            emails = list(data['emails'].keys())
            members = contributors_index.get_idents_by_emails(emails)
            for id, member in members.items():
                member['gravatar'] = hashlib.md5(
                    member['default-email'].encode(
                        errors='ignore')).hexdigest()
                # TODO(fbo): bounces should be a list of bounce
                # Let's deactivate that for now
                # member['bounces'] = bounces
                del member['emails']
                if not member['name']:
                    # Try to find it among commits
                    suggested = ci.get_commits_author_name_by_emails(
                        [member['default-email']])
                    name = suggested.get(member['default-email'], 'Unnamed')
                    member['name'] = name
                del member['default-email']
                rg['members'][utils.encrypt(xorkey, id)] = member

            if withstats == 'true':
                # Fetch the number of projects and repos contributed to
                query_kwargs = utils.resolv_filters(
                    projects_index, contributors_index, pid, None, None, group,
                    dfrom, dto, None, inc_merge_commit, None, None, None)

                repos = [
                    r for r in ci.get_repos(**query_kwargs)[1]
                    if not r.startswith('meta_ref: ')
                ]
                projects = utils.get_projects_from_references(
                    projects_index, repos)
                rg['repos_amount'] = len(repos)
                rg['projects_amount'] = len(projects)

            ret_groups[group] = rg

        return ret_groups