From 03c9d6d8441e3293b058fed270866419781b734c Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 26 Sep 2018 16:23:29 +0200 Subject: Run 2to3 Some stuff is broken now. --- kpov_judge/create_disk_images.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'kpov_judge/create_disk_images.py') diff --git a/kpov_judge/create_disk_images.py b/kpov_judge/create_disk_images.py index c9d433f..b3ea93d 100755 --- a/kpov_judge/create_disk_images.py +++ b/kpov_judge/create_disk_images.py @@ -22,7 +22,7 @@ def get_prepare_disks(db, class_id, task_id): def create_snapshot(class_id, task_id, student_id, disk_name, overwrite = True, cow = False): print(os.path.join(settings.DISK_TEMPLATE_PATH, disk_name) + '.*') template_paths = glob.glob(os.path.join(settings.DISK_TEMPLATE_PATH, disk_name) + '.*') - filtered_paths = filter((lambda x: os.path.splitext(x)[1] == '.' + settings.STUDENT_DISK_FORMAT), template_paths) + filtered_paths = list(filter((lambda x: os.path.splitext(x)[1] == '.' + settings.STUDENT_DISK_FORMAT), template_paths)) if filtered_paths: template_path = filtered_paths[0] else: @@ -60,13 +60,13 @@ def publish_snapshot(d): if __name__ == '__main__': if len(sys.argv) != 1: - print "Usage: {0}" - print "Create the pending disk images" + print("Usage: {0}") + print("Create the pending disk images") db = pymongo.MongoClient(settings.DB_HOST).kpov try: db.authenticate(settings.USERNAME, settings.PASSWORD) - except Exception, e: - print str(e) + except Exception as e: + print(str(e)) dev_prefix = settings.GUESTFS_DEV_PREFIX l = db.student_computers.find({"disk_urls": {"$exists": False}}) computers_by_class_task_student = dict() @@ -75,9 +75,10 @@ if __name__ == '__main__': if (class_id, task_id, student_id) not in computers_by_class_task_student: computers_by_class_task_student[(class_id, task_id, student_id)] = list() computers_by_class_task_student[(class_id, task_id, student_id)].append(computer) - for (class_id, task_id, student_id), computers in computers_by_class_task_student.items(): - print "Creating {}/{} for {}".format(class_id, task_id, student_id) - l = db.student_computers.find_one({'class_id': class_id, 'task_id': task_id, 'student_id':student_id, "disk_urls": {"$exists": False}}) + + for (class_id, task_id, student_id), computers in list(computers_by_class_task_student.items()): + print("Creating {}/{} for {}".format(class_id, task_id, student_id)) + l = db.student_computers.find_one({'class_id': class_id, 'task_id': task_id, 'student_id':student_id, "disk_urls": {"$exists": False}}) if l is None: continue lock_file = os.path.join(settings.STUDENT_LOCKFILE_PATH, @@ -160,9 +161,9 @@ if __name__ == '__main__': g.umount_all() g.close() lock_fp.write("saving URLs\n") - for comp_name, d_dict in all_disks.iteritems(): + for comp_name, d_dict in all_disks.items(): disk_urls = list() - for d_name, d in d_dict.iteritems(): + for d_name, d in d_dict.items(): lock_fp.write('publishing '+ str(d) + '\n') url = publish_snapshot(d) lock_fp.write('published as '+ url + '\n') -- cgit v1.2.1