Skip to content

Commit

Permalink
Remove PUT Model Table. Closes #414.
Browse files Browse the repository at this point in the history
  • Loading branch information
tshead2 committed May 5, 2015
1 parent 29452c7 commit a5b5ffe
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 133 deletions.
31 changes: 31 additions & 0 deletions docs/POST-Model-Files.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
POST Model Files
================

.. http:post /models/(mid)/files
Upload files for addition to a model, either from the client to the server or
a remote host to the server using a remote session. To upload files from the
client, specify the "files" parameter with one or more files. To upload
remote files, specify the "sids" and "paths" parameters with a session id and
remote filepath for each file to upload. In either case specify the
boolean "input" parameter, the name of a parsing plugin in "parser", and one
or more artifact names using "names".
:param mid: Unique model identifier.
:type mid: string
:requestheader Content-Type: form/multipart
:form files: Local files for upload.
:form input: Set to "true" to store results as input artifacts.
:form names: Artifact names for storage.
:form parser: Parsing plugin name.
:form paths: Remote host absolute filesystem paths.
:form sids: Remote session ids.
See Also
--------

- :http:post:`/remotes/(sid)/browse(path)`

30 changes: 0 additions & 30 deletions docs/PUT-Model-Table.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/rest-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ any programming language or library that supports HTTP requests.
GET-User.rst
POST-Events.rst
POST-Model-Command.rst
POST-Model-Files.rst
POST-Model-Finish.rst
POST-Project-Bookmark.rst
POST-Project-Models.rst
Expand All @@ -53,7 +54,6 @@ any programming language or library that supports HTTP requests.
PUT-Model-File.rst
PUT-Model-Inputs.rst
PUT-Model-Parameter.rst
PUT-Model-Table.rst
PUT-Model.rst
PUT-Project.rst

1 change: 0 additions & 1 deletion packages/slycat/web/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def abspath(path):
dispatcher.connect("put-model-inputs", "/models/:mid/inputs", slycat.web.server.handlers.put_model_inputs, conditions={"method" : ["PUT"]})
dispatcher.connect("put-model", "/models/:mid", slycat.web.server.handlers.put_model, conditions={"method" : ["PUT"]})
dispatcher.connect("put-model-parameter", "/models/:mid/parameters/:name", slycat.web.server.handlers.put_model_parameter, conditions={"method" : ["PUT"]})
dispatcher.connect("put-model-table", "/models/:mid/tables/:name", slycat.web.server.handlers.put_model_table, conditions={"method" : ["PUT"]})
dispatcher.connect("put-project", "/projects/:pid", slycat.web.server.handlers.put_project, conditions={"method" : ["PUT"]})

def log_configuration(tree, indent=""):
Expand Down
53 changes: 4 additions & 49 deletions packages/slycat/web/server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,6 @@ def post_model_finish(mid):
cherrypy.response.status = "202 Finishing model."

def post_model_files(mid, input=None, files=None, sids=None, paths=None, names=None, parser=None, **kwargs):
cherrypy.log.error("input %s" % input)
cherrypy.log.error("files %s" % files)
cherrypy.log.error("sids %s" % sids)
cherrypy.log.error("paths %s" % paths)
cherrypy.log.error("names %s" % names)
cherrypy.log.error("parser %s" % parser)
cherrypy.log.error("kwargs %s" % kwargs)

if input is None:
raise cherrypy.HTTPError("400 Required input parameter is missing.")
input = True if input == "true" else False
Expand All @@ -473,6 +465,10 @@ def post_model_files(mid, input=None, files=None, sids=None, paths=None, names=N
files = [files]
files = [file.file.read() for file in files]
elif files is None and sids is not None and paths is not None:
if not isinstance(sids, list):
sids = [sids]
if not isinstance(paths, list):
paths = [paths]
if len(sids) != len(paths):
raise cherrypy.HTTPError("400 sids and paths parameters must have the same length.")
files = []
Expand Down Expand Up @@ -537,47 +533,6 @@ def put_model_inputs(mid):

slycat.web.server.put_model_inputs(database, model, source, deep_copy)

def put_model_table(mid, name, input=None, file=None, sid=None, path=None):
"""Deprecated."""
database = slycat.web.server.database.couchdb.connect()
model = database.get("model", mid)
project = database.get("project", model["project"])
slycat.web.server.authentication.require_project_writer(project)

if input is None:
raise cherrypy.HTTPError("400 Required input parameter is missing.")
input = True if input == "true" else False

if file is not None and sid is None and path is None:
data = file.file.read()
filename = file.filename
elif file is None and sid is not None and path is not None:
with slycat.web.server.remote.get_session(sid) as session:
filename = "%s@%s:%s" % (session.username, session.hostname, path)
if stat.S_ISDIR(session.sftp.stat(path).st_mode):
raise cherrypy.HTTPError("400 Cannot load directory %s." % filename)
data = session.sftp.file(path).read()
else:
raise cherrypy.HTTPError("400 Must supply a file parameter, or sid and path parameters.")

slycat.web.server.update_model(database, model, message="Loading table %s from %s." % (name, filename))
try:
array = slycat.table.parse(data)
except:
raise cherrypy.HTTPError("400 Could not parse file %s" % filename)

storage = uuid.uuid4().hex
with slycat.web.server.hdf5.lock:
with slycat.web.server.hdf5.create(storage) as file:
database.save({"_id" : storage, "type" : "hdf5"})
model["artifact:%s" % name] = storage
model["artifact-types"][name] = "hdf5"
if input:
model["input-artifacts"] = list(set(model["input-artifacts"] + [name]))
database.save(model)
arrayset = slycat.hdf5.ArraySet(file)
arrayset.store_array(0, array)

@cherrypy.tools.json_in(on = True)
def put_model_parameter(mid, name):
database = slycat.web.server.database.couchdb.connect()
Expand Down
34 changes: 0 additions & 34 deletions web-server/js/slycat-web-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,40 +717,6 @@ define("slycat-web-client", ["slycat-server-root", "jquery", "URI"], function(se
});
}

module.put_model_table = function(params)
{
var data = new FormData();
data.append("input", params.input === undefined ? true: params.input ? true: false);
if(params.sid && params.path)
{
data.append("sid", params.sid);
data.append("path", params.path);
}
else if(params.file)
{
data.append("file", params.file);
}

$.ajax(
{
contentType: false,
processData: false,
data: data,
type: "PUT",
url: server_root + "models/" + params.mid + "/tables/" + params.name,
success: function()
{
if(params.success)
params.success();
},
error: function(request, status, reason_phrase)
{
if(params.error)
params.error(request, status, reason_phrase);
},
});
}

module.put_project = function(params)
{
var project = {};
Expand Down
2 changes: 1 addition & 1 deletion web-server/plugins/slycat-cca/js/local-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
files: component.browser.selection(),
input: true,
names: ["data-table"],
parser: "slycat-csv-parser",
parser: component.parser(),
success: function()
{
client.get_model_table_metadata(
Expand Down
10 changes: 6 additions & 4 deletions web-server/plugins/slycat-cca/js/remote-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
component.remote = mapping.fromJS({hostname: null, username: null, password: null, status: null, status_type: null, enable: true, focus: false, sid: null});
component.remote.focus.extend({notify: "always"});
component.browser = mapping.fromJS({path:null, selection: []});
component.parser = ko.observable(null);
component.attributes = mapping.fromJS([]);
component.scale_inputs = ko.observable(true);

Expand Down Expand Up @@ -76,13 +77,14 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
}
component.load_table = function()
{
client.put_model_table(
client.post_model_files(
{
mid: component.model._id(),
sid: component.remote.sid(),
path: component.browser.selection()[0],
sids: [component.remote.sid()],
paths: [component.browser.selection()],
input: true,
name: "data-table",
names: ["data-table"],
parser: component.parser(),
success: function()
{
client.get_model_table_metadata(
Expand Down
1 change: 1 addition & 0 deletions web-server/plugins/slycat-cca/remote-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h3 class="modal-title">New Remote CCA Model</h3>
</div>
<div data-bind="visible:tab() == 2" style="height: 400px">
<slycat-remote-browser params="type:'remote',sid:remote.sid,hostname:remote.hostname,selection:browser.selection,path:browser.path,open_file_callback:load_table"></slycat-remote-browser>
<slycat-parser-controls params="parser:parser"></slycat-parser-controls>
</div>
<div data-bind="visible:tab() == 3">
<table style="width:100%">
Expand Down
3 changes: 1 addition & 2 deletions web-server/plugins/slycat-csv-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def parse(database, model, input, files, names, **kwargs):

slycat.web.server.put_model_arrayset(database, model, name, input)
slycat.web.server.put_model_array(database, model, name, 0, attributes, dimensions)
for attribute_index, column in enumerate(data):
slycat.web.server.put_model_arrayset_data(database, model, name, "%s/%s/..." % (array_index, attribute_index), [column])
slycat.web.server.put_model_arrayset_data(database, model, name, "%s/.../..." % array_index, data)

def register_slycat_plugin(context):
context.register_parser("slycat-csv-parser", "Comma separated values (CSV)", ["table"], parse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h3 class="modal-title">New Linear Regression Model</h3>
</div>
<div data-bind="visible:tab() == 1">
<slycat-local-browser params="selection:browser.selection"></slycat-local-browser>
<slycat-parser-controls params="parser:parser"></slycat-parser-controls>
</div>
<div data-bind="visible:tab() == 2">
<table style="width:100%">
Expand Down
8 changes: 5 additions & 3 deletions web-server/plugins/slycat-linear-regression-demo/wizard-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
component.project = params.projects()[0];
component.model = mapping.fromJS({_id: null, name: "New Linear Regression Demo Model", description: "This model demonstrates plotting with d3.js", marking: null});
component.browser = mapping.fromJS({selection: []});
component.parser = ko.observable(null);
component.attributes = mapping.fromJS([]);
component.x_column = ko.observable(null);
component.y_column = ko.observable(null);
Expand Down Expand Up @@ -37,12 +38,13 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
{
console.log("upload_table", component.browser.selection());

client.put_model_table(
client.post_model_files(
{
mid: component.model._id(),
file: component.browser.selection()[0],
files: component.browser.selection(),
input: true,
name: "data-table",
names: ["data-table"],
parser: component.parser(),
success: function()
{
client.get_model_table_metadata(
Expand Down
10 changes: 6 additions & 4 deletions web-server/plugins/slycat-parameter-image/js/wizard-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
component.remote = mapping.fromJS({hostname: null, username: null, password: null, status: null, status_type: null, enable: true, focus: false, sid: null});
component.remote.focus.extend({notify: "always"});
component.browser = mapping.fromJS({path:null, selection: []});
component.parser = ko.observable(null);
component.attributes = mapping.fromJS([]);

component.cancel = function()
Expand Down Expand Up @@ -63,13 +64,14 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
}
component.load_table = function()
{
client.put_model_table(
client.post_model_files(
{
mid: component.model._id(),
sid: component.remote.sid(),
path: component.browser.selection()[0],
sids: [component.remote.sid()],
paths: component.browser.selection(),
input: true,
name: "data-table",
names: ["data-table"],
parser: component.parser(),
success: function()
{
client.get_model_command(
Expand Down
1 change: 1 addition & 0 deletions web-server/plugins/slycat-parameter-image/wizard-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h3 class="modal-title">Remote Parameter Image Model</h3>
</div>
<div data-bind="visible:tab() == 2" style="height: 400px">
<slycat-remote-browser params="type:'remote',sid:remote.sid,hostname:remote.hostname,selection:browser.selection,path:browser.path,open_file_callback:load_table"></slycat-remote-browser>
<slycat-parser-controls params="parser:parser"></slycat-parser-controls>
</div>
<div data-bind="visible:tab() == 3">
<table style="width:100%">
Expand Down
10 changes: 6 additions & 4 deletions web-server/plugins/slycat-tracer-image/js/wizard-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
component.remote = mapping.fromJS({hostname: null, username: null, password: null, status: null, status_type: null, enable: true, focus: false, sid: null});
component.remote.focus.extend({notify: "always"});
component.browser = mapping.fromJS({path:null, selection: []});
component.parser = ko.observable(null);
component.attributes = mapping.fromJS([]);

component.cancel = function()
Expand Down Expand Up @@ -63,13 +64,14 @@ define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout",
}
component.load_table = function()
{
client.put_model_table(
client.post_model_files(
{
mid: component.model._id(),
sid: component.remote.sid(),
path: component.browser.selection()[0],
sids: [component.remote.sid()],
paths: component.browser.selection(),
input: true,
name: "data-table",
names: ["data-table"],
parser: component.parser(),
success: function()
{
client.get_model_command(
Expand Down
1 change: 1 addition & 0 deletions web-server/plugins/slycat-tracer-image/wizard-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h3 class="modal-title">New Remote Tracer Image Model</h3>
</div>
<div data-bind="visible:tab() == 2" style="height: 400px">
<slycat-remote-browser params="type:'remote',sid:remote.sid,hostname:remote.hostname,selection:browser.selection,path:browser.path,open_file_callback:load_table"></slycat-remote-browser>
<slycat-parser-controls params="parser:parser"></slycat-parser-controls>
</div>
<div data-bind="visible:tab() == 3">
<table style="width:100%">
Expand Down

0 comments on commit a5b5ffe

Please sign in to comment.