1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 16:31:13 +00:00

Show repo in web

This commit is contained in:
plt
2011-08-16 21:05:42 +08:00
parent 207be6c5bb
commit a8224736b1
7 changed files with 319 additions and 16 deletions

View File

@@ -43,6 +43,9 @@
<li>
<a href="{{ SITE_ROOT }}groups/">Groups</a>
</li>
<li>
<a href="{{ SITE_ROOT }}repos/">Repos</a>
</li>
</ul>
{% endblock %}
</div>

43
templates/repo.html Normal file
View File

@@ -0,0 +1,43 @@
{% extends "base.html" %}
{% block right_panel %}
<h3>Basic Info</h3>
<p><i>Name:</i> {{repo.props.name}}</p>
<p><i>ID:</i> {{repo.props.id}}</p>
<p><i>Description:</i> {{repo.props.desc}}</p>
<h3>Branches</h3>
Current branch: {{repo.props.head_branch}}
<table class="branch-list default">
<tr>
<th>Name</th>
<th>Head Commit</th>
</tr>
{% for branch in branches %}
<tr>
<td>{{branch.props.name}}</td>
<td>{{branch.props.commit_id}}</td>
</tr>
{% endfor %}
</table>
<h3>Commits</h3>
<table class="commit-list default">
<tr>
<th>ID</th>
<th>Time</th>
<th>Discription</th>
</tr>
{% for commit in commits %}
<tr>
<td>{{commit.props.id}}</td>
<td>{{ commit.props.ctime }}</td>
<td>{{commit.props.desc}}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

20
templates/repos.html Normal file
View File

@@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block right_panel %}
<table class="repo-list default">
<tr>
<th>Name</th>
<th>ID</th>
<th>Discription</th>
</tr>
{% for repo in repos %}
<tr>
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}/">{{ repo.props.name }}</a></td>
<td>{{ repo.props.id }}</td>
<td>{{ repo.props.desc }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@@ -1,10 +1,17 @@
import service
from service import cclient, ccnet_rpc, seamsg_rpc, seafile_rpc
from service import translate_peerid, translate_msgtime, translate_groupid
from service import get_peers_by_role
from service import translate_peerid, translate_msgtime, translate_groupid, \
translate_userid, translate_msgtime2, translate_time_sec, \
translate_time_usec
from service import get_peers_by_role, send_command
from service import get_groups, get_group
from service import get_users, get_user
from service import get_users, get_user, get_events, count_event
from service import get_message, get_user_messages, get_group_messages, \
get_messages, count_message, count_user_message, count_group_message
from service import get_repos, get_repo, get_repo_sinfo, get_commits, \
get_user_upload_info
get_branches, \
get_upload_task_list, get_download_task_list, list_share_info, open_dir, \
checkout
from seafile import TaskType

View File

@@ -1,4 +1,60 @@
"""
Peer:
peer.props.id: Peer's ID.
peer.props.name peer's name
peer.props.user_id The ID of the user this peer belong to.
peer.props.timestamp Last modification time in milliseconds.
peer.props.role_list The roles I give to this peer's user.
peer.props.myrole_list This roles this peer's user gives to me.
User:
user.props.id: User ID.
user.props.name: User Name.
user.props.timestamp Last modification time in milliseconds.
user.props.is_self True if this is myself.
user.props.role_list The roles I give to this user.
user.props.myrole_list This roles this user gives to me.
user.props.default_relay The user's default relay.
Group:
group.props.id: Group ID.
group.props.name: Group Name.
group.props.creator: Creator
group.props.rendezvous: The ID of the rendezvous peer.
group.props.timestamp: Last modification time.
group.props.members: The peer IDs of the group members seperated by ' '.
group.props.followers: The peer IDs of the followers.
group.props.maintainers: The peer IDs of the maintainers.
Message:
msg.props.id: Message ID
msg.props.parent_id Parent ID
msg.props.src The user who sent this message
msg.props.dest
msg.props.is_to_group True if this is a group message
msg.props.ctime Creation time
msg.props.rtime Receive time
msg.props.n_ack Number of acks
msg.props.n_reply Number of replies
msg.props.content
Repo:
id: Repo ID
name: Repo Name
desc: Repo description
worktree: The full path of the worktree of the repo
head_branch: The name of the head branch
Branch:
name:
commit_id:
repo_id:
"""
from datetime import datetime
import json
import os
import sys
@@ -25,6 +81,23 @@ ccnet_rpc = ccnet.CcnetRpcClient(pool)
seamsg_rpc = seamsg.RpcClient(pool)
seafile_rpc = seafile.RpcClient(pool)
user_db = {}
def translate_userid(user_id):
try:
user = user_db[user_id]
except:
user = ccnet_rpc.get_user(user_id)
if user:
user_db[user_id] = user
else:
return user_id[:8]
if user.props.name:
return user.props.name + "(" + user_id[:4] + ")"
else:
return user_id[:8]
peer_db = {}
def translate_peerid(peer_id):
@@ -41,6 +114,21 @@ def translate_peerid(peer_id):
else:
return peer_id[:8]
user_db = {}
def translate_userid(user_id):
try:
user = user_db[user_id]
except:
user = ccnet_rpc.get_user(user_id)
if user:
user_db[user_id] = user
else:
return user_id[:8]
if user.props.name:
return user.props.name + "(" + user_id[:4] + ")"
else:
return user_id[:8]
group_db = {}
def translate_groupid(group_id):
@@ -62,6 +150,21 @@ def translate_msgtime(msgtime):
return datetime.fromtimestamp(
(float(msgtime))/1000000).strftime("%Y-%m-%d %H:%M:%S")
def translate_msgtime2(msgtime):
return datetime.fromtimestamp(
(float(msgtime))).strftime("%Y-%m-%d %H:%M:%S")
def translate_time_sec(time):
return datetime.fromtimestamp(
(float(time))).strftime("%Y-%m-%d %H:%M:%S")
def translate_time_usec(time):
return datetime.fromtimestamp(
(float(time))/1000000).strftime("%Y-%m-%d %H:%M:%S")
#### Basic ccnet API ####
def get_peers_by_role(role):
try:
@@ -95,9 +198,11 @@ def get_users():
def get_user(user_id):
user = ccnet_rpc.get_user(user_id)
return group
return user
def get_groups():
"""Get group object list. """
group_ids = ccnet_rpc.list_groups()
if not group_ids:
return []
@@ -113,12 +218,83 @@ def get_groups():
def get_group(group_id):
group = ccnet_rpc.get_group(group_id)
if not group:
return None
group.members = group.props.members.split(" ")
group.followers = group.props.followers.split(" ")
group.maintainers = group.props.maintainers.split(" ")
return group
def get_events(offset, limit):
events = ccnet_rpc.get_events(offset, limit)
for event in events:
if not event.props.body:
event.detail = ""
else:
event.detail = json.loads(event.props.body)
return events
def count_event():
return ccnet_rpc.count_event()
def send_command(command):
client = pool.get_client()
client.send_cmd(command)
ret = client.response[2]
pool.return_client(client)
return ret
######## seamsg API #####
def get_message(msgid):
return seamsg_rpc.get_message_by_id(msgid)
def get_user_messages(user, offset, limit):
"""Get messages sent to or received from `user`.
For example:
get_user_message('eb812fd276432eff33bcdde7506f896eb4769da0', 0, 10)
fetches the lastest 10 messages from the given user.
:param user: user ID.
:param offset: offset of the first message.
:param limit: only fetch `limit` messages.
"""
return seamsg_rpc.get_user_messages(user, offset, limit)
def get_group_messages(group, offset, limit):
"""Get messages of `group`."""
return seamsg_rpc.get_group_messages(group, offset, limit)
def get_messages(offset, limit):
"""Get messages start at `offset`."""
return seamsg_rpc.get_messages(offset, limit)
def count_message():
return seamsg_rpc.count_message()
def count_user_message(user):
return seamsg_rpc.count_user_message(user)
def count_group_message(group):
return seamsg_rpc.count_group_message(group)
######## seafile API ####
def get_repos():
"""
Return repository list.
"""
return seafile_rpc.get_repo_list("", 100)
def get_repo(repo_id):
@@ -130,5 +306,43 @@ def get_repo_sinfo(repo_id):
def get_commits(repo_id):
return seafile_rpc.get_commit_list(repo_id, "", 100)
def get_user_upload_info(user_id):
return seafile_rpc.get_user_upload_info(user_id, 0, 100)
def checkout(repo_id, commit_id):
return seafile_rpc.checkout(repo_id, commit_id)
def get_upload_task_list():
return seafile_rpc.get_upload_task_list()
def get_download_task_list():
return seafile_rpc.get_download_task_list()
def get_branches(repo_id):
"""Get branches of a given repo"""
return seafile_rpc.branch_gets(repo_id)
def list_share_info():
return seafile_rpc.list_share_info(0, 100)
######## ccnet-applet API #####
class CcnetError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return self.msg
def open_dir(path):
"""Call remote service `opendir`."""
client = pool.get_client()
req_id = client.get_request_id()
req = "applet-opendir " + path
client.send_request(req_id, req)
if client.read_response() < 0:
raise NetworkError("Read response error")
rsp = client.response
pool.return_client(client)
if rsp[0] != "200":
raise CcnetError("Error received: %s %s" % (rsp[0], rsp[1]))

View File

@@ -1,6 +1,7 @@
from django.conf.urls.defaults import *
from django.conf import settings
from seahub.views import root, home, peers, groups, myhome, myfiles
from seahub.views import root, home, peers, groups, myhome, myfiles, \
repos, repo
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
@@ -24,6 +25,8 @@ urlpatterns = patterns('',
(r'^home/my/$', myhome),
(r'^peers/$', peers),
(r'^groups/$', groups),
(r'^repos/$', repos),
(r'^repo/(?P<repo_id>[^/]+)/', repo),
(r'^files/my/$', myfiles),
(r'^avatar/', include('avatar.urls')),

View File

@@ -4,8 +4,8 @@ from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from seaserv import cclient, ccnet_rpc, get_groups, get_users, \
get_user_upload_info
from seaserv import cclient, ccnet_rpc, get_groups, get_users, get_repos, \
get_repo, get_commits, get_branches
def root(request):
if request.user.is_authenticated():
@@ -18,6 +18,22 @@ def home(request):
return render_to_response('home.html', {
}, context_instance=RequestContext(request))
def repos(request):
repos = get_repos()
return render_to_response('repos.html', {
"repos": repos,
}, context_instance=RequestContext(request))
def repo(request, repo_id):
repo = get_repo(repo_id)
commits = get_commits(repo_id)
branches = get_branches(repo_id)
return render_to_response('repo.html', {
"repo": repo,
"commits": commits,
"branches": branches,
}, context_instance=RequestContext(request))
def get_user_cid(user):
try:
@@ -74,10 +90,7 @@ def groups(request):
@login_required
def myfiles(request):
cid = get_user_cid(request.user)
if not cid:
uploaded_items = []
else:
uploaded_items = get_user_upload_info(cid)
return render_to_response('myfiles.html', {
'uploaded_items': uploaded_items,
}, context_instance=RequestContext(request))