Beispiel #1
0
    def index(self):
        #stores = etree.Element ('resource', resource_type='stores')
        #for k,v in self.drivers.items():
        #    etree.SubElement(stores, 'store', name = k, resource_unid=k, value=v.top)

        if identity.anonymous():
            return "<resource/>"

        root = self._create_root_mount()
        return etree.tostring(root)
Beispiel #2
0
    def stats(self, **kw):
        log.info('stats %s' % kw)
        wpublic = kw.pop('wpublic', 0)
        anonymous = identity.anonymous()

        def usage_resource():
            log.info("CALL EXPENSIVE")
            all_count = data_service.count("image",
                                           wpublic=wpublic,
                                           images2d=True,
                                           parent=False)
            image_count = data_service.count("image",
                                             wpublic=wpublic,
                                             permcheck=not anonymous)
            #images2d = data_service.count("image", wpublic=wpublic, images2d=True)
            tag_count = data_service.count("tag",
                                           wpublic=wpublic,
                                           permcheck=not anonymous,
                                           parent=False)
            gob_count = data_service.count("gobject",
                                           wpublic=wpublic,
                                           permcheck=not anonymous,
                                           parent=False)

            resource = etree.Element('resource', uri='/usage/stats')
            etree.SubElement(resource,
                             'tag',
                             name='number_images',
                             value=str(all_count))
            etree.SubElement(resource,
                             'tag',
                             name='number_images_user',
                             value=str(image_count))
            #etree.SubElement(resource, 'tag', name='number_images_planes', value=str(images2d))
            etree.SubElement(resource,
                             'tag',
                             name='number_tags',
                             value=str(tag_count))
            etree.SubElement(resource,
                             'tag',
                             name='number_gobs',
                             value=str(gob_count))

            return etree.tostring(resource)

        usage_cache = cache.get_cache("usage")
        resource = usage_cache.get_value(key=identity.get_username(),
                                         createfunc=usage_resource,
                                         expiretime=3600)
        return resource
Beispiel #3
0
    def _default(self, *path, **kw):
        """ Dispatch based on request method GET, ...
        """

        # Ignore silently anonymous requests (no looking at files when not logged in)
        if identity.anonymous():
            return "<resource/>"

        # hmm some path elements arrive %encoded and utf8..  convert back to simple unicode
        path = [url2unicode(x) for x in path]
        method = tg.request.method
        if method == 'GET':
            return self._get(list(path), **kw)
        elif method in ('POST', 'PUT'):
            return self._post(list(path), **kw)
        elif method == 'DELETE':
            return self._delete(list(path), **kw)
        abort(400)
Beispiel #4
0
    def savefile(self, **kw):
        log.info("savefile request " + str(tg.request))
        username = get_username()
        # check the user identity here and return 401 if fails
        if anonymous():
            response.status_int = 401
            log.debug('Access denied')
            return 'Access denied'

        # if requested test for uploaded
        hashes_str = kw.pop('hashes', None)
        if hashes_str != None:
            all_hashes = [fhash.strip() for fhash in hashes_str.split(',')]
            #for fhash in hashes_str.split(','):
            #    all_hashes.append( fhash )
            #found_hashes = blob_service.files_exist(all_hashes) TODO
            found_hashes = []
            found_html = ",".join([str(h) for h in found_hashes])
            return "Found: " + found_html

        # here user is authenticated - upload
        if not 'upload' in kw:
            response.status_int = 501
            return "No file to be uploaded..."
        upload = kw['upload']
        uploadroot = config.get('bisque.image_service.upload_dir',
                                data_path('uploads'))
        upload_dir = uploadroot + '/' + str(username)
        _mkdir(upload_dir)
        if not upload.filename:
            return 'No file sent...'
        #patch for no copy file uploads - check for regular file or file like object
        uploadpath = upload_dir + '/' + upload.filename
        #KGK: note upload.file.name is not available for some uploads (attached files)
        #abs_path_src = os.path.abspath(upload.file.name)
        #if os.path.isfile(abs_path_src):
        #    shutil.move(abs_path_src, uploadpath)
        #else:
        with open(uploadpath, 'wb') as trg:
            shutil.copyfileobj(upload.file, trg)

        return 'Upload done for: ' + upload.filename