1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-01 15:23:05 +00:00

Update seafile rpc

This commit is contained in:
plt 2012-02-27 15:24:27 +08:00
parent 104b90cad0
commit 23e0d2b79c
3 changed files with 19 additions and 151 deletions

View File

@ -1,6 +1,7 @@
import service
from service import cclient, ccnet_rpc, monitor_rpc, seafserv_rpc
from service import cclient, ccnet_rpc, monitor_rpc, seafserv_rpc, \
seafserv_threaded_rpc
from service import translate_peerid, translate_msgtime, translate_groupid, \
translate_userid, translate_msgtime2, translate_time_sec, \
translate_time_usec, get_peer_avatar_url, get_user_avatar_url, \
@ -8,11 +9,7 @@ from service import translate_peerid, translate_msgtime, translate_groupid, \
from service import get_peers_by_role, get_peers_by_myrole, send_command
from service import get_groups, get_group
from service import get_users, get_user, get_events, count_event
from service import get_repos, get_repo, get_repo_sinfo, get_commits, \
get_branches, get_commit_tree_block_number, \
get_upload_task_list, get_download_task_list, list_share_info, open_dir, \
checkout, get_repo_status, get_diff, list_dir
from service import get_repos, get_repo, get_commits, get_branches
from service import CCNET_CONF_PATH
from seafile import TaskType

View File

@ -114,6 +114,7 @@ pool = ccnet.ClientPool(CCNET_CONF_PATH)
ccnet_rpc = ccnet.CcnetRpcClient(pool)
monitor_rpc = seafile.MonitorRpcClient(pool)
seafserv_rpc = seafile.ServerRpcClient(pool)
seafserv_threaded_rpc = seafile.ServerThreadedRpcClient(pool)
user_db = {}
@ -350,146 +351,16 @@ def get_repos():
Return repository list.
"""
return seafserv_rpc.get_repo_list("", 100)
return seafserv_threaded_rpc.get_repo_list("", 100)
def get_repo(repo_id):
return seafserv_rpc.get_repo(repo_id)
def get_repo_sinfo(repo_id):
return seafserv_rpc.get_repo_sinfo(repo_id)
return seafserv_threaded_rpc.get_repo(repo_id)
def get_commits(repo_id, offset, limit):
"""Get commit lists."""
return seafserv_rpc.get_commit_list(repo_id, offset, limit)
def get_commit_tree_block_number(commit_id):
return seafserv_rpc.get_commit_tree_block_number(commit_id);
def checkout(repo_id, commit_id):
return seafile_threaded_rpc.checkout(repo_id, commit_id)
def get_upload_task_list():
return seafserv_rpc.get_upload_task_list()
def get_download_task_list():
return seafserv_rpc.get_download_task_list()
return seafserv_threaded_rpc.get_commit_list(repo_id, offset, limit)
def get_branches(repo_id):
"""Get branches of a given repo"""
return seafserv_rpc.branch_gets(repo_id)
return seafserv_threaded_rpc.branch_gets(repo_id)
def list_share_info():
return seafserv_rpc.list_share_info(0, 100)
def get_filename(start, ent):
i = start + 1
lenidx = start - 1
while i <= len(ent):
tmp = " ".join(ent[start:i])
if len(tmp) == int(ent[lenidx]):
return (tmp, i)
i = i + 1
return ("", 0)
def add_to_status_list(lists, status_ent):
if status_ent[1] == 'A':
filename, index = get_filename(4, status_ent)
lists[0].append(filename)
elif status_ent[1] == 'D':
filename, index = get_filename(4, status_ent)
lists[1].append(filename)
elif status_ent[1] == 'R':
filename1, index1 = get_filename(4, status_ent)
filename2, index2 = get_filename(index1 + 1, status_ent)
lists[2].append(filename1 + " was moved to " + filename2)
elif status_ent[1] == 'M':
filename, index = get_filename(4, status_ent)
lists[3].append(filename)
elif status_ent[1] == 'U':
if int(status_ent[2]) == 3:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Modified by others but removed by me")
elif int(status_ent[2]) == 4:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Modified by me but removed by others")
elif int(status_ent[2]) == 6:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Others change it from directory to a "\
"file while I modified files under that directory")
elif int(status_ent[2]) == 5:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": I change it from file to a "\
"directory while others modified this file")
elif int(status_ent[2]) == 2:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Newly added by me and others, with different content")
elif int(status_ent[2]) == 1:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Modified by me and others, with different content")
def get_repo_status(repo_id):
# New Removed Renamed Modified Conflict
lists = ([], [], [], [], [])
fmt_status = seafile_threaded_rpc.get_repo_status(repo_id)
if fmt_status == "":
return lists
status_result = fmt_status[:len(fmt_status)-1]
for status_ent in status_result.split("\n"):
tmp = status_ent.split(" ")
# Only display changes in worktree
if tmp[0] == 'W':
add_to_status_list(lists, tmp)
return lists
def get_diff(repo_id, arg1, arg2):
# New Removed Renamed Modified Conflict
# conflict is not used
lists = ([], [], [], [], [])
diff_result = seafserv_rpc.get_diff(repo_id, arg1, arg2)
if diff_result == "":
return lists;
diff_result = diff_result[:len(diff_result)-1]
for d in diff_result.split("\n"):
tmp = d.split(" ")
if tmp[0] == 'C':
add_to_status_list(lists, tmp)
return lists
def list_dir(root_id):
dirent_list = seafserv_rpc.list_dir(root_id);
return dirent_list
######## 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 " + os.path.normpath(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

@ -8,7 +8,7 @@ from django.contrib.auth.models import User
from seaserv import cclient, ccnet_rpc, get_groups, get_users, get_repos, \
get_repo, get_commits, get_branches, \
seafserv_rpc
seafserv_threaded_rpc
from seahub.profile.models import UserProfile
from seahub.share.models import GroupShare, UserShare
@ -100,9 +100,9 @@ def repo(request, repo_id):
is_owner = False
if request.user.is_authenticated():
cid = request.user.user_id
if seafserv_rpc.is_repo_owner(cid, repo_id):
if seafserv_threaded_rpc.is_repo_owner(cid, repo_id):
is_owner = True
token = seafserv_rpc.get_repo_token(repo_id)
token = seafserv_threaded_rpc.get_repo_token(repo_id)
return render_to_response('repo.html', {
"repo": repo,
@ -124,12 +124,12 @@ def repo_share(request, repo_id):
@login_required
def modify_token(request, repo_id):
cid = request.user.user_id
if not seafserv_rpc.is_repo_owner(cid, repo_id):
if not seafserv_threaded_rpc.is_repo_owner(cid, repo_id):
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
token = request.POST.get('token', '')
if token:
seafserv_rpc.set_repo_token(repo_id, token)
seafserv_threaded_rpc.set_repo_token(repo_id, token)
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
@ -137,11 +137,11 @@ def modify_token(request, repo_id):
@login_required
def remove_repo(request, repo_id):
cid = request.user.user_id
if not seafserv_rpc.is_repo_owner(cid, repo_id) and not request.user.is_staff:
if not seafserv_threaded_rpc.is_repo_owner(cid, repo_id) and not request.user.is_staff:
return render_to_response('permission_error.html', {
}, context_instance=RequestContext(request))
seafserv_rpc.remove_repo(repo_id)
seafserv_threaded_rpc.remove_repo(repo_id)
return HttpResponseRedirect(request.META['HTTP_REFERER'])
@ -152,8 +152,8 @@ def myhome(request):
user_id = request.user.user_id
if user_id:
owned_repos = seafserv_rpc.list_owned_repos(user_id)
quota_usage = seafserv_rpc.get_user_quota_usage(user_id)
owned_repos = seafserv_threaded_rpc.list_owned_repos(user_id)
quota_usage = seafserv_threaded_rpc.get_user_quota_usage(user_id)
return render_to_response('myhome.html', {
"owned_repos": owned_repos,
@ -171,7 +171,7 @@ def seafadmin(request):
if not request.user.is_staff:
raise Http404
repos = seafserv_rpc.get_repo_list("", 1000)
repos = seafserv_threaded_rpc.get_repo_list("", 1000)
return render_to_response(
'repos.html', {
'repos': repos,
@ -189,7 +189,7 @@ def useradmin(request):
user.profile = user.get_profile()
user.ccnet_user = ccnet_rpc.get_user(user.profile.ccnet_user_id)
user.role_list = user.ccnet_user.props.role_list.split(',')
except UserProfile.DoesNotExist:
except:
user.profile = None
user.ccnet_user = None