Exemplo n.º 1
0
def format_reply_list(items):
    for item in items:
        reply = Obj()
        if item.who != g.current_user.id:
            reply.user = get_user(item.who)
        else:
            reply.user = g.current_user
        reply.content = item.content
        reply.time = item.time
        yield reply
Exemplo n.º 2
0
 def get_repos(self, organization, team=None, f=None):
     ret = self.filter_repos(organization, team, f)
     for r in ret:
         t = Obj()
         t.name = None
         if not team and r.tid != 0:
             t = get_team(r.tid)
         elif team:
             t = team
         setattr(r, 'team', t)
         yield r
Exemplo n.º 3
0
 def render_rev(self, rev, organization, gist):
     rev['view'] = get_url(organization, gist, version=rev['sha'])
     rev['committer_time'] = format_time(rev['committer_time'])
     author = reqcache.get(rev['author_email'])
     if not author:
         author = get_user_from_alias(rev['author_email'])
         reqcache.set(rev['author_email'], author)
     if not author:
         author = Obj()
         author.email = rev['author_email']
         author.name = None
     rev['author'] = author
     rev['diff'] = render_diff(rev['diff'])
Exemplo n.º 4
0
def render_commit(commit, organization, repo):
    commit['author_date'] = datetime.fromtimestamp(float(
        commit['author_time'])).date()
    commit['author_time'] = format_time(commit['author_time'])
    author = reqcache.get(commit['author_email'])
    if not author:
        author = get_user_from_alias(commit['author_email'])
        reqcache.set(commit['author_email'], author)
    if not author:
        author = Obj()
        author.email = commit['author_email']
        author.name = None
        author.avatar = lambda size: get_avatar(author.email, size)
    commit['author'] = author
Exemplo n.º 5
0
def get_tree_with_content(jagare,
                          tree,
                          repo,
                          organization,
                          render=True,
                          version='master'):
    ret = []
    for d in tree:
        data = Obj()
        if d['type'] == 'blob':
            data.content, data.content_type, data.length = format_content(
                    jagare, repo, d['path'], render=render, version=version, \
            )
        else:
            continue
        data.name = d['name']
        data.sha = d['sha']
        data.type = d['type']
        data.ago = format_time(d['commit']['committer']['ts'])
        data.message = d['commit']['message'][:150]
        data.commit = d['commit']['sha']
        data.path = d['path']
        ret.append(data)
    return ret
Exemplo n.º 6
0
def format_topic_list(items):
    for item in items:
        t = get_topic(item.tid)
        if not t:
            #TODO have to log
            continue
        topic = Obj()
        topic.id = t.id
        topic.user = get_user(item.contact)
        topic.last_reply = get_reply(t.last_rid)
        topic.title = t.title
        topic.has_new = item.has_new
        yield topic
Exemplo n.º 7
0
def generate_masters_config(
    masters, quorum, \
    down_after_milliseconds, parallel_syncs, \
    failover_timeout, \
):
    id = 0
    for master, values in masters.iteritems():
        values = values or {}
        define = Obj()
        define.id = id
        define.ip, define.port = get_address(master)
        define.quorum = values.get('quorum', quorum)
        define.down_after_milliseconds = values.get('down_after_milliseconds', down_after_milliseconds)
        define.parallel_syncs = values.get('parallel_syncs', parallel_syncs)
        define.failover_timeout = values.get('failover_timeout', failover_timeout)
        yield define
        id += 1
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def render_tree(self, jagare, repo, organization, tree, version, team):
     ret = []
     readme = None
     for d in tree:
         data = Obj()
         if d['type'] == 'tree':
             data.url = get_url(organization,
                                repo,
                                view='repos.view',
                                team=team,
                                version=version,
                                path=d['path'])
         elif d['type'] == 'blob':
             data.url = get_url(organization,
                                repo,
                                view='repos.blob',
                                team=team,
                                version=version,
                                path=d['path'])
             if d['name'].startswith('README.'):
                 readme, content_type, _ = format_content(jagare,
                                                          repo,
                                                          d['path'],
                                                          version=version)
                 if content_type != 'file':
                     readme = None
         elif d['type'] == 'submodule':
             data.url = get_submodule_url(d['submodule'], d['sha'])
             d['name'] = '%s@%s' % (d['name'], d['sha'][:10])
         data.name = d['name']
         data.sha = d['sha']
         data.type = d['type']
         data.ago = format_time(d['commit']['committer']['ts'])
         data.message = d['commit']['message'][:150]
         data.commit = d['commit']['sha']
         data.path = d['path']
         ret.append(data)
     return readme, ret
Exemplo n.º 10
0
 def get_commit_user(self, meta):
     user = Obj()
     commit = Obj()
     user.name = meta['committer']['name']
     user.email = meta['committer']['email']
     user.avatar = None
     commit.message = meta['message']
     commit.user = user
     commit.sha = meta['sha']
     commit.date = meta['committer']['date']
     alias = get_alias_by_email(user.email)
     if alias:
         user = get_user(alias.uid)
         commit.user.name = user.name
         commit.user.avatar = user.avatar(18)
     return commit
Exemplo n.º 11
0
 def gen_tree(self, filenames, codes):
     for filename, content in zip(filenames, codes):
         d = Obj()
         d.name = filename
         d.content = lambda: content
         yield d
Exemplo n.º 12
0
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)