예제 #1
0
파일: repos.py 프로젝트: petrus-hanks/titan
def set_repo_meta(organization, repo, team=None):
    meta = Obj()
    meta.watch = get_url(organization, repo, 'repos.watch', team=team)
    meta.unwatch = get_url(organization, repo, 'repos.unwatch', team=team)
    meta.watchers = get_url(organization, repo, 'repos.watchers', team=team)
    meta.view = get_url(organization, repo, 'repos.view', team=team)
    meta.fork = get_url(organization, repo, 'repos.fork', team=team)
    meta.forks = get_url(organization, repo, 'repos.forks', team=team)
    meta.delete = get_url(organization, repo, 'repos.delete', team=team)
    meta.setting = get_url(organization, repo, 'repos.setting', team=team)
    meta.commiter = get_url(organization, repo, 'repos.commiters', team=team)
    meta.remove_commiter = get_url(organization,
                                   repo,
                                   'repos.remove_commiter',
                                   team=team)
    meta.transport = get_url(organization, repo, 'repos.transport', team=team)
    meta.delete = get_url(organization, repo, 'repos.delete', team=team)
    meta.activities = get_url(organization,
                              repo,
                              'repos.activities',
                              team=team)
    meta.get_view = reqcache(key_formatter_maker('repos:view'))(get_url_maker(
        organization, repo, team, 'repos.view'))
    meta.get_blob = reqcache(key_formatter_maker('repos:blob'))(get_url_maker(
        organization, repo, team, 'repos.blob'))
    meta.get_raw = reqcache(key_formatter_maker('repos:raw'))(get_url_maker(
        organization, repo, team, 'repos.raw'))
    meta.get_commits = reqcache(key_formatter_maker('repos:commits'))(
        get_url_maker(organization, repo, team, 'repos.commits'))
    meta.get_commit = reqcache(key_formatter_maker('repos:commit'))(
        get_url_maker(organization, repo, team, 'repos.commit'))
    meta.get_delete_file = reqcache(key_formatter_maker('repos:delete:file'))(
        get_url_maker(organization, repo, team, 'repos.delete_file'))
    meta.get_edit_file = reqcache(key_formatter_maker('repos:edit:file'))(
        get_url_maker(organization, repo, team, 'repos.edit_file'))
    meta.get_new_file = reqcache(key_formatter_maker('repos:new:file'))(
        get_url_maker(organization, repo, team, 'repos.new_file'))
    if repo.parent:
        parent = get_repo(repo.parent)
        #TODO valid check
        parent_team = get_team(parent.tid) if parent.tid else None
        meta.parent = set_repo_meta(organization, parent, team=parent_team)

    @reqcache('repo:commits:count:{gid}:{path}')
    def count_commits(gid, path):
        jagare = get_jagare(repo.id, repo.parent)
        error, ret = jagare.get_log(repo.get_real_path(), total=1, path=path)
        count = 0 if error else ret['total']
        return count

    meta.count_commits = lambda path: count_commits(repo.id, path)
    setattr(repo, 'meta', meta)
예제 #2
0
def set_gist_meta(organization, gist):
    meta = Obj()
    meta.watch = get_url(organization, gist, 'gists.watch')
    meta.unwatch = get_url(organization, gist, 'gists.unwatch')
    meta.watchers = get_url(organization, gist, 'gists.watchers')
    meta.view = get_url(organization, gist, 'gists.view')
    meta.edit = get_url(organization, gist, 'gists.edit')
    meta.fork = get_url(organization, gist, 'gists.fork')
    meta.forks = get_url(organization, gist, 'gists.forks')
    meta.delete = get_url(organization, gist, 'gists.delete')
    meta.revisions = get_url(organization, gist, 'gists.revisions')
    if gist.parent:
        meta.parent = set_gist_meta(organization, get_gist(gist.parent))

    @reqcache('gist:revisions:count:{gid}')
    def count_revisions(gid):
        jagare = get_jagare(gist.id, gist.parent)
        error, ret = jagare.get_log(gist.get_real_path(), total=1)
        count = 0 if error else ret['total']
        return count

    meta.count_revisions = lambda: count_revisions(gist.id)
    setattr(gist, 'meta', meta)