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

Python client.get_container函数代码示例

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

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



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

示例1: create_container

def create_container(request):
    """ Creates a container (empty object of type application/directory) """

    storage_url = request.session.get("storage_url", "")
    auth_token = request.session.get("auth_token", "")

    headers = {
        "X-Container-Meta-Access-Control-Expose-Headers": "Access-Control-Allow-Origin",
        "X-Container-Meta-Access-Control-Allow-Origin": settings.BASE_URL,
    }

    form = CreateContainerForm(request.POST or None)
    if form.is_valid():
        container = form.cleaned_data["containername"]

        # Check container does not already exist
        try:
            client.get_container(storage_url, auth_token, container)
            messages.add_message(request, messages.ERROR, _("Container {0} already exists.".format(container)))
        except:
            try:
                client.put_container(storage_url, auth_token, container, headers)
                messages.add_message(request, messages.INFO, _("Container created."))
            except client.ClientException:
                messages.add_message(request, messages.ERROR, _("Access denied."))

        return redirect(containerview)

    return render_to_response(
        "create_container.html", {"session": request.session}, context_instance=RequestContext(request)
    )
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:31,代码来源:containers.py


示例2: _get_total_objects

def _get_total_objects(request, container, objectname):
    """ Return the total number of objects under a pseudofolder. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')
    prefix = request.session.get('prefix')

    if prefix:
        prefix += objectname
    else:
        prefix = objectname

    try:
        if prefix:
            meta, objects = client.get_container(
                storage_url, auth_token, container,
                prefix=prefix, full_listing=True,
                headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')})

        else:
            meta, objects = client.get_container(
                storage_url, auth_token, container,
                headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')},
                full_listing=True)

    except client.ClientException:
        return 0

    pseudofolders, objs = pseudofolder_object_list(objects, prefix)

    return len(objs)
开发者ID:bkawula,项目名称:django-swiftbrowser,代码行数:31,代码来源:__init__.py


示例3: delete_given_folder

def delete_given_folder(request, container, foldername):
    """ Recursively delete all the objects in the given folder and then
    delete the folder itself. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    # Get all objects within folder.
    meta, objects = client.get_container(
        storage_url, auth_token, container,
        headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')},
        delimiter='/', prefix=foldername)

    # Recursive call to delete subfolders.
    pseudofolders, objs = pseudofolder_object_list(objects, foldername)
    for folder in pseudofolders:
        delete_given_folder(request, container, folder[0])

    # Delete all objects.
    for obj in objs:
        delete_given_object(request, container, obj["name"])

    # Delete the folder itself.
    try:
        client.get_object(
            storage_url, auth_token, container, foldername,
            headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')})
        delete_given_object(request, container, foldername)
    except:
        # If folder does not exist, pass
        pass
开发者ID:bkawula,项目名称:django-swiftbrowser,代码行数:31,代码来源:__init__.py


示例4: objectview

def objectview(request, container, prefix=None):
    """ Returns list of all objects in current container. """

    storage_url = get_endpoint(request, 'adminURL')
    public_url = get_endpoint(request, 'publicURL') + '/' + container
    auth_token = get_token_id(request)
    http_conn = client.http_connection(storage_url,
                                       insecure=settings.SWIFT_INSECURE)

    page = request.GET.get('page', 1)

    try:
        _, objects = client.get_container(storage_url, auth_token,
                                             container, delimiter='/',
                                             prefix=prefix,
                                             http_conn=http_conn)
    except client.ClientException as err:
        log.exception('{}{}'.format(ugettext('Exception:').encode('UTF-8'), err))
        messages.add_message(request, messages.ERROR, ugettext('Access denied.'))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    object_list = pseudofolder_object_list(objects, prefix, public_url)
    context = utils.update_default_context(request, {
        'container': container,
        'objects': utils.generic_pagination(object_list, page),
        'prefix': prefix,
        'prefixes': prefixes,
    })

    return render_to_response("objectview.html", context,
                              context_instance=RequestContext(request))
开发者ID:globocom,项目名称:vault,代码行数:32,代码来源:views.py


示例5: delete_container

def delete_container(request, container, force=True):
    """
    Deletes a container. If force is True, it will deletes all objects first.
    """

    storage_url = get_endpoint(request, 'adminURL')
    auth_token = get_token_id(request)
    http_conn = client.http_connection(storage_url,
                                       insecure=settings.SWIFT_INSECURE)

    if force:
        try:
            _, objects = client.get_container(storage_url,
                                           auth_token,
                                           container,
                                           http_conn=http_conn)

        except client.ClientException as err:
            log.exception('{}{}'.format(ugettext('Exception:').encode('UTF-8'), err))
            return False

        for obj in objects:
            delete_object(request=request,
                          container=container,
                          objectname=obj['name'])

    try:
        client.delete_container(storage_url, auth_token,
                                container, http_conn=http_conn)
        actionlog.log(request.user.username, "delete", container)
    except client.ClientException as err:
        log.exception('{}{}'.format(ugettext('Exception:').encode('UTF-8'), err))
        return False

    return True
开发者ID:globocom,项目名称:vault,代码行数:35,代码来源:views.py


示例6: list_container

    def list_container(self,container_name,prefix=None,delimiter=None):

        try:
            return client.get_container(self.storage_url,self.token,container_name,prefix=prefix,delimiter=delimiter,http_conn=self.http_conn)

        except:
            return None
开发者ID:flyz1360,项目名称:ThuCloudDisk,代码行数:7,代码来源:swift.py


示例7: public_objectview

def public_objectview(request, account, container, prefix=None):
    """ Returns list of all objects in current container. """
    storage_url = settings.STORAGE_URL + account
    auth_token = ' '
    try:
        _meta, objects = client.get_container(
            storage_url, auth_token, container, delimiter='/', prefix=prefix)

    except client.ClientException:
        traceback.print_exc()
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split('/')[-1]

    return render_to_response("publicview.html", {
        'container': container,
        'objects': objs,
        'folders': pseudofolders,
        'prefix': prefix,
        'prefixes': prefixes,
        'base_url': base_url,
        'storage_url': storage_url,
        'account': account},
        context_instance=RequestContext(request))
开发者ID:unibg-seclab,项目名称:django-swiftbrowser,代码行数:28,代码来源:views.py


示例8: getMemberNames

    def getMemberNames(self):
        _stat, objects = client.get_container(self.storage_url,
                                              self.auth_token,
                                              container=self.container,
                                              delimiter='/',
                                              prefix=self.prefix,
                                              http_conn=self.http_connection)

        self.objects = {}

        childs = []
        for obj in objects:
            name = obj.get('name')
            if name and name != self.prefix:
                name = name.encode("utf8")
                childs.append(name)
                self.objects[name] = obj
            subdir = obj.get('subdir')
            if subdir and subdir != self.prefix:
                subdir = subdir.rstrip('/')
                subdir = subdir.encode("utf8")
                # there might be two entries:
                # 1. object with type application/directory and no trailing '/'
                # 2. subdir entry with trailing '/'
                if subdir not in childs:
                    childs.append(subdir)
                    self.objects[subdir] = obj
        return childs
开发者ID:cschwede,项目名称:swiftdav,代码行数:28,代码来源:swiftdav.py


示例9: test_create_swift_client

 def test_create_swift_client(self):
     mock_resp = mock(dict)
     when(swiftclient.client.Connection).get_container("bob").thenReturn(["text", mock_resp])
     client = remote.create_swift_client(TroveContext(tenant="123"))
     headers, container = client.get_container("bob")
     self.assertIs(headers, "text")
     self.assertIs(container, mock_resp)
开发者ID:zhujzhuo,项目名称:trove-1.0.10.4,代码行数:7,代码来源:test_remote.py


示例10: get_object_table

def get_object_table(request):
    """ Returns json object of all objects in current container. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')
    container = request.session.get('container')
    prefix = request.session.get('prefix')

    try:
        meta, objects = client.get_container(
            storage_url, auth_token, container, delimiter='/', prefix=prefix,
            headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')})

    except client.ClientException:
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    pseudofolders, objs = pseudofolder_object_list(objects, prefix)

    # Check for incomplete SLO uploads. The object table will display them
    # allowing the user to continue uploading or delete them.
    incomplete_slo = check_incomplete_slo(
        request, storage_url, auth_token, container, prefix)

    return JsonResponse({
        'success': True,
        "data": {
            'container': container,
            'objects': objs,
            'folders': pseudofolders,
            'folder_prefix': prefix,
            'incomplete_slo': incomplete_slo
        }
    })
开发者ID:bkawula,项目名称:django-swiftbrowser,代码行数:34,代码来源:objects.py


示例11: get_all

def get_all(request, container):
    """ Returns List of all Objects present in specified container
    :param container: Name of Swift Container
    :return: meta data and id's of all the objects
    """
    try:
        response_dict = dict()
        storage_url, auth_token = _get_auth_data(request.session)
        data_container = client.get_container(storage_url, auth_token, container)
        for obj in data_container[1]:
            meta_object = client.head_object(storage_url, auth_token, container, obj['name'])
            if not meta_object['x-object-meta-deleted']:
                if meta_object['x-object-meta-type'] in ['thumbnail', 'original-thumbnail']:
                    if meta_object['x-object-meta-format'] not in response_dict:
                        form = meta_object['x-object-meta-format']
                        response_dict[form] = []
                    if meta_object['x-object-meta-format'] in response_dict:
                        new_obj = {'thumbnail_id': obj['name'],
                                   'name': meta_object['x-object-meta-name'],
                                   'type': meta_object['x-object-meta-type'],
                                   'resolution': meta_object['x-object-meta-resolution']}
                        if meta_object['x-object-meta-format'] is 'thumbnail':
                            new_obj['original_id'] = meta_object['x-object-meta-original']
                        response_dict[form].append(new_obj)
        return Response(response_dict)
    except swift_exception.ClientException as e:
        print e
        return Response('Please contact your admininstrator', status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    except Exception as e:
        print e
        return Response('Please contact your admininstrator', status=status.HTTP_500_INTERNAL_SERVER_ERROR)
开发者ID:InBetween,项目名称:AssetManager,代码行数:31,代码来源:views.py


示例12: get_object_table

def get_object_table(request):
    """ Returns json object of all objects in current container. """

    storage_url = request.session.get("storage_url", "")
    auth_token = request.session.get("auth_token", "")
    container = request.session.get("container")
    prefix = request.session.get("prefix")

    try:
        meta, objects = client.get_container(storage_url, auth_token, container, delimiter="/", prefix=prefix)

    except client.ClientException:
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split("/")[-1]

    return JsonResponse(
        {
            "success": True,
            "data": {"container": container, "objects": objs, "folders": pseudofolders, "folder_prefix": prefix},
        }
    )
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:26,代码来源:objects.py


示例13: subdir_proc

def subdir_proc(storage_url, token, container, subdir=None, nest=0):
    #print "DEBUG %s" % subdir
    (c_headers, objects) = get_container(storage_url, token,
                                         container,
                                         prefix=subdir,
                                         delimiter='/')
    spacer = ' ' * ((nest + 1) * 2)
    for obj in objects:
        if 'subdir' in obj:
            sdir_name = obj['subdir']
            l = len(sdir_name)
            idx = sdir_name.rfind('/', 0, l - 1)
            if idx >= 0:
                sdir_name = sdir_name[idx + 1:]
            print "%-30s" % (spacer + sdir_name)
            if subdir is None:
                new_subdir = obj['subdir']
            else:
                new_subdir = obj['subdir']
            subdir_proc(storage_url, token, container, new_subdir, nest + 1)
        else:
            if subdir is None:
                l = 0
            else:
                l = len(subdir)
            objname = obj['name'][l:]
            print "%-30s  %20s bytes" % (spacer + objname, obj['bytes'])
开发者ID:yoyama,项目名称:swift_book,代码行数:27,代码来源:swift_subfolder.py


示例14: public_objectview

def public_objectview(request, account, container, prefix=None):
    """ Returns list of all objects in current container. """
    storage_url = settings.STORAGE_URL + account
    auth_token = " "
    try:
        _meta, objects = client.get_container(storage_url, auth_token, container, delimiter="/", prefix=prefix)

    except client.ClientException:
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split("/")[-1]

    return render_to_response(
        "publicview.html",
        {
            "container": container,
            "objects": objs,
            "folders": pseudofolders,
            "prefix": prefix,
            "prefixes": prefixes,
            "base_url": base_url,
            "storage_url": storage_url,
            "account": account,
        },
        context_instance=RequestContext(request),
    )
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:30,代码来源:objects.py


示例15: list

 def list(self):
     swift_objects = []
     for cont in self.list_containers():
         objs = [{'container': cont, 'name': obj['name']} for obj in
                 swift_client.get_container(self.endpoint, self.token, cont)[1]]
         swift_objects.extend(objs)
     return swift_objects
开发者ID:carriercomm,项目名称:ospurge,代码行数:7,代码来源:ospurge.py


示例16: delete_given_folder

def delete_given_folder(request, container, foldername):

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    # Get all objects within folder.
    meta, objects = client.get_container(
        storage_url, auth_token, container, delimiter='/', prefix=foldername)

    # Recursive call to delete subfolders.
    pseudofolders, objs = pseudofolder_object_list(objects, foldername)
    for folder in pseudofolders:
        delete_given_folder(request, container, folder[0])

    # Delete all objects.
    for obj in objs:
        delete_given_object(request, container, obj["name"])

    # Delete the folder itself.
    try:
        delete_given_object(request, container, foldername)
    except:
        #Except a failure to delete if the pseudo folder was not created
        #manually.
        pass
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:25,代码来源:utils.py


示例17: get_temp_key

def get_temp_key(storage_url, auth_token, container):
    """ Tries to get meta-temp-url key from account.
    If not set, generate tempurl and save it to acocunt.
    This requires at least account owner rights. """

    try:
        account = client.get_account(storage_url, auth_token)
    except client.ClientException:

        #Try to get the container temp url key instead
        try:
            container = client.get_container(
                storage_url, auth_token, container)
            return container[0].get('x-container-meta-temp-url-key')
        except client.ClientException:
            return None
        return None

    key = account[0].get('x-account-meta-temp-url-key')

    if not key:
        chars = string.ascii_lowercase + string.digits
        key = ''.join(random.choice(chars) for x in range(32))
        headers = {'x-account-meta-temp-url-key': key}
        try:
            client.post_account(storage_url, auth_token, headers)
        except client.ClientException:
            return None
    return key
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:29,代码来源:utils.py


示例18: delete_data

 def delete_data(self, context, container_name):
     url = self._get_endpoint_url(context)
     token = context.auth_token
     try:
         headers, info = swift_client.get_container(
             url, token, container_name
         )
         for obj in info:
             try:
                 swift_client.delete_object(
                     url, token, container_name, obj['name']
                 )
             except swift_exceptions.ClientException as e:
                 LOG.error(e)
                 if e.http_status != 404:
                     raise
         swift_client.delete_container(url, token, container_name)
     except swift_exceptions.ClientException as e:
         LOG.error(e)
         if e.http_status == 404:
             raise exception.ContainerNotExists(
                 container_name=container_name
             )
         else:
             raise exception.ContainerDeletionError(
                 container_name=container_name
             )
开发者ID:accelazh,项目名称:magnetodb,代码行数:27,代码来源:api.py


示例19: get_segment_number

def get_segment_number(file_name, request, container, prefix=None):
    '''Return the segment number a given file should create next. If it is 0,
    create a pseudo folder for the file. The folder is created if it doesn't
    exist. '''

    if prefix:
        foldername = prefix + '/' + file_name + '_segments'
    else:
        foldername = file_name + '_segments'

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    foldername = os.path.normpath(foldername)
    foldername = foldername.strip('/')
    foldername += '/'

    content_type = 'application/directory'
    obj = None

    client.put_object(storage_url, auth_token, container, foldername, obj,
                      content_type=content_type)

    meta, objects = client.get_container(storage_url, auth_token, container,
                                         delimiter='/', prefix=foldername)

    pseudofolders, objs = pseudofolder_object_list(objects, prefix)

    return get_first_nonconsecutive(objs)
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:29,代码来源:slo.py


示例20: object_versioning

def object_versioning(request, container, prefix=None):
    storage_url = get_endpoint(request, 'adminURL')
    auth_token = get_token_id(request)
    public_url = get_endpoint(request, 'publicURL') + '/' + container
    http_conn = client.http_connection(storage_url,
                                       insecure=settings.SWIFT_INSECURE)

    objects = []

    page = request.GET.get('page', 1)

    if request.method == 'GET':
        headers = client.head_container(storage_url,
                                auth_token,
                                container,
                                http_conn=http_conn)

        version_location = headers.get('x-versions-location', None)

        if version_location:
            try:
                _, objects = client.get_container(storage_url,
                                                  auth_token,
                                                  version_location,
                                                  prefix=prefix,
                                                  delimiter='/',
                                                  http_conn=http_conn)
            except client.ClientException:
                pass

        prefixes = prefix_list(prefix)
        object_list = pseudofolder_object_list(objects, prefix, public_url)

        context = utils.update_default_context(request, {
            'container': container,
            'objects': utils.generic_pagination(object_list, page),
            'version_location': version_location,
            'prefix': prefix,
            'prefixes': prefixes,
        })

        return render_to_response('container_versioning.html',
                                  dictionary=context,
                                  context_instance=RequestContext(request))

    if request.method == 'POST':

        action = request.POST.get('action', None)

        if action == 'enable':
            enable_versioning(request, container)
            actionlog.log(request.user.username, "enable", 'Versioning. Container: %s' % container)
        elif action == 'disable':
            disable_versioning(request, container)
            actionlog.log(request.user.username, "disable", 'Versioning. Container: %s' % container)
        else:
            messages.add_message(request, messages.ERROR, ugettext('Action is required.'))

        return redirect(object_versioning, container=container)
开发者ID:globocom,项目名称:vault,代码行数:59,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python client.get_object函数代码示例发布时间:2022-05-27
下一篇:
Python client.get_auth函数代码示例发布时间: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