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


Python client.get_container函数代码示例

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


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


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