From: František Dvořák Date: Sat, 12 Sep 2015 22:30:55 +0000 (+0200) Subject: Initial import. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=4a009be95c5de88b51f5552a7f296a2a35c22c51;p=pOCCI-flask.git Initial import. --- 4a009be95c5de88b51f5552a7f296a2a35c22c51 diff --git a/app.py b/app.py new file mode 100755 index 0000000..4fd87c8 --- /dev/null +++ b/app.py @@ -0,0 +1,65 @@ +#! /usr/bin/python + +import sys +import cStringIO + +from flask import Flask, request, url_for, redirect, render_template +from flask.ext.wtf import Form +from wtforms.fields import PasswordField, StringField, SubmitField + +import pOCCI +import pOCCI.occi +import pOCCI.pOCCI + + +params = { + 'url': '--url', + 'user': '--user', + 'password': '--password', +} + + +app = Flask(__name__) +app.config['SECRET_KEY'] = 'please, tell nobody' + + +class SubmitForm(Form): + url = StringField(u'OCCI URL') + user = StringField(u'User') + password = PasswordField(u'Password') + submit = SubmitField(u'Launch tests') + + +@app.route('/', methods=['GET', 'POST']) +def launch(): + error = None + + if request.method == 'POST': + opts = ['-t', 'OCCI/CORE/READ/001'] + for p in params.keys(): + if p in request.form and request.form[p]: + opts.append(params[p]) + opts.append(request.form[p]) + print opts + + out = [cStringIO.StringIO(), cStringIO.StringIO()] + sys.stdout = out[0] + sys.stderr = out[1] + try: + pOCCI.pOCCI.main(opts) + except SystemExit as se: + if se.args[0] >= 2: + error = 'Fatal error.' + + sys.stdout = sys.__stdout__ + sys.stderr = sys.__stderr__ + + return render_template('output.html', result = out[0].getvalue() + out[1].getvalue(), error = error) + + form = SubmitForm() + return render_template('index.html', form = form) + + +if __name__ == '__main__': + app.debug = True + app.run() diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..36d5602 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,26 @@ + + + + + OCCI Compliance Tests + + + +
+ {{ form.hidden_tag() }} + + + + + + + + + + +
{{ form.url.label }}{{ form.url(size=30) }}
{{ form.user.label }}{{ form.user(size=20) }}
{{ form.password.label }}{{ form.password(size=20, password=True) }}
+ {{ form.submit }} +
+ + + diff --git a/templates/output.html b/templates/output.html new file mode 100644 index 0000000..861a617 --- /dev/null +++ b/templates/output.html @@ -0,0 +1,15 @@ + + + + + OCCI Compliance Tests + + + +
{{ result }}
+{% if error %} +

{{error}} +{% endif %} + + +