From 448ff2cd1168ccee81f848238170ad156a3684b4 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 16 Feb 2019 17:44:42 +0100 Subject: Create disk images in multiple formats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor some code in create_disk_images.oy into a »prepare_disks« function that creates disk images in the given format for one task. Store paths to images in multiple formats in the database and update the front-end. --- kpov_judge/web/kpov_judge/kpov_judge.py | 16 +++++++--- .../web/kpov_judge/templates/task_greeting.html | 36 ++++++++++++++-------- 2 files changed, 34 insertions(+), 18 deletions(-) (limited to 'kpov_judge/web') diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py index c0bf885..9e4e24a 100755 --- a/kpov_judge/web/kpov_judge/kpov_judge.py +++ b/kpov_judge/web/kpov_judge/kpov_judge.py @@ -255,11 +255,17 @@ def task_greeting(class_id, task_id, lang): }] except Exception as e: instructions = str(e) + computer_list = list(db.student_computers.find({'class_id': class_id, 'task_id': task_id, 'student_id': student_id})) - backing_images = set() + + backing_files = collections.defaultdict(set) for computer in computer_list: - for disk_url in computer.get('disk_urls', []): - backing_images |= set(disk_url['backing']) + if 'disk_urls' not in computer: + continue + for name, disk in computer['disk_urls'].items(): + for fmt in disk['formats']: + backing_files[fmt] |= set(disk[fmt][1:]) + if request.args.get('narediStack', 'false') == 'true': #db.student_tasks.update({'task_id': task_id, 'student_id': student_id}, {'$set': {'create_openstack': True}}, upsert = True) openstackCreated = False # Spremeni na True, ko odkomentiras zgornjo vrstico. @@ -285,8 +291,8 @@ def task_greeting(class_id, task_id, lang): disk_base_url='/'.join([app.config['STUDENT_DISK_URL'], student_id, class_id, task_id, '']), class_id=class_id, task_id=task_id, - computers=computer_list, - backing_images=sorted(backing_images), + computers=sorted((c for c in computer_list if 'disk_urls' in c), key=lambda c: c['name']), + backing_files={fmt: sorted(images) for fmt, images in backing_files.items()}, lang='sl' if lang == 'si' else lang, # TODO s/si/sl in all tasks (and maybe elsewhere) openstack=openstackCreated, instructions=jinja2.Template(instructions), diff --git a/kpov_judge/web/kpov_judge/templates/task_greeting.html b/kpov_judge/web/kpov_judge/templates/task_greeting.html index 49288e3..ee27853 100644 --- a/kpov_judge/web/kpov_judge/templates/task_greeting.html +++ b/kpov_judge/web/kpov_judge/templates/task_greeting.html @@ -56,37 +56,47 @@ section > ul {

{{ _('Računalniki') }}

+{% if computers %}

-{{ _('Slike diskov za to nalogo:') }} +{{ _('Za GNS3 uporabite slike v formatu qcow2 ali VMDK, za katere rabite še zaledne datoteke (angl. backing files). VirtualBox ne podpira zalednih datotek, zato so slike VDI precej večje. Namesto prenosa lahko slike VDI dobite iz formata qcow2 ali VMDK.') }} {% for c in computers %}

  • {{c['name']}} - {% if 'disk_urls' in c %}
      - {% for u in c['disk_urls'] %} -
    • {{u['name']}} + {% for name, disk in c['disk_urls'].items() %} +
    • {{name}} [ {% for fmt in disk['formats'] %}{{fmt}} {% endfor %}] + {% else %} {% endfor %}
    - {% else %} -
    {{ _('Slike navideznih diskov so v izdelavi in bodo kmalu na voljo.') }} - {% endif %}
{% endfor %} +{% if backing_files %}
-{% if backing_images %} -

{{ _('Osnovne slike') }}

+

{{ _('Zaledne datoteke') }}

-{{ _('Te slike so enake za vse naloge. Prenesite samo tiste, ki jih še nimate.') }} +{{ _('Vsako od spodnjih slik prenesete samo pri prvi nalogi, v kateri se pojavi. Vse datoteke morajo biti v istem imeniku.') }}

    -{% for b in backing_images %} -
  • {{b}}
  • +{% for fmt, images in backing_files.items() %} + {% if images %} +
  • {{fmt}} +
      + {% for image in images %} +
    • {{image}}
    • + {% endfor %} +
    +
  • + {% endif %} {% endfor %}
-{% endif %}
+{% endif %} + +{% else %} +

{{ _('Slike navideznih diskov so v izdelavi in bodo kmalu na voljo.') }} +{% endif %}

-- cgit v1.2.1