本文整理汇总了Python中seahub.utils.normalize_file_path函数的典型用法代码示例。如果您正苦于以下问题:Python normalize_file_path函数的具体用法?Python normalize_file_path怎么用?Python normalize_file_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize_file_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_related_file_uuid
def add_related_file_uuid(self, o_repo_id, r_repo_id, o_path, r_path):
o_file_path = normalize_file_path(o_path)
o_filename = os.path.basename(o_file_path)
o_parent_path = os.path.dirname(o_file_path)
r_file_path = normalize_file_path(r_path)
r_filename = os.path.basename(r_file_path)
r_parent_path = os.path.dirname(r_file_path)
o_uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(o_repo_id, o_parent_path, o_filename, is_dir=False)
r_uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(r_repo_id, r_parent_path, r_filename, is_dir=False)
related_file_uuid = self.model(o_uuid=o_uuid, r_uuid=r_uuid)
related_file_uuid.save()
return related_file_uuid
示例2: get_related_file_uuid
def get_related_file_uuid(self, o_repo_id, r_repo_id, o_path, r_path):
o_file_path = normalize_file_path(o_path)
o_filename = os.path.basename(o_file_path)
o_parent_path = os.path.dirname(o_file_path)
r_file_path = normalize_file_path(r_path)
r_filename = os.path.basename(r_file_path)
r_parent_path = os.path.dirname(r_file_path)
o_uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(o_repo_id, o_parent_path, o_filename, is_dir=False)
r_uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(r_repo_id, r_parent_path, r_filename, is_dir=False)
try:
return super(RelatedFilesManager, self).get(
Q(o_uuid=o_uuid, r_uuid=r_uuid) | Q(o_uuid=r_uuid, r_uuid=o_uuid))
except self.model.DoesNotExist:
return None
示例3: get
def get(self, request, repo_id):
"""list all tags of a file.
"""
# argument check
file_path = request.GET.get('file_path')
if not file_path:
error_msg = 'file_path invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
file_path = normalize_file_path(file_path)
# resource check
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
file_id = seafile_api.get_file_id_by_path(repo_id, file_path)
if not file_id:
error_msg = 'File not found.'
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# permission check
if not check_folder_permission(request, repo_id, '/'):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
try:
file_tags = FileTags.objects.get_file_tag_by_path(repo_id, file_path)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error.'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({"file_tags": file_tags}, status=status.HTTP_200_OK)
示例4: delete
def delete(self, request, repo_id):
""" delete a single file/folder in a library
"""
path = request.GET.get('path', None)
if not path:
error_msg = 'path invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
path = normalize_file_path(path)
file_id = None
dir_id = None
try:
file_id = seafile_api.get_file_id_by_path(repo_id, path)
dir_id = seafile_api.get_dir_id_by_path(repo_id, path)
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
if not file_id and not dir_id:
return Response({'success': True})
parent_dir = os.path.dirname(path)
file_name = os.path.basename(path)
try:
seafile_api.del_file(repo_id,
parent_dir, file_name, request.user.username)
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
示例5: put
def put(self, request, repo_id):
""" Copy a single file/folder to other place.
"""
# check parameter for src
path = request.GET.get('path', None)
if not path:
error_msg = 'path invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
try:
dirent = seafile_api.get_dirent_by_path(repo_id, path)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
if not dirent:
error_msg = 'File or folder %s not found.' % path
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
if path == '/':
error_msg = 'path invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# normalize path to '/1/2/3' format
# NOT ends with '/'
path = normalize_file_path(path)
# now get `src_dir` and `obj_name` according to normalized path
src_repo_id = repo_id
src_dir = os.path.dirname(path)
src_obj_name = os.path.basename(path)
# check parameter for dst
dst_repo_id = request.data.get('dst_repo_id', src_repo_id)
if dst_repo_id != src_repo_id and not seafile_api.get_repo(dst_repo_id):
error_msg = 'Library %s not found.' % dst_repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
dst_dir = request.data.get('dst_dir', '/')
if dst_dir != '/':
dst_dir = normalize_dir_path(dst_dir)
if not seafile_api.get_dir_id_by_path(dst_repo_id, dst_dir):
error_msg = 'Folder %s not found.' % dst_dir
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# copy file
username = request.user.username
dst_obj_name = check_filename_with_rename(dst_repo_id, dst_dir,
src_obj_name)
try:
seafile_api.copy_file(src_repo_id, src_dir, src_obj_name, dst_repo_id,
dst_dir, dst_obj_name, username, need_progress=0, synchronous=1)
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True, 'dst_item_name': dst_obj_name})
示例6: get_file_draft
def get_file_draft(repo_id, file_path, is_draft=False, has_draft=False):
draft = {}
draft['draft_id'] = None
draft['draft_file_path'] = ''
draft['draft_origin_file_path'] = ''
from .models import Draft
if is_draft:
d = Draft.objects.get(origin_repo_id=repo_id, draft_file_path=file_path)
uuid = FileUUIDMap.objects.get_fileuuidmap_by_uuid(d.origin_file_uuid)
file_path = posixpath.join(uuid.parent_path, uuid.filename)
draft['draft_id'] = d.id
draft['draft_file_path'] = d.draft_file_path
draft['draft_origin_file_path'] = file_path
if has_draft:
file_path = normalize_file_path(file_path)
parent_path = os.path.dirname(file_path)
filename = os.path.basename(file_path)
file_uuid = FileUUIDMap.objects.get_fileuuidmap_by_path(
repo_id, parent_path, filename, is_dir=False)
d = Draft.objects.get(origin_file_uuid=file_uuid.uuid)
draft['draft_id'] = d.id
draft['draft_file_path'] = d.draft_file_path
return draft
示例7: create_file_link
def create_file_link(self, username, repo_id, path, password=None,
expire_date=None):
"""Create download link for file.
"""
path = normalize_file_path(path)
return self._add_file_share(username, repo_id, path, 'f', password,
expire_date)
示例8: get_draft_file_name
def get_draft_file_name(repo_id, file_path):
file_path = normalize_file_path(file_path)
file_name, file_ext = os.path.splitext(os.path.basename(file_path))
draft_file_name = "%s%s%s" % (file_name, '(draft)', file_ext)
draft_file_name = check_filename_with_rename(repo_id, '/Drafts', draft_file_name)
return draft_file_name
示例9: get_private_share_in_file
def get_private_share_in_file(self, username, repo_id, path):
"""Get a file that private shared to ``username``.
"""
path = normalize_file_path(path)
ret = super(PrivateFileDirShareManager, self).filter(
to_user=username, repo_id=repo_id, path=path, s_type='f')
return ret[0] if len(ret) > 0 else None
示例10: get_dir_starred_files
def get_dir_starred_files(email, repo_id, parent_dir, org_id=-1):
'''Get starred files under parent_dir.
'''
starred_files = UserStarredFiles.objects.filter(email=email,
repo_id=repo_id,
path__startswith=parent_dir,
org_id=org_id)
return [ normalize_file_path(f.path) for f in starred_files ]
示例11: delete
def delete(self, request, repo_id, format=None):
""" Delete file.
Permission checking:
1. user with 'rw' permission.
"""
# argument check
path = request.GET.get('p', None)
if not path:
error_msg = 'p invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
path = normalize_file_path(path)
# resource check
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
file_id = seafile_api.get_file_id_by_path(repo_id, path)
if not file_id:
return Response({'success': True})
# permission check
parent_dir = os.path.dirname(path)
username = request.user.username
if check_folder_permission(request, repo_id, parent_dir) != PERMISSION_READ_WRITE:
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
# check file lock
try:
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
if is_locked and not locked_by_me:
error_msg = _("File is locked")
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
# delete file
file_name = os.path.basename(path)
try:
seafile_api.del_file(repo_id, parent_dir,
file_name, request.user.username)
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
示例12: add_file_tag
def add_file_tag(self, repo_id, repo_tag_id, file_path):
file_path = normalize_file_path(file_path)
filename = os.path.basename(file_path)
parent_path = os.path.dirname(file_path)
file_uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(
repo_id, parent_path, filename, is_dir=False)
repo_tag = RepoTags.objects.get_repo_tag_by_id(repo_tag_id)
file_tag = self.model(repo_tag=repo_tag, file_uuid=file_uuid)
file_tag.save()
return file_tag
示例13: add_private_file_share
def add_private_file_share(self, from_user, to_user, repo_id, path, perm):
"""
"""
path = normalize_file_path(path)
token = gen_token(max_length=10)
pfs = self.model(from_user=from_user, to_user=to_user, repo_id=repo_id,
path=path, s_type='f', token=token, permission=perm)
pfs.save(using=self._db)
return pfs
示例14: is_draft_file
def is_draft_file(repo_id, file_path):
is_draft = False
file_path = normalize_file_path(file_path)
from .models import Draft
try:
Draft.objects.get(origin_repo_id=repo_id, draft_file_path=file_path)
is_draft = True
except Draft.DoesNotExist:
pass
return is_draft
示例15: get_file_tag
def get_file_tag(self, repo_id, repo_tag_id, file_path):
file_path = normalize_file_path(file_path)
filename = os.path.basename(file_path)
parent_path = os.path.dirname(file_path)
file_uuid = FileUUIDMap.objects.get_fileuuidmap_by_path(
repo_id, parent_path, filename, is_dir=False)
try:
return super(FileTagsManager, self).get(repo_tag_id=repo_tag_id,
file_uuid=file_uuid)
except self.model.DoesNotExist:
return None