Exemple #1
0
    def __init__(self, uniq, resource, path, **kw):
        """ Returns table information """
        super(TableExcel, self).__init__(uniq, resource, path, **kw)

        if self.t is None:
            # try to load the resource binary
            b = blob_service.localpath(uniq, resource=resource) or abort (404, 'File not available from blob service')
            self.filename = b.path
            self.info()
Exemple #2
0
    def __init__(self, uniq, resource, path, **kw):
        super(PipelineDream3D, self).__init__(uniq, resource, path, **kw)

        # try to load the resource binary
        b = blob_service.localpath(uniq, resource=resource) or abort (404, 'File not available from blob service')
        self.filename = b.path
        self.data = {}
        raw_pipeline = '{}'
        with open(self.filename, 'r') as pipeline_file:
            self.data = dream3d_to_json(pipeline_file)
Exemple #3
0
 def get_blobs(self, blocking=True):
     self.validate()
     if self.files is not None:
         # dima: do file existence check here
         # re-request blob service if unavailable
         #log.debug('%s blob from cache'%self.uniq)
         return self.files
     self.get_resource()
     self.files = blob_service.localpath(self.uniq, resource=self.resource, blocking=blocking)
     self.ts_files = datetime.now()
     return self.files
Exemple #4
0
    def __init__(self, uniq, resource, path, **kw):
        """ Returns table information """
        super(TableHDF, self).__init__(uniq, resource, path, **kw)

        if self.t is None:
            # try to load the resource binary
            b = blob_service.localpath(uniq, resource=resource) or abort (404, 'File not available from blob service')
            self.filename = b.path
            try:
                self.info()
            except Exception:
                # close any open table
                if self.t is not None:
                    self.t.close()
                raise
Exemple #5
0
    def __init__(self, uniq, resource, path, **kw):
        super(PipelineIJ, self).__init__(uniq, resource, path, **kw)

        # allow to initialize with JSON directly
        self.filename = None
        self.data = kw.get('data', None)
        if self.data:
            return

        # try to load the resource binary
        b = blob_service.localpath(uniq, resource=resource) or abort(
            404, 'File not available from blob service')
        self.filename = b.path
        self.data = {}
        raw_pipeline = []
        with open(self.filename, 'r') as pipeline_file:
            self.data = imagej_to_json(pipeline_file)
Exemple #6
0
        def fileInfo(relpath, uri, index=0):
            xml = data_service.get_resource(uri, view='deep,clean')
            if xml is None:
                log.warn('skipping unreadable uri %s', uri)
                return None

            name = xml.get('name')
            uniq = xml.get('resource_uniq', None)

            # try to figure out a name for the resource
            if not name:
                name = xml.xpath('./tag[@name="filename"]') or xml.xpath(
                    './tag[@name="name"]')
                name = name and name[0].get('value')
            if not name and uniq:
                name = uniq[-4]
            if not name:
                name = str(index)

            path = None
            files = None
            if uniq is not None:
                #del xml.attrib['resource_uniq'] # dima: strip resource_uniq from exported xml
                b = blob_service.localpath(uniq)
                if b:
                    files = b.files
                    if files is not None and len(files) > 0:
                        path = files[0]
                    else:
                        path = b.path
                    if path and not os.path.exists(path):
                        path = None
                else:
                    log.warn("Resource %s ( %s ) did not have blob", uniq,
                             xml.tag)

            # if resource is just an XML doc
            content = None
            if path is None:
                content = etree.tostring(xml)
                name = '%s_%s' % (name, uniq)
                xml = None

            # disambiguate file name if present
            ext = '' if path is not None else '.xml'
            outpath = os.path.join(relpath,
                                   '%s%s' % (name, ext)).replace('\\', '/')
            if outpath in fileHash:
                fname, ext = os.path.splitext(name)
                name = '%s%s%s' % (fname, uniq, ext)
                outpath = os.path.join(relpath, '%s%s' % (name, ext)).replace(
                    '\\', '/')
            fileHash[outpath] = name

            if files is None or len(files) < 2:
                return [{
                    'xml': xml,
                    'content': content,
                    'name': name,
                    'uniq': uniq,
                    'path': path,
                    'relpath': relpath,
                    'outpath': outpath,
                }]

            log.debug('fileInfo name: %s, path: %s, relpath: %s, outpath: %s',
                      name, path, relpath, outpath)
            log.debug('fileInfo files: %s', files)

            # find minimum relative path
            min_length = sys.maxint
            for f in files:
                min_length = min(min_length, len(os.path.dirname(f)))
            minpath = files[0][:min_length + 1]
            log.debug('fileInfo minpath: %s', minpath)

            # check if file disimbiguation is needed
            subpath = files[0][min_length + 1:]
            outpath = os.path.join(relpath, name, subpath).replace('\\', '/')
            if outpath in fileHash:
                name = '%s.%s' % (name, uniq)
                outpath = os.path.join(relpath, name,
                                       subpath).replace('\\', '/')
            fileHash[outpath] = name

            infos = []
            first = True
            for f in files:
                subpath = f[min_length + 1:]
                info = {
                    'name':
                    os.path.basename(f),
                    'uniq':
                    uniq,
                    'path':
                    f,
                    'relpath':
                    relpath,
                    'outpath':
                    os.path.join(relpath, name, subpath).replace('\\', '/'),
                    'subpath':
                    subpath.replace('\\', '/'),
                }
                if first is True:
                    first = False
                    info['xml'] = xml
                    info['content'] = content
                infos.append(info)

            log.debug('fileInfo infos: %s', infos)
            return infos