Skip to content
This repository has been archived by the owner on May 26, 2018. It is now read-only.

Commit

Permalink
api implementation + test with autogen form tool brutusin
Browse files Browse the repository at this point in the history
  • Loading branch information
ikit committed Oct 11, 2016
1 parent 29d0b1b commit 28c6545
Show file tree
Hide file tree
Showing 12 changed files with 1,854 additions and 14 deletions.
48 changes: 45 additions & 3 deletions pirus/api_v1/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def notify_all(src, msg):




# API HANDLERS

class WebsiteHandler:
Expand Down Expand Up @@ -95,6 +96,9 @@ def get_api(self, request):
"TODO" : "url to the swagger and the doc for this version of the api"
})

def get_db(self, request):
return rest_success([f for f in os.listdir(DATABASES_DIR) if os.path.isfile(os.path.join(DATABASES_DIR, f))])




Expand Down Expand Up @@ -153,15 +157,53 @@ def get_file_details(self, request):
return rest_error("Unknow file id " + str(file_id))
return rest_success(PirusFile.objects.get(pk=file_id).export_client_data())

def get_file_by_name(self, request):
return rest_success({})

def get_file_by_id(self, request):
async def dl_file(self, request):
# 1- Retrieve request parameters
file_id = request.match_info.get('file_id', -1)
if file_id == -1:
return rest_error("No file id provided")
pirus_file = PirusFile.from_id(file_id)
if pirus_file == None:
return rest_error("File with id " + str(file_id) + "doesn't exits.")
file = None
if os.path.isfile(pirus_file.file_path):
with open(path, 'br') as content_file:
file = content_file.read()
return web.Response(
headers=MultiDict({'Content-Disposition': 'Attachment'}),
body=file
)


async def dl_pipe_file(self, request):
# 1- Retrieve request parameters
pipe_id = request.match_info.get('pipe_id', -1)
filename = request.match_info.get('filename', None)
if pipe_id == -1:
return rest_error("Unknow pipeline id " + str(pipe_id))
pipeline = Pipeline.from_id(pipe_id)
if filename == None:
return rest_error("No filename provided")
path = os.path.join(pipeline.path, filename)
file = None
if os.path.isfile(path):
with open(path, 'br') as content_file:
file = content_file.read()
return web.Response(
headers=MultiDict({'Content-Disposition': 'Attachment'}),
body=file
)


async def dl_run_file(self, request):
return rest_success({})






class PipelineHandler:
def __init__(self):
pass
Expand Down
10 changes: 5 additions & 5 deletions pirus/api_v1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def import_data(self, data):
def from_id(ifile_id):
if not ObjectId.is_valid(ifile_id):
return None;
file = InputFile.objects.get(pk=ifile_id)
file = PirusFile.objects.get(pk=ifile_id)
return file




Expand Down Expand Up @@ -146,9 +146,9 @@ def export_client_data(self):
"inputs_allowed" : self.inputs_allowed,
"license" : self.license,
"authors" : self.authors,
"config_json" : "http://" + HOSTNAME + "/dl/" + str(self.id) + "/config.json",
"form_json" : "http://" + HOSTNAME + "/dl/" + str(self.id) + "/form.json",
"logo" : "http://" + HOSTNAME + "/dl/" + str(self.id) + "/" + os.path.basename(self.lfile)
"config_json" : "http://" + HOSTNAME + "/dl/p/" + str(self.id) + "/config.json",
"form_json" : "http://" + HOSTNAME + "/dl/p/" + str(self.id) + "/form.json",
"logo" : "http://" + HOSTNAME + "/dl/p/" + str(self.id) + "/" + os.path.basename(self.lfile)
}

def import_data(self, data):
Expand Down
6 changes: 4 additions & 2 deletions pirus/api_v1/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
app.router.add_route('GET', "/v1/www", website.home)
app.router.add_route('GET', "/v1/config", website.get_config)
app.router.add_route('GET', "/v1/api", website.get_api)
app.router.add_route('GET', "/v1/db", website.get_db)
app.router.add_route('GET', "/v1/ws", websocket.get)

app.router.add_route('GET', "/v1/pipeline", pipeHdl.get)
Expand All @@ -57,8 +58,9 @@
app.router.add_route('PATCH', "/v1/bigfile", fileHdl.upload_resumable)
app.router.add_route('DELETE', "/v1/file/{file_id}", fileHdl.delete)
app.router.add_route('GET', "/v1/file/{file_id}", fileHdl.get_file_details)
app.router.add_route('GET', "/v1/dl/{run_or_pipe_id}/{filename}", fileHdl.get_file_by_name)
app.router.add_route('GET', "/v1/dl/{file_id}", fileHdl.get_file_by_id)
app.router.add_route('GET', "/v1/dl/f/{file_id}", fileHdl.dl_file)
app.router.add_route('GET', "/v1/dl/p/{pipe_id}/{filename}", fileHdl.dl_pipe_file)
app.router.add_route('GET', "/v1/dl/r/{run_id}/{filename}", fileHdl.dl_run_file)

app.router.add_route('GET', "/v1/run/notify/{run_id}/p/{complete}", runHdl.up_progress)
app.router.add_route('GET', "/v1/run/notify/{run_id}/s/{status}", runHdl.up_status)
Expand Down
109 changes: 109 additions & 0 deletions pirus/templates/brutusin/css/brutusin-json-forms.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright 2015 brutusin.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Ignacio del Valle Alles idelvall@brutusin.org
*/
.loading-layer{
position: absolute;
top:0px;
left:0px;
z-index : 10;
width: 100%;
height: 100%;
opacity: 0.7;
background-color: white;
}
.loading-icon{
position: absolute;
top:14px;
left:50%;
z-index : 11;
}
.loading-icon-select{
position: absolute;
top:14px;
left:50%;
z-index : 11;
}
.loading-icon-checkbox{
position: absolute;
top:7px;
left:3px;
z-index : 11;
}
.glyphicon-refresh-animate {
animation: spin .7s infinite linear;
-webkit-animation: spin2 .7s infinite linear;
}

@-webkit-keyframes spin2 {
from { -webkit-transform: rotate(0deg);}
to { -webkit-transform: rotate(360deg);}
}

@keyframes spin {
from { transform: scale(1) rotate(0deg);}
to { transform: scale(1) rotate(360deg);}
}
form.brutusin-form table, form.brutusin-form input, form.brutusin-form select, form.brutusin-form textarea{
width: 100% !important;
min-width: 80px;
}
form.brutusin-form input[type=checkbox]{
width: auto !important;
min-width: auto !important;
}
form.brutusin-form textarea{
height: 8em;
}
form.brutusin-form table table{
border-left: solid 1px;
border-color: lightgray;
margin: 4px;
}
form.brutusin-form td {
vertical-align: top;
padding: 4px;
white-space: nowrap;
}
form.brutusin-form td.prop-name {
text-align: right;
}
form.brutusin-form td.add-prop-name table {
text-align: right;
border: none;
}
form.brutusin-form td.add-prop-name table td {
vertical-align: middle;
}
form.brutusin-form td.prop-value {
width: 100%;
text-align: left;
}
form.brutusin-form td.item-index{
font-size: 0.8em;
color: lightgray;
width: 25px;
text-align: right;
}
form.brutusin-form td.item-action{
width: 30px;
}
form.brutusin-form .error {
border-color: red;
}
form.brutusin-form .error-message {
color: red;
}
1 change: 1 addition & 0 deletions pirus/templates/brutusin/css/brutusin-json-forms.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 28c6545

Please sign in to comment.