本文整理汇总了Python中seaserv.seafile_api.get_owned_repo_list函数的典型用法代码示例。如果您正苦于以下问题:Python get_owned_repo_list函数的具体用法?Python get_owned_repo_list怎么用?Python get_owned_repo_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_owned_repo_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self):
"""
When delete user, we should also delete group relationships.
"""
if self.source == "DB":
source = "DB"
else:
source = "LDAP"
owned_repos = []
orgs = ccnet_threaded_rpc.get_orgs_by_user(self.username)
if orgs:
for org in orgs:
owned_repos += seafile_api.get_org_owned_repo_list(org.org_id,
self.username)
else:
owned_repos += seafile_api.get_owned_repo_list(self.username)
for r in owned_repos:
seafile_api.remove_repo(r.id)
clear_token(self.username)
# remove current user from joined groups
ccnet_api.remove_group_user(self.username)
ccnet_api.remove_emailuser(source, self.username)
Profile.objects.delete_profile_by_user(self.username)
示例2: post
def post(self, request, email, format=None):
# migrate an account's repos and groups to an exist account
if not is_valid_username(email):
return api_error(status.HTTP_400_BAD_REQUEST, 'Email %s invalid.' % email)
op = request.data.get('op', '').lower()
if op == 'migrate':
from_user = email
to_user = request.data.get('to_user', '')
if not is_valid_username(to_user):
return api_error(status.HTTP_400_BAD_REQUEST, 'Email %s invalid.' % to_user)
try:
user2 = User.objects.get(email=to_user)
except User.DoesNotExist:
return api_error(status.HTTP_404_NOT_FOUND, 'User %s not found.' % to_user)
# transfer owned repos to new user
for r in seafile_api.get_owned_repo_list(from_user):
seafile_api.set_repo_owner(r.id, user2.username)
# transfer joined groups to new user
for g in seaserv.get_personal_groups_by_user(from_user):
if not seaserv.is_group_user(g.id, user2.username):
# add new user to the group on behalf of the group creator
ccnet_threaded_rpc.group_add_member(g.id, g.creator_name,
to_user)
if from_user == g.creator_name:
ccnet_threaded_rpc.set_group_creator(g.id, to_user)
return Response("success")
else:
return api_error(status.HTTP_400_BAD_REQUEST, 'op can only be migrate.')
示例3: personal_wiki
def personal_wiki(request, page_name="home"):
username = request.user.username
wiki_exists = True
try:
content, repo, dirent = get_personal_wiki_page(username, page_name)
except WikiDoesNotExist:
wiki_exists = False
owned_repos = seafile_api.get_owned_repo_list(username)
owned_repos = [r for r in owned_repos if not r.encrypted]
return render_to_response(
"wiki/personal_wiki.html",
{"wiki_exists": wiki_exists, "owned_repos": owned_repos},
context_instance=RequestContext(request),
)
except WikiPageMissing:
repo = get_personal_wiki_repo(username)
filename = clean_page_name(page_name) + ".md"
if not seaserv.post_empty_file(repo.id, "/", filename, username):
return render_error(request, _("Failed to create wiki page. Please retry later."))
return HttpResponseRedirect(reverse("personal_wiki", args=[page_name]))
else:
url_prefix = reverse("personal_wiki", args=[])
content = convert_wiki_link(content, url_prefix, repo.id, username)
# fetch file latest contributor and last modified
path = "/" + dirent.obj_name
file_path_hash = hashlib.md5(urllib2.quote(path.encode("utf-8"))).hexdigest()[:12]
contributors, last_modified, last_commit_id = FileContributors.objects.get_file_contributors(
repo.id, path.encode("utf-8"), file_path_hash, dirent.obj_id
)
latest_contributor = contributors[0] if contributors else None
wiki_index_exists = True
index_pagename = "index"
index_content = None
try:
index_content, index_repo, index_dirent = get_personal_wiki_page(username, index_pagename)
except (WikiDoesNotExist, WikiPageMissing) as e:
wiki_index_exists = False
else:
index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username)
return render_to_response(
"wiki/personal_wiki.html",
{
"wiki_exists": wiki_exists,
"content": content,
"page": os.path.splitext(dirent.obj_name)[0],
"last_modified": last_modified,
"latest_contributor": latest_contributor,
"path": path,
"repo_id": repo.id,
"search_repo_id": repo.id,
"search_wiki": True,
"wiki_index_exists": wiki_index_exists,
"index_content": index_content,
},
context_instance=RequestContext(request),
)
示例4: list_repos_by_name_and_owner
def list_repos_by_name_and_owner(repo_name, owner):
repos = []
owned_repos = seafile_api.get_owned_repo_list(owner)
for repo in owned_repos:
if repo_name in repo.name:
repo.owner = owner
repos.append(repo)
return repos
示例5: personal_wiki
def personal_wiki(request, page_name="home"):
username = request.user.username
wiki_exists = True
try:
content, repo, dirent = get_personal_wiki_page(username, page_name)
except WikiDoesNotExist:
wiki_exists = False
owned_repos = seafile_api.get_owned_repo_list(username)
owned_repos = [r for r in owned_repos if not r.encrypted]
return render_to_response("wiki/personal_wiki.html", {
"wiki_exists": wiki_exists,
"owned_repos": owned_repos,
}, context_instance=RequestContext(request))
except WikiPageMissing:
repo = get_personal_wiki_repo(username)
filename = clean_page_name(page_name) + '.md'
if not seaserv.post_empty_file(repo.id, "/", filename, username):
return render_error(request, _("Failed to create wiki page. Please retry later."))
return HttpResponseRedirect(reverse('personal_wiki', args=[page_name]))
else:
url_prefix = reverse('personal_wiki', args=[])
content = convert_wiki_link(content, url_prefix, repo.id, username)
# fetch file modified time and modifier
path = '/' + dirent.obj_name
try:
dirent = seafile_api.get_dirent_by_path(repo.id, path)
if dirent:
latest_contributor, last_modified = dirent.modifier, dirent.mtime
else:
latest_contributor, last_modified = None, 0
except SearpcError as e:
logger.error(e)
latest_contributor, last_modified = None, 0
wiki_index_exists = True
index_pagename = 'index'
index_content = None
try:
index_content, index_repo, index_dirent = get_personal_wiki_page(username, index_pagename)
except (WikiDoesNotExist, WikiPageMissing) as e:
wiki_index_exists = False
else:
index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username)
return render_to_response("wiki/personal_wiki.html", {
"wiki_exists": wiki_exists,
"content": content,
"page": os.path.splitext(dirent.obj_name)[0],
"last_modified": last_modified,
"latest_contributor": latest_contributor or _("Unknown"),
"path": path,
"repo_id": repo.id,
"search_repo_id": repo.id,
"search_wiki": True,
"wiki_index_exists": wiki_index_exists,
"index_content": index_content,
}, context_instance=RequestContext(request))
示例6: get_owned_repo_list
def get_owned_repo_list(request):
"""List owned repos.
"""
username = request.user.username
if is_org_context(request):
org_id = request.user.org.org_id
return seafile_api.get_org_owned_repo_list(org_id, username)
else:
return seafile_api.get_owned_repo_list(username)
示例7: edit_profile
def edit_profile(request):
"""
Show and edit user profile.
"""
username = request.user.username
form_class = DetailedProfileForm
if request.method == 'POST':
form = form_class(request.POST)
if form.is_valid():
form.save(username=username)
messages.success(request, _(u'Successfully edited profile.'))
# refresh nickname cache
refresh_cache(request.user.username)
return HttpResponseRedirect(reverse('edit_profile'))
else:
messages.error(request, _(u'Failed to edit profile'))
else:
profile = Profile.objects.get_profile_by_user(username)
d_profile = DetailedProfile.objects.get_detailed_profile_by_user(
username)
init_dict = {}
if profile:
init_dict['nickname'] = profile.nickname
init_dict['intro'] = profile.intro
if d_profile:
init_dict['department'] = d_profile.department
init_dict['telephone'] = d_profile.telephone
form = form_class(init_dict)
# common logic
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
default_repo_id = UserOptions.objects.get_default_repo(username)
if default_repo_id:
default_repo = seafile_api.get_repo(default_repo_id)
else:
default_repo = None
owned_repos = seafile_api.get_owned_repo_list(username)
return render_to_response('profile/set_profile.html', {
'form': form,
'server_crypto': server_crypto,
"sub_lib_enabled": sub_lib_enabled,
'force_server_crypto': settings.FORCE_SERVER_CRYPTO,
'default_repo': default_repo,
'owned_repos': owned_repos,
}, context_instance=RequestContext(request))
示例8: get_keeper_default_library
def get_keeper_default_library():
try:
from_repos = seafile_api.get_owned_repo_list(SERVER_EMAIL)
from_repos = [r for r in from_repos if r.name == KEEPER_DEFAULT_LIBRARY]
if from_repos:
from_repo_id = from_repos[0].id
return { 'repo_id': from_repo_id, 'dirents': seafile_api.list_dir_by_path(from_repo_id, '/') }
else:
raise Exception("Cannot find KEEPER_DEFAULT_LIBRARY repo in admin libraries, please install!")
except Exception as err:
logging.error("Cannot find KEEPER_DEFAULT_LIBRARY dirents, err: " + str(err))
return None
示例9: user_info
def user_info(request, email):
owned_repos = seafile_api.get_owned_repo_list(email)
quota = seafile_api.get_user_quota(email)
quota_usage = 0
share_usage = 0
my_usage = 0
my_usage = seafile_api.get_user_self_usage(email)
if CALC_SHARE_USAGE:
try:
share_usage = seafile_api.get_user_share_usage(email)
except SearpcError, e:
logger.error(e)
share_usage = 0
quota_usage = my_usage + share_usage
示例10: get_my_unenc_repos
def get_my_unenc_repos(request):
"""Get my owned and unencrypted repos.
"""
if not request.is_ajax():
raise Http404
content_type = 'application/json; charset=utf-8'
repos = seafile_api.get_owned_repo_list(request.user.username)
repo_list = []
for repo in repos:
if repo.encrypted:
continue
repo_list.append({"name": repo.name, "id": repo.id})
return HttpResponse(json.dumps(repo_list), content_type=content_type)
示例11: user_info
def user_info(request, email):
owned_repos = seafile_api.get_owned_repo_list(email)
org = ccnet_threaded_rpc.get_orgs_by_user(email)
if not org:
my_usage = seafile_api.get_user_self_usage(email)
quota = seafile_api.get_user_quota(email)
else:
org_id = org[0].org_id
my_usage =seafserv_threaded_rpc. \
get_org_user_quota_usage(org_id, email)
quota = seafserv_threaded_rpc. \
get_org_user_quota(org_id, email)
if CALC_SHARE_USAGE:
try:
share_usage = seafile_api.get_user_share_usage(email)
except SearpcError, e:
logger.error(e)
share_usage = 0
quota_usage = my_usage + share_usage
示例12: user_info
def user_info(request, email):
if request.method == 'POST':
result = {}
content_type = 'application/json; charset=utf-8'
f = SetUserQuotaForm(request.POST)
if f.is_valid():
email = f.cleaned_data['email']
quota_mb = f.cleaned_data['quota']
quota = quota_mb * (1 << 20)
try:
seafile_api.set_user_quota(email, quota)
except:
result['error'] = _(u'Failed to set quota: internal error')
return HttpResponse(json.dumps(result), content_type=content_type)
result['success'] = True
return HttpResponse(json.dumps(result), content_type=content_type)
else:
result['error'] = str(f.errors.values()[0])
return HttpResponse(json.dumps(result), content_type=content_type)
owned_repos = []
owned_repos = seafile_api.get_owned_repo_list(email)
quota = seafile_api.get_user_quota(email)
quota_usage = 0
share_usage = 0
my_usage = 0
my_usage = seafile_api.get_user_self_usage(email)
if CALC_SHARE_USAGE:
try:
share_usage = seafile_api.get_user_share_usage(email)
except SearpcError, e:
logger.error(e)
share_usage = 0
quota_usage = my_usage + share_usage
示例13: list_repos_by_owner
def list_repos_by_owner(owner):
repos = seafile_api.get_owned_repo_list(owner)
for e in repos:
e.owner = owner
return repos
示例14: test_migrate
def test_migrate(self):
self.login_as(self.admin)
# user1 created a repo
user1_repo = self.create_repo(name='user1-repo', desc='',
username=self.user1.username,
passwd=None)
user1_repos = seafile_api.get_owned_repo_list(self.user1.username)
self.assertEqual(len(user1_repos), 1)
self.assertEqual(user1_repos[0].id, user1_repo)
# user1 created a group and joined a group created by the other
user1_group = self.create_group(group_name='test_group',
username=self.user1.username)
other_group = self.create_group(group_name='other_group',
username=self.user.username)
seaserv.ccnet_threaded_rpc.group_add_member(other_group.id,
self.user.username,
self.user1.username)
user1_groups = seaserv.get_personal_groups_by_user(self.user1.username)
self.assertEqual(len(user1_groups), 2)
self.assertEqual(user1_groups[0].id, user1_group.id)
self.assertEqual(user1_groups[0].creator_name, self.user1.username)
self.assertEqual(user1_groups[1].id, other_group.id)
self.assertEqual(user1_groups[1].creator_name, self.user.username)
# user2 had no repos
user2_repos = seafile_api.get_owned_repo_list(self.user2.username)
self.assertEqual(len(user2_repos), 0)
# user2 had no groups
user2_groups = seaserv.get_personal_groups_by_user(self.user2.username)
self.assertEqual(len(user2_groups), 0)
# admin migrate account user1 to account user2
resp = self._do_migrate()
self.assertEqual(200, resp.status_code)
### Verify ###
# user1 should have no repos
new_user1_repos = seafile_api.get_owned_repo_list(self.user1.username)
self.assertEqual(len(new_user1_repos), 0)
# user1 should still in two groups, except not the creator anymore in
# the first group, but second group should remain the same
user1_groups = seaserv.get_personal_groups_by_user(self.user1.username)
self.assertEqual(len(user1_groups), 2)
self.assertEqual(user1_groups[0].id, user1_group.id)
self.assertNotEqual(user1_groups[0].creator_name, self.user1.username)
self.assertEqual(user1_groups[1].id, other_group.id)
self.assertEqual(user1_groups[1].creator_name, self.user.username)
# user2 should have the repo used to be user1's
new_user2_repos = seafile_api.get_owned_repo_list(self.user2.username)
self.assertEqual(len(new_user2_repos), 1)
self.assertEqual(new_user2_repos[0].id, user1_repo)
# user2 should be in two groups, and is the creator of first group,
# but second group should remain the same
user2_groups = seaserv.get_personal_groups_by_user(self.user2.username)
self.assertEqual(len(user2_groups), 2)
self.assertEqual(user2_groups[0].id, user1_group.id)
self.assertEqual(user2_groups[0].creator_name, self.user2.username)
self.assertEqual(user2_groups[1].id, other_group.id)
self.assertEqual(user2_groups[1].creator_name, self.user.username)
示例15: get
def get(self, request):
""" Return repos user can access.
Permission checking:
1. all authenticated user can perform this action.
"""
filter_by = {
'mine': False,
'shared': False,
'group': False,
'public': False,
}
request_type_list = request.GET.getlist('type', "")
if not request_type_list:
# set all to True, no filter applied
filter_by = filter_by.fromkeys(filter_by.iterkeys(), True)
for request_type in request_type_list:
request_type = request_type.strip()
filter_by[request_type] = True
email = request.user.username
# Use dict to reduce memcache fetch cost in large for-loop.
contact_email_dict = {}
nickname_dict = {}
org_id = None
if is_org_context(request):
org_id = request.user.org.org_id
try:
starred_repos = UserStarredFiles.objects.get_starred_repos_by_user(email)
starred_repo_id_list = [item.repo_id for item in starred_repos]
except Exception as e:
logger.error(e)
starred_repo_id_list = []
repo_info_list = []
if filter_by['mine']:
if org_id:
owned_repos = seafile_api.get_org_owned_repo_list(org_id,
email, ret_corrupted=True)
else:
owned_repos = seafile_api.get_owned_repo_list(email,
ret_corrupted=True)
# Reduce memcache fetch ops.
modifiers_set = set([x.last_modifier for x in owned_repos])
for e in modifiers_set:
if e not in contact_email_dict:
contact_email_dict[e] = email2contact_email(e)
if e not in nickname_dict:
nickname_dict[e] = email2nickname(e)
owned_repos.sort(lambda x, y: cmp(y.last_modify, x.last_modify))
for r in owned_repos:
# do not return virtual repos
if r.is_virtual:
continue
repo_info = {
"type": "mine",
"repo_id": r.id,
"repo_name": r.name,
"owner_email": email,
"owner_name": email2nickname(email),
"owner_contact_email": email2contact_email(email),
"last_modified": timestamp_to_isoformat_timestr(r.last_modify),
"modifier_email": r.last_modifier,
"modifier_name": nickname_dict.get(r.last_modifier, ''),
"modifier_contact_email": contact_email_dict.get(r.last_modifier, ''),
"size": r.size,
"encrypted": r.encrypted,
"permission": 'rw', # Always have read-write permission to owned repo
"starred": r.repo_id in starred_repo_id_list,
}
if is_pro_version() and ENABLE_STORAGE_CLASSES:
repo_info['storage_name'] = r.storage_name
repo_info['storage_id'] = r.storage_id
repo_info_list.append(repo_info)
if filter_by['shared']:
if org_id:
shared_repos = seafile_api.get_org_share_in_repo_list(org_id,
email, -1, -1)
else:
shared_repos = seafile_api.get_share_in_repo_list(
email, -1, -1)
repos_with_admin_share_to = ExtraSharePermission.objects.\
get_repos_with_admin_permission(email)
#.........这里部分代码省略.........