当前位置: 首页>>代码示例>>Python>>正文


Python seaserv.get_repo函数代码示例

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


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


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