RAPPEL : Opération de maintenance > ForgeMIA indisponible le 20 Janvier entre 7h et 12h

Commit d33a7eba authored by Jerome Mariette's avatar Jerome Mariette
Browse files

add application class

parent 9d981dc5
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import cherrypy
import cgi
import tempfile
import json
import sys
import datetime
from functools import wraps
import time
import os
import argparse
try:
import _preamble
except ImportError:
sys.exc_clear()
from jflowapp.server import ApplicationServer
WEB_DIR = os.path.abspath(os.path.join(__file__, "../../docs"))
class MyJflowApp( ApplicationServer ):
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--daemon", action="store_true", dest="daemon", default=False, help="Run the server as daemon")
args = vars(parser.parse_args())
app_conf = {
'/':
{'tools.staticdir.root': WEB_DIR, 'tools.CORS.on': True},
os.path.join('/', 'css'):
{'tools.staticdir.on' : True, 'tools.staticdir.dir' : './css/'},
os.path.join('/', 'js'):
{'tools.staticdir.on' : True, 'tools.staticdir.dir' : './js/'},
os.path.join('/', 'img'):
{'tools.staticdir.on' : True, 'tools.staticdir.dir' : './img/'},
os.path.join('/', 'fonts'):
{'tools.staticdir.on' : True, 'tools.staticdir.dir' : './fonts/'},
os.path.join('/', 'app'):
{'tools.staticdir.on' : True, 'tools.staticdir.dir' : './'}
}
ApplicationServer.quickstart(MyJflowApp, app_conf, daemon=args["daemon"])
\ No newline at end of file
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
\ No newline at end of file
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import pickle
from jflow.workflow import Workflow
class Result (object):
def __init__(self, name, type):
self.name = name
self.type = type
self.content = None
def serialize(self, output):
dumpfh = open(os.path.join(output, "toto.dump"), "wb")
pickle.dump(self, dumpfh)
dumpfh.close()
class Application (Workflow):
def __init__(self, args={}, id=None, function= "process"):
Workflow.__init__(self, args, id, function)
self.__results = {}
def add_result_table(self, name, content):
self.__results[name] = Result(name, "table")
self.__results[name].content = content
def post_process(self):
self.define_results()
for result in self.__results:
self.__results[result].serialize(self.directory)
\ No newline at end of file
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import pkgutil
import workflows
import inspect
import jflowapp
import sys
from jflowapp.application import Application
from jflow.workflows_manager import WorkflowsManager
class ApplicationsManager(WorkflowsManager):
def __init__(self):
WorkflowsManager.__init__(self)
def get_available_applications(self, function="process", filter_groups = [], select = False ):
if function.__class__.__name__ == "str":
functions = [function]
else:
functions = set(function)
wf_instances, wf_methodes = [], []
if isinstance(filter_groups, str): filter_groups = [filter_groups]
# Load all modules within the workflow module
for importer, modname, ispkg in pkgutil.iter_modules(workflows.__path__, workflows.__name__ + "."):
__import__(modname)
# Search for Workflow classes
for class_name, obj in inspect.getmembers(sys.modules[modname], inspect.isclass):
if issubclass(obj, jflowapp.application.Application) and obj.__name__ != jflowapp.application.Application.__name__:
for function in functions:
# check if the application has the requested methode
# inspect.ismethod has been changed for inspect.isfunction in Python3
for ifunction in inspect.getmembers(obj, predicate=inspect.isfunction):
if ifunction[0] == function:
# try to build the application
try:
select_application = True
inst = obj(function=function)
if filter_groups :
select_application = (inst.get_workflow_group() in filter_groups) == select
if select_application:
wf_instances.append(inst)
wf_methodes.append(function)
except: pass
return [wf_instances, wf_methodes]
\ No newline at end of file
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import cherrypy
from functools import wraps
from jinja2 import Environment, FileSystemLoader
from jflow.server import JFlowServer
from jflowapp.applications_manager import ApplicationsManager
class ApplicationServer( JFlowServer ):
TMPL_REP_PATH = "./views/"
def __init__(self):
JFlowServer.__init__(self)
self.wfmanager = ApplicationsManager()
workflows = self.wfmanager.get_available_applications()
print (workflows)
self.first_instance = workflows[0][0]
self.name = self.first_instance.get_name()
self.description = self.first_instance.get_description()
def get_template(self, template, func = None):
jinja_env = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(os.path.abspath(__file__)), self.TMPL_REP_PATH)))
if func != None:
jinja_env.filters[func.__name__] = func
return jinja_env.get_template( template )
@cherrypy.expose
def index(self):
return self.get_template('jflow_application_template.tmpl').render(application_name=self.name, page = "index", application_description=self.description)
@cherrypy.expose
def process(self):
return self.get_template('jflow_process.tmpl').render(application_name = self.name, wf_class = self.first_instance.__class__.__name__, page = "process", application_description=self.description)
@cherrypy.expose
def results(self, workflow_id):
try:
return self.get_template(self.name+'_results.tmpl').render(application_name=self.name, wf_id = "13", application_description=self.description)
except:
return self.get_template('jflow_results.tmpl').render(application_name=self.name, wf_id = workflow_id, application_description=self.description)
{#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<title>{{application_name}}</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/theme.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body role="document">
<!-- Fixed navbar -->
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./index">{{application_name}}</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li {% if page == "index" %} class="active" {% endif %}><a href="./index">About</a></li>
<li {% if page == "process" %} class="active" {% endif %}><a href="./process">Process</a></li>
<li><a href="mailto:support.genopole@toulouse.inra.fr">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container theme-showcase" role="main">
<!-- Jumbotron -->
<div class="jumbotron" style="margin-top:-25px;text-align:justify">
<h1>{{application_name}}</h1>
<p class="lead">{{application_description}}</p>
</div>
<div class="container theme-showcase" role="main">
{% block page_body_content %}
{% endblock page_body_content %}
</div>
<hr>
<footer>
<div class="container" style="text-align: center;">
<p>Copyright © 2015, INRA | Designed by <a target="_blank" href="http://bioinfo.genotoul.fr/">GenoToul Bioinfo platform</a> and <a target="_blank" href="http://www.sigenae.org/">Sigenae platform</a>.</p>
</div>
</footer>
</div> <!-- /container -->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src='js/jflow.min.js' type='text/javascript'></script>
{% block js_file %}
{% endblock js_file %}
<script type='text/javascript'>
$(document).ready(function(){
{% block js_block %}
{% endblock js_block %}
});
</script>
</body>
</html>
{#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "jflow_application_template.tmpl" %}
{% block page_body_content %}
<div id="jflow-form"> </div>
{% endblock page_body_content %}
{% block js_block %}
$('#jflow-form').wfform({
workflowClass: "{{wf_class}}"
});
$('#jflow-form').on('run.wfform', function(event, running_wf) {
window.location = "/results?workflow_id="+running_wf.id;
});
{% endblock js_block %}
\ No newline at end of file
{#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "jflow_application_template.tmpl" %}
{% block page_body_content %}
<div id="results"> </div>
{% endblock page_body_content %}
{% block js_block %}
$('#results').wfoutputs({
workflowID: {{wf_id}}
}) ;
{% endblock js_block %}
{#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "jflow_application_template.tmpl" %}
{% block page_body_content %}
<div id="results"> </div>
{% endblock page_body_content %}
{% block js_block %}
$('#results').wfoutputs({
workflowID: {{wf_id}}
}) ;
{% endblock js_block %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment