Initial import.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sat, 12 Sep 2015 22:30:55 +0000 (00:30 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sat, 12 Sep 2015 22:30:55 +0000 (00:30 +0200)
app.py [new file with mode: 0755]
templates/index.html [new file with mode: 0644]
templates/output.html [new file with mode: 0644]

diff --git a/app.py b/app.py
new file mode 100755 (executable)
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 (file)
index 0000000..36d5602
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+    <title>OCCI Compliance Tests</title>
+</head>
+
+<body>
+    <form method='POST' action='/'>
+        {{ form.hidden_tag() }}
+        <table>
+            <tr>
+                <td>{{ form.url.label }}</td><td>{{ form.url(size=30) }}</td>
+            </tr>
+            <tr>
+                <td>{{ form.user.label }}</td><td>{{ form.user(size=20) }}</td>
+            </tr>
+            <tr>
+                <td>{{ form.password.label }}</td><td>{{ form.password(size=20, password=True) }}</td>
+            </tr>
+        </table>
+        {{ form.submit }}
+    </form>
+</body>
+
+</html>
diff --git a/templates/output.html b/templates/output.html
new file mode 100644 (file)
index 0000000..861a617
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+    <title>OCCI Compliance Tests</title>
+</head>
+
+<body>
+    <pre>{{ result }}</pre>
+{% if error %}
+    <p>{{error}}
+{% endif %}
+</body>
+
+</html>