def icon(self, value): if value: return value if 'package' in self['type']: return ad.PropertyMeta( url='/static/images/package.png', path=join(static.PATH, 'images', 'package.png'), mime_type='image/png') else: return ad.PropertyMeta( url='/static/images/missing.png', path=join(static.PATH, 'images', 'missing.png'), mime_type='image/png')
def _get_prop(self, request, response): guid = request.path[1] prop = request.path[2] if prop == 'preview': return ad.PropertyMeta(path=_prop_path(guid, prop), mime_type='image/png') elif prop == 'data': return ad.PropertyMeta(path=_ds_path(guid, 'data'), mime_type=get(guid, 'mime_type') or 'application/octet') else: response.content_type = 'application/json' return get(guid, prop)
def preview(self, value): if value: return value return ad.PropertyMeta( url='/static/images/missing.png', path=join(static.PATH, 'images', 'missing.png'), mime_type='image/png')
def artifact_icon(self, value): if value: return value return ad.PropertyMeta( url='/static/images/missing.svg', path=join(static.PATH, 'images', 'missing.svg'), mime_type='image/svg+xml')
def packages(self, request, response): response.content_type = 'application/json' if len(request.path) <= 3: path = join(obs.obs_presolve_path.value, *request.path[1:]) return os.listdir(path) elif len(request.path) == 4: path = join(obs.obs_presolve_path.value, *request.path[1:]) return ad.PropertyMeta(path=path, filename=request.path[-1], mime_type='application/json') else: raise RuntimeError('Incorrect path')
def call(self, request, response): if 'HTTP_ORIGIN' in request.environ: enforce(self._assert_origin(request.environ), ad.Forbidden, 'Cross-site is not allowed for %r origin', request.environ['HTTP_ORIGIN']) response['Access-Control-Allow-Origin'] = \ request.environ['HTTP_ORIGIN'] if request['method'] == 'OPTIONS': # TODO Process OPTIONS request per url? if request.environ['HTTP_ORIGIN']: response['Access-Control-Allow-Methods'] = \ request.environ['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] response['Access-Control-Allow-Headers'] = \ request.environ['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'] else: response['Allow'] = 'GET, POST, PUT, DELETE' response.content_length = 0 return None request.principal = self.authenticate(request) if request.path[:1] == ['static']: path = join(static.PATH, *request.path[1:]) result = ad.PropertyMeta(path=path, mime_type=_get_mime_type(path), filename=split(path)[-1]) else: rout = self._routes.get( (request['method'], request.path[0] if request.path else '')) if rout: result = rout(request, response) else: result = self.commands.call(request, response) if isinstance(result, ad.PropertyMeta): if 'url' in result: raise Redirect(result['url']) path = result['path'] enforce(isfile(path), 'No such file') mtime = result.get('mtime') or os.stat(path).st_mtime if request.if_modified_since and mtime and \ mtime <= request.if_modified_since: raise NotModified() response.last_modified = mtime response.content_type = result.get('mime_type') or \ 'application/octet-stream' filename = result.get('filename') if not filename: filename = _filename( result.get('name') or splitext(split(path)[-1])[0], response.content_type) response['Content-Disposition'] = \ 'attachment; filename="%s"' % filename result = file(path, 'rb') if hasattr(result, 'read'): if hasattr(result, 'fileno'): response.content_length = os.fstat(result.fileno()).st_size elif hasattr(result, 'seek'): result.seek(0, 2) response.content_length = result.tell() result.seek(0) result = stream_reader(result) return result
def favicon(self, request, response): return ad.PropertyMeta(path=join(static.PATH, 'favicon.ico'), mime_type='image/x-icon')