From 12e68f7b18a44c0ac7dfee74a53327efbd7f180a Mon Sep 17 00:00:00 2001 From: Matthew Letter Date: Mon, 7 Dec 2015 08:48:07 -0700 Subject: [PATCH] un did this change so plugin will work until its fixed #174 --- packages/slycat/web/server/engine.py | 2 +- packages/slycat/web/server/handlers.py | 114 ++++++++++++------------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/packages/slycat/web/server/engine.py b/packages/slycat/web/server/engine.py index 2e69a6cc1..06d718081 100644 --- a/packages/slycat/web/server/engine.py +++ b/packages/slycat/web/server/engine.py @@ -83,7 +83,7 @@ def abspath(path): dispatcher.connect("get-configuration-version", "/configuration/version", slycat.web.server.handlers.get_configuration_version, conditions={"method" : ["GET"]}) dispatcher.connect("get-configuration-wizards", "/configuration/wizards", slycat.web.server.handlers.get_configuration_wizards, conditions={"method" : ["GET"]}) dispatcher.connect("get-global-resource", "/resources/global/{resource:.*}", slycat.web.server.handlers.get_global_resource, conditions={"method" : ["GET"]}) - #dispatcher.connect("get-model-array-attribute-chunk", "/models/:mid/arraysets/:aid/arrays/:array/attributes/:attribute/chunk", slycat.web.server.handlers.get_model_array_attribute_chunk, conditions={"method" : ["GET"]}) + dispatcher.connect("get-model-array-attribute-chunk", "/models/:mid/arraysets/:aid/arrays/:array/attributes/:attribute/chunk", slycat.web.server.handlers.get_model_array_attribute_chunk, conditions={"method" : ["GET"]}) dispatcher.connect("get-model-arrayset-data", "/models/:mid/arraysets/:aid/data", slycat.web.server.handlers.get_model_arrayset_data, conditions={"method" : ["GET"]}) dispatcher.connect("get-model-arrayset-metadata", "/models/:mid/arraysets/:aid/metadata", slycat.web.server.handlers.get_model_arrayset_metadata, conditions={"method" : ["GET"]}) dispatcher.connect("get-model-file", "/models/:mid/files/:aid", slycat.web.server.handlers.get_model_file, conditions={"method" : ["GET"]}) diff --git a/packages/slycat/web/server/handlers.py b/packages/slycat/web/server/handlers.py index d3a0698bf..9cbddc390 100644 --- a/packages/slycat/web/server/handlers.py +++ b/packages/slycat/web/server/handlers.py @@ -843,63 +843,63 @@ def delete_project_cache_object(pid, key): slycat.email.send_error("slycat.web.server.handlers.py delete_project_cache_object", "cherrypy.HTTPError 404") raise cherrypy.HTTPError(404) -# def get_model_array_attribute_chunk(mid, aid, array, attribute, **arguments): -# try: -# attribute = int(attribute) -# except: -# raise cherrypy.HTTPError("400 Malformed attribute argument must be a zero-based integer attribute index.") -# -# try: -# ranges = [int(spec) for spec in arguments["ranges"].split(",")] -# i = iter(ranges) -# ranges = list(itertools.izip(i, i)) -# except: -# raise cherrypy.HTTPError("400 Malformed ranges argument must be a comma separated collection of half-open index ranges.") -# -# byteorder = arguments.get("byteorder", None) -# if byteorder is not None: -# if byteorder not in ["little", "big"]: -# raise cherrypy.HTTPError("400 Malformed byteorder argument must be 'little' or 'big'.") -# accept = cherrypy.lib.cptools.accept(["application/octet-stream"]) -# else: -# accept = cherrypy.lib.cptools.accept(["application/json"]) -# cherrypy.response.headers["content-type"] = accept -# -# database = slycat.web.server.database.couchdb.connect() -# model = database.get("model", mid) -# project = database.get("project", model["project"]) -# slycat.web.server.authentication.require_project_reader(project) -# -# artifact = model.get("artifact:%s" % aid, None) -# if artifact is None: -# raise cherrypy.HTTPError(404) -# artifact_type = model["artifact-types"][aid] -# if artifact_type not in ["hdf5"]: -# raise cherrypy.HTTPError("400 %s is not an array artifact." % aid) -# -# with slycat.web.server.hdf5.lock: -# with slycat.web.server.hdf5.open(artifact) as file: -# hdf5_arrayset = slycat.hdf5.ArraySet(file) -# hdf5_array = hdf5_arrayset[array] -# -# if not(0 <= attribute and attribute < len(hdf5_array.attributes)): -# raise cherrypy.HTTPError("400 Attribute argument out-of-range.") -# if len(ranges) != hdf5_array.ndim: -# raise cherrypy.HTTPError("400 Ranges argument doesn't contain the correct number of dimensions.") -# -# ranges = [(max(dimension["begin"], range[0]), min(dimension["end"], range[1])) for dimension, range in zip(hdf5_array.dimensions, ranges)] -# index = tuple([slice(begin, end) for begin, end in ranges]) -# -# attribute_type = hdf5_array.attributes[attribute]["type"] -# data = hdf5_array.get_data(attribute)[index] -# -# if byteorder is None: -# return json.dumps(data.tolist()) -# else: -# if sys.byteorder != byteorder: -# return data.byteswap().tostring(order="C") -# else: -# return data.tostring(order="C") +def get_model_array_attribute_chunk(mid, aid, array, attribute, **arguments): + try: + attribute = int(attribute) + except: + raise cherrypy.HTTPError("400 Malformed attribute argument must be a zero-based integer attribute index.") + + try: + ranges = [int(spec) for spec in arguments["ranges"].split(",")] + i = iter(ranges) + ranges = list(itertools.izip(i, i)) + except: + raise cherrypy.HTTPError("400 Malformed ranges argument must be a comma separated collection of half-open index ranges.") + + byteorder = arguments.get("byteorder", None) + if byteorder is not None: + if byteorder not in ["little", "big"]: + raise cherrypy.HTTPError("400 Malformed byteorder argument must be 'little' or 'big'.") + accept = cherrypy.lib.cptools.accept(["application/octet-stream"]) + else: + accept = cherrypy.lib.cptools.accept(["application/json"]) + cherrypy.response.headers["content-type"] = accept + + database = slycat.web.server.database.couchdb.connect() + model = database.get("model", mid) + project = database.get("project", model["project"]) + slycat.web.server.authentication.require_project_reader(project) + + artifact = model.get("artifact:%s" % aid, None) + if artifact is None: + raise cherrypy.HTTPError(404) + artifact_type = model["artifact-types"][aid] + if artifact_type not in ["hdf5"]: + raise cherrypy.HTTPError("400 %s is not an array artifact." % aid) + + with slycat.web.server.hdf5.lock: + with slycat.web.server.hdf5.open(artifact) as file: + hdf5_arrayset = slycat.hdf5.ArraySet(file) + hdf5_array = hdf5_arrayset[array] + + if not(0 <= attribute and attribute < len(hdf5_array.attributes)): + raise cherrypy.HTTPError("400 Attribute argument out-of-range.") + if len(ranges) != hdf5_array.ndim: + raise cherrypy.HTTPError("400 Ranges argument doesn't contain the correct number of dimensions.") + + ranges = [(max(dimension["begin"], range[0]), min(dimension["end"], range[1])) for dimension, range in zip(hdf5_array.dimensions, ranges)] + index = tuple([slice(begin, end) for begin, end in ranges]) + + attribute_type = hdf5_array.attributes[attribute]["type"] + data = hdf5_array.get_data(attribute)[index] + + if byteorder is None: + return json.dumps(data.tolist()) + else: + if sys.byteorder != byteorder: + return data.byteswap().tostring(order="C") + else: + return data.tostring(order="C") @cherrypy.tools.json_out(on = True) def get_model_arrayset_metadata(mid, aid, **kwargs):