• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python seaserv.get_repo函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中seaserv.get_repo函数的典型用法代码示例。如果您正苦于以下问题:Python get_repo函数的具体用法?Python get_repo怎么用?Python get_repo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_repo函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: render_file_revisions

def render_file_revisions (request, repo_id):
    """List all history versions of a file."""

    days_str = request.GET.get('days', '')
    try:
        days = int(days_str)
    except ValueError:
        days = 7

    path = request.GET.get('p', '/')
    if path[-1] == '/':
        path = path[:-1]
    u_filename = os.path.basename(path)

    if not path:
        return render_error(request)

    repo = get_repo(repo_id)
    if not repo:
        error_msg = _(u"Library does not exist")
        return render_error(request, error_msg)

    filetype = get_file_type_and_ext(u_filename)[0].lower()
    if filetype == 'text' or filetype == 'markdown':
        can_compare = True
    else:
        can_compare = False

    try:
        commits = seafile_api.get_file_revisions(repo_id, path, -1, -1, days)
    except SearpcError, e:
        logger.error(e.msg)
        return render_error(request, e.msg)
开发者ID:domal,项目名称:seahub,代码行数:33,代码来源:__init__.py


示例2: GET

    def GET(self):
        inputs = web.webapi.input(repo='')
        sync_status = {}
        repo = get_repo(inputs.repo)
        if not repo or not repo.props.worktree or not repo.props.head_branch: 
            return json.dumps(sync_status)

        relay = get_relay_of_repo(repo)
        if relay:
            if relay.props.net_state != NET_STATE_CONNECTED:
                sync_status['state'] = 'relay not connected'
                return json.dumps(sync_status)

        t = seafile_rpc.get_repo_sync_task(inputs.repo)
        if t:
            if t.props.state == 'error' and t.props.error == 'relay not connected':
                # Hide the 'relay not connected' error from daemon when relay
                # is actually connected, but the check sync pulse has not come yet
                sync_status['state'] = 'waiting for sync'
                return json.dumps(sync_status)
            elif t.props.state == 'canceled' or t.props.state == 'cancel pending':
                sync_status['state'] = 'waiting for sync'
            else:
                sync_status['state'] = t.props.state

            sync_status['is_sync_lan'] = t.props.is_sync_lan
            sync_status['error'] = t.props.error
        else:
            # No sync task yet: seafile maybe have just been started 
            sync_status['state'] = 'waiting for sync'

        if sync_status['state'] == 'waiting for sync' and not repo.props.auto_sync:
            sync_status['state'] = 'auto sync is turned off'

        return json.dumps(sync_status)
开发者ID:sheyong,项目名称:seafile,代码行数:35,代码来源:main.py


示例3: delete

    def delete(self, request, repo_id, format=None):
        # delete dir or file
        repo = get_repo(repo_id)
        if not repo:
            return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
        
        resp = check_repo_access_permission(request, repo)
        if resp:
            return resp

        path = request.GET.get('p', None)
        if not path:
            return api_error(status.HTTP_400_BAD_REQUEST, 'Path is missing.')

        if path == '/':         # Can not delete root path.
            return api_error(status.HTTP_400_BAD_REQUEST, 'Path is invalid.')

        if path[-1] == '/':     # Cut out last '/' if possible.
            path = path[:-1]
            
        parent_dir = os.path.dirname(path)
        parent_dir_utf8 = os.path.dirname(path).encode('utf-8')
        file_name_utf8 = os.path.basename(path).encode('utf-8')

        try:
            seafserv_threaded_rpc.del_file(repo_id, parent_dir_utf8,
                                           file_name_utf8,
                                           request.user.username)
        except SearpcError, e:
            return api_error(HTTP_520_OPERATION_FAILED,
                             "Failed to delete file.")
开发者ID:viktorlindgren,项目名称:seahub,代码行数:31,代码来源:views.py


示例4: post

    def post(self, request, repo_id):
        repo = get_repo(repo_id)
        resp = check_repo_access_permission(request, repo)
        if resp:
            return resp

        path = request.GET.get('p', None)
        if not path:
            return api_error(request, '413', 'Path needed')

        op = request.GET.get('op', 'sendsharelink')
        if op == 'sendsharelink':
            emails = request.POST.get('email', None)
            if not emails:
                return api_error(request, '400', "Email required")
            return send_share_link(request, path, emails)
        elif op == 'star':
            org_id = int(request.GET.get('org', '-1'))
            star_file(request.user.username, repo_id, path, False, org_id=org_id)
            return HttpResponse(json.dumps('success'), status=200,
                                content_type=json_content_type)
        elif op == 'unstar':
            unstar_file(request.user.username, repo_id, path)
            return HttpResponse(json.dumps('success'), status=200,
                                content_type=json_content_type)
        return api_error(request, '415')
开发者ID:hilerchyn,项目名称:seahub,代码行数:26,代码来源:views.py


示例5: _decorated

    def _decorated(request, *args, **kwargs):
        repo_id = kwargs.get('repo_id', None)
        if not repo_id:
            raise Exception, 'Repo id is not found in url.'
        repo = get_repo(repo_id)
        if not repo:
            raise Http404
        username = request.user.username
        if repo.encrypted:
            try:
                server_crypto = UserOptions.objects.is_server_crypto(username)
            except CryptoOptionNotSetError:
                return render_to_response('options/set_user_options.html', {
                        }, context_instance=RequestContext(request))

            if (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
                    and not is_passwd_set(repo_id, username):
                return render_to_response('decrypt_repo_form.html', {
                        'repo': repo,
                        'next': request.get_full_path(),
                        }, context_instance=RequestContext(request))

            if repo.enc_version == 2 and not server_crypto:
                return render_error(request, _(u'Files in this library can not be viewed online.'))

        return func(request, *args, **kwargs)
开发者ID:gekkstah,项目名称:seahub,代码行数:26,代码来源:decorators.py


示例6: share_link_thumbnail_get

def share_link_thumbnail_get(request, token, size, path):
    """ handle thumbnail src from dir download link page

    return thumbnail file to web
    """

    fileshare = FileShare.objects.get_valid_file_link_by_token(token)
    if not fileshare:
        return HttpResponse()

    repo_id = fileshare.repo_id
    repo = get_repo(repo_id)
    if not repo:
        return HttpResponse()

    if fileshare.path == '/':
        image_path = path
    else:
        image_path = posixpath.join(fileshare.path, path.lstrip('/'))

    obj_id = get_file_id_by_path(repo_id, image_path)
    thumbnail_file = os.path.join(THUMBNAIL_ROOT, str(size), obj_id)

    if not os.path.exists(thumbnail_file) and \
        allow_generate_thumbnail(request, repo_id, image_path):
            generate_thumbnail(request, repo_id, size, image_path)
    try:
        with open(thumbnail_file, 'rb') as f:
            thumbnail = f.read()
        return HttpResponse(content=thumbnail, mimetype='image/'+THUMBNAIL_EXTENSION)
    except IOError as e:
        logger.error(e)
        return HttpResponse()
开发者ID:penyatree,项目名称:seahub,代码行数:33,代码来源:views.py


示例7: repo_online_gc

def repo_online_gc(request, repo_id):
    if request.method != 'POST':
        raise Http404

    repo = get_repo(repo_id)
    if not repo:
        raise Http404

    referer = request.META.get('HTTP_REFERER', None)
    next = settings.SITE_ROOT if referer is None else referer

    username = request.user.username
    if is_org_context(request):
        repo_owner = seafile_api.get_org_repo_owner(repo.id)
    else:
        repo_owner = seafile_api.get_repo_owner(repo.id)
    is_repo_owner = True if repo_owner == username else False
    if not is_repo_owner:
        messages.error(request, _('Permission denied'))
        return HttpResponseRedirect(next)

    day = int(request.POST.get('day'))
    try:
        seafile_api.clean_up_repo_history(repo.id, day)
    except SearpcError as e:
        logger.error(e)
        messages.error(request, _('Internal server error'))
        return HttpResponseRedirect(next)

    return HttpResponseRedirect(next)
开发者ID:domal,项目名称:seahub,代码行数:30,代码来源:__init__.py


示例8: _decorated

    def _decorated(request, *args, **kwargs):
        repo_id = kwargs.get("repo_id", None)
        if not repo_id:
            raise Exception, "Repo id is not found in url."
        repo = get_repo(repo_id)
        if not repo:
            raise Http404
        username = request.user.username
        if repo.encrypted:
            try:
                server_crypto = UserOptions.objects.is_server_crypto(username)
            except CryptoOptionNotSetError:
                return render_to_response("options/set_user_options.html", {}, context_instance=RequestContext(request))

            if (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) and not is_passwd_set(
                repo_id, username
            ):
                return render_to_response(
                    "decrypt_repo_form.html",
                    {"repo": repo, "next": request.get_full_path(), "force_server_crypto": FORCE_SERVER_CRYPTO},
                    context_instance=RequestContext(request),
                )

            if repo.enc_version == 2 and not server_crypto:
                return render_error(request, _(u"Files in this library can not be viewed online."))

        return func(request, *args, **kwargs)
开发者ID:rominf,项目名称:seahub,代码行数:27,代码来源:decorators.py


示例9: post

    def post(self, request, repo_id, format=None):
        repo = get_repo(repo_id)
        if not repo:
            return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
        
        resp = check_repo_access_permission(request, repo)
        if resp:
            return resp

        parent_dir = request.GET.get('p', '/')
        file_names = request.POST.get("file_names")

        if not parent_dir or not file_names:
            return api_error(status.HTTP_404_NOT_FOUND,
                             'File or directory not found.')

        names =  file_names.split(':')
        names = map(lambda x: unquote(x).decode('utf-8'), names)

        for file_name in names:
            try:
                seafserv_threaded_rpc.del_file(repo_id, parent_dir,
                                               file_name, request.user.username)
            except SearpcError,e:
                return api_error(HTTP_520_OPERATION_FAILED,
                                 "Failed to delete file.")
开发者ID:chuyskywalker,项目名称:seahub,代码行数:26,代码来源:views.py


示例10: get

    def get(self, request, repo_id, format=None):
        repo = get_repo(repo_id)
        if not repo:
            return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')

        # check whether user is repo owner
        if validate_owner(request, repo_id):
            owner = "self"
        else:
            owner = "share"

        last_commit = get_commits(repo.id, 0, 1)[0]
        repo.latest_modify = last_commit.ctime if last_commit else None

        # query repo infomation
        repo.size = seafserv_threaded_rpc.server_repo_size(repo_id)
        current_commit = get_commits(repo_id, 0, 1)[0]
        root_id = current_commit.root_id if current_commit else None

        repo_json = {
            "type":"repo",
            "id":repo.id,
            "owner":owner,
            "name":repo.name,
            "desc":repo.desc,
            "mtime":repo.latest_modify,
            "size":repo.size,
            "encrypted":repo.encrypted,
            "root":root_id,
            }

        return Response(repo_json)
开发者ID:viktorlindgren,项目名称:seahub,代码行数:32,代码来源:views.py


示例11: repo_history

def repo_history(request, repo_id):
    """
    List library modification histories.
    """
    user_perm = check_folder_permission(request, repo_id, '/')
    if not user_perm:
        return render_permission_error(request, _(u'Unable to view library modification'))

    repo = get_repo(repo_id)
    if not repo:
        raise Http404

    username = request.user.username
    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

    password_set = False
    if repo.props.encrypted and \
            (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)):
        try:
            ret = seafserv_rpc.is_passwd_set(repo_id, username)
            if ret == 1:
                password_set = True
        except SearpcError, e:
            return render_error(request, e.msg)

        if not password_set:
            return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, '']))
开发者ID:domal,项目名称:seahub,代码行数:31,代码来源:__init__.py


示例12: share_link_latest_entry

def share_link_latest_entry(request, token, size, path):
    fileshare = FileShare.objects.get_valid_file_link_by_token(token)
    if not fileshare:
        return None

    repo_id = fileshare.repo_id
    repo = get_repo(repo_id)
    if not repo:
        return None

    if fileshare.path == '/':
        image_path = path
    else:
        image_path = posixpath.join(fileshare.path, path.lstrip('/'))

    obj_id = get_file_id_by_path(repo_id, image_path)
    if obj_id:
        try:
            thumbnail_file = os.path.join(THUMBNAIL_ROOT, str(size), obj_id)
            last_modified_time = os.path.getmtime(thumbnail_file)
            # convert float to datatime obj
            return datetime.datetime.fromtimestamp(last_modified_time)
        except Exception as e:
            logger.error(e)
            # no thumbnail file exists
            return None
    else:
        return None
开发者ID:AviorAlong,项目名称:haiwen-5.1.3,代码行数:28,代码来源:views.py


示例13: _get_events_inner

    def _get_events_inner(ev_session, username, start, org_id=None):
        '''Read 11 events from seafevents database, and remove events that are
        no longer valid

        '''
        if org_id == None:
            events = seafevents.get_user_events(ev_session, username, start, start + 11)
        else:
            events = seafevents.get_org_user_events(ev_session, \
                                    org_id, username, start, start + 11)
        total = len(events)
        valid_events = []
        for ev in events:
            if ev.etype == 'repo-update':
                repo = get_repo(ev.repo_id)
                if not repo:
                    # delete the update event for repo which has been deleted
                    seafevents.delete_event(ev_session, ev.uuid)
                    continue
                if repo.encrypted:
                    repo.password_set = seafserv_rpc.is_passwd_set(repo.id, username)
                ev.repo = repo
                ev.commit = seafserv_threaded_rpc.get_commit(ev.commit_id)

            valid_events.append(ev)

        return total, valid_events
开发者ID:oculusit,项目名称:seahub,代码行数:27,代码来源:__init__.py


示例14: get

    def get(self, request, repo_id, dir_id):
        repo = get_repo(repo_id)
        resp = check_repo_access_permission(request, repo)
        if resp:
            return resp

        return get_dir_entrys_by_id(request, dir_id)
开发者ID:hilerchyn,项目名称:seahub,代码行数:7,代码来源:views.py


示例15: _get_events_inner

    def _get_events_inner(ev_session, username, start, limit):
        '''Read events from seafevents database, and remove events that are
        no longer valid

        Return 'limit' events or less than 'limit' events if no more events remain
        '''
        valid_events = []
        next_start = start
        while True:
            events = seafevents.get_user_events(ev_session, username,
                                                next_start, limit)
            if not events:
                break

            for ev in events:
                if ev.etype == 'repo-update':
                    repo = get_repo(ev.repo_id)
                    if not repo:
                        # delete the update event for repo which has been deleted
                        seafevents.delete_event(ev_session, ev.uuid)
                        continue
                    if repo.encrypted:
                        repo.password_set = seafserv_rpc.is_passwd_set(repo.id, username)
                    ev.repo = repo
                    ev.commit = seafserv_threaded_rpc.get_commit(repo.id, repo.version, ev.commit_id)

                valid_events.append(ev)
                if len(valid_events) == limit:
                    break

            if len(valid_events) == limit:
                break            
            next_start = next_start + len(valid_events)

        return valid_events
开发者ID:jamjr,项目名称:seahub,代码行数:35,代码来源:__init__.py


示例16: view_shared_file

def view_shared_file(request, token):
    """
    Preview file via shared link.
    """
    assert token is not None    # Checked by URLconf

    try:
        fileshare = FileShare.objects.get(token=token)
    except FileShare.DoesNotExist:
        raise Http404

    shared_by = fileshare.username
    repo_id = fileshare.repo_id
    repo = get_repo(repo_id)
    if not repo:
        raise Http404

    path = fileshare.path.rstrip('/') # Normalize file path 
    obj_id = seafile_api.get_file_id_by_path(repo_id, path)
    if not obj_id:
        return render_error(request, _(u'File does not exist'))
    file_size = seafile_api.get_file_size(obj_id)
    
    filename = os.path.basename(path)
    filetype, fileext = get_file_type_and_ext(filename)
    access_token = seafserv_rpc.web_get_access_token(repo.id, obj_id,
                                                     'view', '')
    raw_path = gen_file_get_url(access_token, filename)
    inner_path = gen_inner_file_get_url(access_token, filename)

    # get file content
    ret_dict = {'err': '', 'file_content': '', 'encoding': '', 'file_enc': '',
                'file_encoding_list': [], 'html_exists': False,
                'filetype': filetype}
    fsize = get_file_size(obj_id)
    exceeds_limit, err_msg = file_size_exceeds_preview_limit(fsize, filetype)
    if exceeds_limit:
        err = err_msg
    else:
        """Choose different approach when dealing with different type of file."""

        if is_textual_file(file_type=filetype):
            handle_textual_file(request, filetype, inner_path, ret_dict)
        elif filetype == DOCUMENT:
            handle_document(inner_path, obj_id, fileext, ret_dict)
        elif filetype == PDF:
            handle_pdf(inner_path, obj_id, fileext, ret_dict)

        # Increase file shared link view_cnt, this operation should be atomic
        fileshare.view_cnt = F('view_cnt') + 1
        fileshare.save()

        # send statistic messages
        if ret_dict['filetype'] != 'Unknown':
            try:
                obj_size = seafserv_threaded_rpc.get_file_size(obj_id)
                send_message('seahub.stats', 'file-view\t%s\t%s\t%s\t%s' % \
                             (repo.id, shared_by, obj_id, obj_size))
            except SearpcError, e:
                logger.error('Error when sending file-view message: %s' % str(e))
开发者ID:datawerk,项目名称:seahub,代码行数:60,代码来源:file.py


示例17: view_file_via_shared_dir

def view_file_via_shared_dir(request, token):
    assert token is not None    # Checked by URLconf

    try:
        fileshare = FileShare.objects.get(token=token)
    except FileShare.DoesNotExist:
        raise Http404

    shared_by = fileshare.username
    repo_id = fileshare.repo_id
    repo = get_repo(repo_id)
    if not repo:
        raise Http404
    
    path = request.GET.get('p', '').rstrip('/')
    if not path:
        raise Http404
    if not path.startswith(fileshare.path): # Can not view upper dir of shared dir
        raise Http404
    zipped = gen_path_link(path, '')

    obj_id = seafile_api.get_file_id_by_path(repo_id, path)
    if not obj_id:
        return render_error(request, _(u'File does not exist'))
    file_size = seafile_api.get_file_size(obj_id)

    filename = os.path.basename(path)
    filetype, fileext = get_file_type_and_ext(filename)
    access_token = seafserv_rpc.web_get_access_token(repo.id, obj_id,
                                                     'view', '')
    raw_path = gen_file_get_url(access_token, filename)
    inner_path = gen_inner_file_get_url(access_token, filename)

    # get file content
    ret_dict = {'err': '', 'file_content': '', 'encoding': '', 'file_enc': '',
                'file_encoding_list': [], 'html_exists': False,
                'filetype': filetype}
    fsize = get_file_size(obj_id)
    exceeds_limit, err_msg = file_size_exceeds_preview_limit(fsize, filetype)
    if exceeds_limit:
        err = err_msg
    else:
        """Choose different approach when dealing with different type of file."""

        if is_textual_file(file_type=filetype):
            handle_textual_file(request, filetype, inner_path, ret_dict)
        elif filetype == DOCUMENT:
            handle_document(inner_path, obj_id, fileext, ret_dict)
        elif filetype == PDF:
            handle_pdf(inner_path, obj_id, fileext, ret_dict)

        # send statistic messages
        try:
            obj_size = seafserv_threaded_rpc.get_file_size(obj_id)
            send_message('seahub.stats', 'file-view\t%s\t%s\t%s\t%s' % \
                         (repo.id, shared_by, obj_id, obj_size))
        except SearpcError, e:
            logger.error('Error when sending file-view message: %s' % str(e))
开发者ID:swpd,项目名称:seahub,代码行数:58,代码来源:file.py


示例18: msg_reply_new

def msg_reply_new(request):
    username = request.user.username
    grpmsg_reply_list = [x for x in UserNotification.objects.get_group_msg_reply_notices(username)]

    msg_ids = []
    for e in grpmsg_reply_list:
        try:
            msg_id = e.grpmsg_reply_detail_to_dict().get("msg_id")
        except UserNotification.InvalidDetailError:
            continue
        msg_ids.append(msg_id)

    group_msgs = []
    for msg_id in msg_ids:
        try:
            m = GroupMessage.objects.get(id=msg_id)
        except GroupMessage.DoesNotExist:
            continue
        else:
            if m in group_msgs:
                continue

            # get group name
            group = get_group(m.group_id)
            if not group:
                continue
            m.group_name = group.group_name

            # get attachements
            attachments = m.messageattachment_set.all()
            for attachment in attachments:
                path = attachment.path
                if path == "/":
                    repo = get_repo(attachment.repo_id)
                    if not repo:
                        continue
                    attachment.name = repo.name
                else:
                    attachment.name = os.path.basename(path)

            m.attachments = attachments

            # get message replies
            reply_list = MessageReply.objects.filter(reply_to=m)
            m.reply_cnt = reply_list.count()
            if m.reply_cnt > 3:
                m.replies = reply_list[m.reply_cnt - 3 :]
            else:
                m.replies = reply_list

            group_msgs.append(m)

    # remove new group msg reply notification
    UserNotification.objects.seen_group_msg_reply_notice(username)

    return render_to_response(
        "group/new_msg_reply.html", {"group_msgs": group_msgs}, context_instance=RequestContext(request)
    )
开发者ID:octomike,项目名称:seahub,代码行数:58,代码来源:views.py


示例19: get_personal_wiki_repo

def get_personal_wiki_repo(username):
    try:
        wiki = PersonalWiki.objects.get(username=username)
    except PersonalWiki.DoesNotExist:
        raise WikiDoesNotExist
    repo = seaserv.get_repo(wiki.repo_id)
    if not repo:
        raise WikiDoesNotExist
    return repo
开发者ID:sebheitzmann,项目名称:seahub,代码行数:9,代码来源:utils.py


示例20: post

    def post(self, request, repo_id, format=None):
        resp = check_repo_access_permission(request, get_repo(repo_id))
        if resp:
            return resp
        op = request.GET.get('op', 'setpassword')
        if op == 'setpassword':
            return Response("success")

        return Response("unsupported operation")
开发者ID:strogo,项目名称:seahub,代码行数:9,代码来源:views.py



注:本文中的seaserv.get_repo函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python seaserv.is_group_user函数代码示例发布时间:2022-05-27
下一篇:
Python seaserv.get_personal_groups_by_user函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap