summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kpov_judge/web/kpov_judge/kpov_draw_setup.py50
-rwxr-xr-xkpov_judge/web/kpov_judge/kpov_judge.py19
-rw-r--r--kpov_judge/web/kpov_judge/static/icons/computer.pngbin0 -> 15600 bytes
-rw-r--r--kpov_judge/web/kpov_judge/static/icons/computer.svg (renamed from kpov_judge/web/kpov_judge/icons/computer.svg)0
-rw-r--r--kpov_judge/web/kpov_judge/static/icons/drive-harddisk.pngbin0 -> 1940 bytes
-rw-r--r--kpov_judge/web/kpov_judge/static/icons/drive-harddisk.svg (renamed from kpov_judge/web/kpov_judge/icons/drive-harddisk.svg)0
-rw-r--r--kpov_judge/web/kpov_judge/static/icons/internet.pngbin0 -> 9438 bytes
-rw-r--r--kpov_judge/web/kpov_judge/static/icons/internet.svg (renamed from kpov_judge/web/kpov_judge/icons/internet.svg)0
-rw-r--r--kpov_judge/web/kpov_judge/templates/task_greeting.html4
9 files changed, 45 insertions, 28 deletions
diff --git a/kpov_judge/web/kpov_judge/kpov_draw_setup.py b/kpov_judge/web/kpov_judge/kpov_draw_setup.py
index a6ffc82..0042389 100644
--- a/kpov_judge/web/kpov_judge/kpov_draw_setup.py
+++ b/kpov_judge/web/kpov_judge/kpov_draw_setup.py
@@ -1,35 +1,41 @@
import pygraphviz as pgv
-def draw_setup(computers, networks, destination = None):
- G = pgv.AGraph()
+def draw_setup(computers, networks, destination=None,
+ icon_prefix = '../../../static/icons/',
+ format='svg', icon_path = '', icon_suffix = None):
+ if icon_suffix is None:
+ icon_suffix = format
+ icon_suffix = '.' + icon_suffix
+ G = pgv.AGraph(imagepath=icon_path + '/')
+ print G.graph_attr
have_internet = []
- for net, net_params in networks.iteritems():
- if net_params.get('public', False):
- have_internet.append(net)
- G.add_node('net-' + net, label=net, shape='rectangle')
+ for net in networks:
+ net_name = net.get('name', 'net')
+ if net.get('public', False):
+ have_internet.append(net_name)
+ G.add_node('net-' + net_name, label=net_name, shape='rectangle')
if len(have_internet):
G.add_node('net-' + 'internet',
label='internet',
- labelloc='b', image='icons/internet.svg', shape='none')
+ labelloc='b',
+ image=icon_prefix + 'internet' + icon_suffix,
+ shape='none')
for n in have_internet:
G.add_edge('net-' + n, 'net-internet')
- for c, properties in computers.iteritems():
- G.add_node('comp-' + c,
- label = c,
- image='icons/computer.svg',
- shape='none', labelloc='b')
- G_sub = G.add_subgraph(['comp-' + c], name='cluster-' + c,
- label = c,
- rank='same', pack=True)
+ for properties in computers:
+ c = properties.get('name', '')
+ label_str = '< <TABLE BORDER="0"><TR><TD COLSPAN="2"><B>{}</B></TD></TR><TR><TD COLSPAN="2"><IMG SRC="{}"/></TD></TR>'
+ label = label_str.format(c, icon_prefix + 'computer' + icon_suffix)
for hdd in properties.get('disks', []):
- G_sub.add_node('disk-' + hdd['name'],
- label=hdd['name'],
- shape='none',
- image='icons/drive-harddisk.svg')
- G_sub.add_edge('comp-' + c, 'disk-' + hdd['name'])
- for iface in properties.get('network_interfaces'):
+ icon = icon_prefix + 'drive-harddisk' + icon_suffix
+ label += '<TR><TD><IMG SRC="{}" /></TD><TD>{}</TD></TR>'.format(icon, hdd['name'])
+ label += '</TABLE> >'
+ G.add_node('comp-' + c,
+ label = label,
+ shape='box', labelloc='b')
+ for iface in properties.get('network_interfaces', []):
G.add_edge('comp-' + c, 'net-' + iface['network'])
- return G.draw(path=destination, format='svg', prog='dot')
+ return G.draw(path=destination, format=format, prog='dot')
if __name__ == '__main__':
import sample_task as task
diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py
index d02ba99..21233f4 100755
--- a/kpov_judge/web/kpov_judge/kpov_judge.py
+++ b/kpov_judge/web/kpov_judge/kpov_judge.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import flask
-from flask import Flask, g, session, redirect, url_for, abort, render_template, flash, app, request
+from flask import Flask, g, session, redirect, url_for, abort, render_template, flash, app, request, Response
import pymongo
import json
import random
@@ -104,11 +104,18 @@ def results_json(task_id):
return json.dumps(results_post(task_id, json.loads(flask.app.request.form['results'])))
return json.dumps(results_dict(task_id))
-@app.route('/tasks/<task_id>/setup.svg', methods=['GET'])
-def setup_svg(task_id):
- networks = db.networks.find({'task_id': task_id})
- computers = db.computers_meta.find({'task_id': task_id})
- return draw_setup(computers, networks)
+@app.route('/tasks/<task_id>/<lang>/setup.<ending>', methods=['GET'])
+def setup_svg(task_id, lang, ending):
+ db = g.db
+ fmt, mimetype = {
+ 'svg':('svg', 'image/svg+xml'),
+ 'png':('png', 'image/png'),
+ }[ending]
+ networks = list(db.networks.find({'task_id': task_id}))
+ computers = list(db.computers_meta.find({'task_id': task_id}))
+ return Response(draw_setup(computers, networks, format=fmt,
+ icon_path=app.config['STATIC_DIR']),
+ mimetype=mimetype)
@app.route('/tasks/<task_id>/<lang>/results.html')
def results_html(task_id, lang):
diff --git a/kpov_judge/web/kpov_judge/static/icons/computer.png b/kpov_judge/web/kpov_judge/static/icons/computer.png
new file mode 100644
index 0000000..aebd82e
--- /dev/null
+++ b/kpov_judge/web/kpov_judge/static/icons/computer.png
Binary files differ
diff --git a/kpov_judge/web/kpov_judge/icons/computer.svg b/kpov_judge/web/kpov_judge/static/icons/computer.svg
index 6da674d..6da674d 100644
--- a/kpov_judge/web/kpov_judge/icons/computer.svg
+++ b/kpov_judge/web/kpov_judge/static/icons/computer.svg
diff --git a/kpov_judge/web/kpov_judge/static/icons/drive-harddisk.png b/kpov_judge/web/kpov_judge/static/icons/drive-harddisk.png
new file mode 100644
index 0000000..ce482f2
--- /dev/null
+++ b/kpov_judge/web/kpov_judge/static/icons/drive-harddisk.png
Binary files differ
diff --git a/kpov_judge/web/kpov_judge/icons/drive-harddisk.svg b/kpov_judge/web/kpov_judge/static/icons/drive-harddisk.svg
index 5f36f85..5f36f85 100644
--- a/kpov_judge/web/kpov_judge/icons/drive-harddisk.svg
+++ b/kpov_judge/web/kpov_judge/static/icons/drive-harddisk.svg
diff --git a/kpov_judge/web/kpov_judge/static/icons/internet.png b/kpov_judge/web/kpov_judge/static/icons/internet.png
new file mode 100644
index 0000000..2f70cbf
--- /dev/null
+++ b/kpov_judge/web/kpov_judge/static/icons/internet.png
Binary files differ
diff --git a/kpov_judge/web/kpov_judge/icons/internet.svg b/kpov_judge/web/kpov_judge/static/icons/internet.svg
index 5efbd24..5efbd24 100644
--- a/kpov_judge/web/kpov_judge/icons/internet.svg
+++ b/kpov_judge/web/kpov_judge/static/icons/internet.svg
diff --git a/kpov_judge/web/kpov_judge/templates/task_greeting.html b/kpov_judge/web/kpov_judge/templates/task_greeting.html
index f19f534..f188def 100644
--- a/kpov_judge/web/kpov_judge/templates/task_greeting.html
+++ b/kpov_judge/web/kpov_judge/templates/task_greeting.html
@@ -13,6 +13,7 @@
<p>
<a href='howto/'>Podrobna navodila (HOWTO)</a>
</p>
+
<h2>Računalniki v vaji</h2>
{% for c in computers %}
<h3>{{c['name']}}</h3>
@@ -28,6 +29,9 @@
{% endfor %}
</p>
<p>
+<img src="setup.png"/>
+</p>
+<p>
Lahko si ogledate surove:
<ul>
<li><a href='results.html'>rezultate</a> (<a href='../results.json'>json</a>)</li>