From 317a1fa7d30d7b65741d0bcaec9fe7363400732f Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Sat, 29 Feb 2020 21:27:49 -0500 Subject: [PATCH 1/9] Tools --- install_lichen.sh | 2 ++ tools/assignmentPlacer.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tools/assignmentPlacer.py diff --git a/install_lichen.sh b/install_lichen.sh index 030f1b1..7f57eaa 100755 --- a/install_lichen.sh +++ b/install_lichen.sh @@ -30,6 +30,7 @@ fi # compile & install the tools mkdir -p ${lichen_installation_dir}/bin +mkdir -p ${lichen_installation_dir}/tools #-------------------- @@ -64,6 +65,7 @@ cp ${lichen_repository_dir}/tokenizer/java/java_tokenizer.py ${lichen_installati cp ${lichen_repository_dir}/tokenizer/mips/mips_tokenizer.py ${lichen_installation_dir}/bin/mips_tokenizer.py cp ${lichen_repository_dir}/tokenizer/data.json ${lichen_installation_dir}/bin/data.json +cp ${lichen_repository_dir}/tools/* ${lichen_installation_dir}/tools ######################################################################################################################## # fix permissions diff --git a/tools/assignmentPlacer.py b/tools/assignmentPlacer.py new file mode 100644 index 0000000..11d5de7 --- /dev/null +++ b/tools/assignmentPlacer.py @@ -0,0 +1,14 @@ +import os, sys + +gradeable_path = '/var/local/submitty/courses/s20/sample/submissions/grades_released_homework_autohiddenEC' + +if __name__ == "__main__": + if not os.exists('assignments') or not os.exists(gradeable_path): + print('The assignments directory or the gradeable does not exist. Please create these.') + sys.exit(1) + + num_to_place = min(len(os.list(greadeable_path)), len(os.list('assignments'))) + + for root, dirs, files in os.walk(gradeable_path): + for name in dirs: + print(f'{root}: {name}') From db0728fda9566fbba0b95525b2f766e414f61b0c Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Tue, 3 Mar 2020 20:16:16 -0500 Subject: [PATCH 2/9] fixed --- .gitignore | 3 ++- tools/assignmentPlacer.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index e4e5f6c..7080991 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*~ \ No newline at end of file +*~ +tools/assignments/* diff --git a/tools/assignmentPlacer.py b/tools/assignmentPlacer.py index 11d5de7..39cbf71 100644 --- a/tools/assignmentPlacer.py +++ b/tools/assignmentPlacer.py @@ -1,14 +1,29 @@ import os, sys +import shutil gradeable_path = '/var/local/submitty/courses/s20/sample/submissions/grades_released_homework_autohiddenEC' if __name__ == "__main__": - if not os.exists('assignments') or not os.exists(gradeable_path): + if not os.path.isdir('assignments') or not os.path.isdir(gradeable_path): print('The assignments directory or the gradeable does not exist. Please create these.') sys.exit(1) - num_to_place = min(len(os.list(greadeable_path)), len(os.list('assignments'))) - + num_to_place = min(len(os.listdir(gradeable_path)), len(os.listdir('assignments'))) + placed = 0 + ci = 1000 + gradeable_path_count = gradeable_path.count('/') for root, dirs, files in os.walk(gradeable_path): for name in dirs: - print(f'{root}: {name}') + print(f'{root} {name}') + if (root.count('/') == gradeable_path_count): + res = list(filter(lambda x: not 'json' in x, os.listdir(f'{root}/{name}'))) + print(res) + highest = int(max(res)) + 1 + #print(f'{root}/{name}/{highest}') + new_path = f'{root}/{name}/{highest}' + os.mkdir(new_path) + shutil.copy2(f'assignments/{ci}.txt', f'{new_path}/{ci}.txt') + ci+=1 + placed += 1 + if(placed == num_to_place): + sys.exit() From 79321eae76c9e1c68e999e48057fdc0c76c0f7b3 Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Thu, 19 Mar 2020 12:24:32 -0400 Subject: [PATCH 3/9] assign Placer tweak --- tools/assignmentPlacer.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/assignmentPlacer.py b/tools/assignmentPlacer.py index 39cbf71..73e7cf7 100644 --- a/tools/assignmentPlacer.py +++ b/tools/assignmentPlacer.py @@ -8,21 +8,20 @@ print('The assignments directory or the gradeable does not exist. Please create these.') sys.exit(1) - num_to_place = min(len(os.listdir(gradeable_path)), len(os.listdir('assignments'))) + files_in_assign = os.listdir('assignments') + num_to_place = min(len(os.listdir(gradeable_path)), len(files_in_assign)) placed = 0 - ci = 1000 + ci = 0 gradeable_path_count = gradeable_path.count('/') for root, dirs, files in os.walk(gradeable_path): for name in dirs: print(f'{root} {name}') if (root.count('/') == gradeable_path_count): res = list(filter(lambda x: not 'json' in x, os.listdir(f'{root}/{name}'))) - print(res) - highest = int(max(res)) + 1 - #print(f'{root}/{name}/{highest}') + highest = int(max(res)) + 1 new_path = f'{root}/{name}/{highest}' os.mkdir(new_path) - shutil.copy2(f'assignments/{ci}.txt', f'{new_path}/{ci}.txt') + shutil.copy2(f'assignments/{files_in_assign[ci]}', f'{new_path}/{files_in_assign[ci]}') ci+=1 placed += 1 if(placed == num_to_place): From 2dc581954e7eb5789464abb02498885da024b537 Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Thu, 19 Mar 2020 12:25:37 -0400 Subject: [PATCH 4/9] fix install.sh --- install_lichen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_lichen.sh b/install_lichen.sh index 7f57eaa..8214bfe 100755 --- a/install_lichen.sh +++ b/install_lichen.sh @@ -65,7 +65,7 @@ cp ${lichen_repository_dir}/tokenizer/java/java_tokenizer.py ${lichen_installati cp ${lichen_repository_dir}/tokenizer/mips/mips_tokenizer.py ${lichen_installation_dir}/bin/mips_tokenizer.py cp ${lichen_repository_dir}/tokenizer/data.json ${lichen_installation_dir}/bin/data.json -cp ${lichen_repository_dir}/tools/* ${lichen_installation_dir}/tools +cp -rf ${lichen_repository_dir}/tools/* ${lichen_installation_dir}/tools ######################################################################################################################## # fix permissions From 5d5f6efa0fcac623f835d01205535d7f547e0f6f Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Tue, 24 Mar 2020 14:58:40 -0400 Subject: [PATCH 5/9] update assignment_placer --- install_lichen.sh | 3 +-- tools/assignmentPlacer.py | 28 -------------------------- tools/assignment_placer.py | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 30 deletions(-) delete mode 100644 tools/assignmentPlacer.py create mode 100644 tools/assignment_placer.py diff --git a/install_lichen.sh b/install_lichen.sh index 8214bfe..328b13e 100755 --- a/install_lichen.sh +++ b/install_lichen.sh @@ -30,8 +30,7 @@ fi # compile & install the tools mkdir -p ${lichen_installation_dir}/bin -mkdir -p ${lichen_installation_dir}/tools - +mkdir -p ${lichen_installation_dir}/tools/assignments #-------------------- # plaintext tool diff --git a/tools/assignmentPlacer.py b/tools/assignmentPlacer.py deleted file mode 100644 index 73e7cf7..0000000 --- a/tools/assignmentPlacer.py +++ /dev/null @@ -1,28 +0,0 @@ -import os, sys -import shutil - -gradeable_path = '/var/local/submitty/courses/s20/sample/submissions/grades_released_homework_autohiddenEC' - -if __name__ == "__main__": - if not os.path.isdir('assignments') or not os.path.isdir(gradeable_path): - print('The assignments directory or the gradeable does not exist. Please create these.') - sys.exit(1) - - files_in_assign = os.listdir('assignments') - num_to_place = min(len(os.listdir(gradeable_path)), len(files_in_assign)) - placed = 0 - ci = 0 - gradeable_path_count = gradeable_path.count('/') - for root, dirs, files in os.walk(gradeable_path): - for name in dirs: - print(f'{root} {name}') - if (root.count('/') == gradeable_path_count): - res = list(filter(lambda x: not 'json' in x, os.listdir(f'{root}/{name}'))) - highest = int(max(res)) + 1 - new_path = f'{root}/{name}/{highest}' - os.mkdir(new_path) - shutil.copy2(f'assignments/{files_in_assign[ci]}', f'{new_path}/{files_in_assign[ci]}') - ci+=1 - placed += 1 - if(placed == num_to_place): - sys.exit() diff --git a/tools/assignment_placer.py b/tools/assignment_placer.py new file mode 100644 index 0000000..336b132 --- /dev/null +++ b/tools/assignment_placer.py @@ -0,0 +1,40 @@ +import os +import argparse +import shutil +import secrets + +def getArgs(): + parser = argparse.ArgumentParser() + parser.add_argument("course", help="The course_id where assignments will be placed (i.e. sample).") + parser.add_argument("gradeable", help="The gradeable_id where assignments will be placed (i.e. grades_released_homework_autohiddenEC).") + args = parser.parse_args() + return args + +def generateHashPrefix(nbytes = 8): + return secrets.token_hex(nbytes) + +if __name__ == "__main__": + args = getArgs() + gradeable_path = f'/var/local/submitty/courses/s20/{args.course}/submissions/{args.gradeable}' + assignments_path = f'{os.path.dirname(os.path.realpath(__file__))}/assignments' + + if not os.path.isdir(assignments_path) or not os.path.isdir(gradeable_path): + raise SystemExit('The assignments directory or the gradeable does not exist. Please create those.') + + files_in_assign = os.listdir(assignments_path) + users_for_placement = os.listdir(gradeable_path) + num_to_place = min(len(users_for_placement)), len(files_in_assign)) + a_ind = 0 + + hash_prefix = generateHashPrefix() + for user_id in users_for_placement: + current_path = f'{gradeable_path}/{user_id}' + res = list(filter(lambda x: os.path.isdir(f'{current_path}/{x}'), os.listdir(current_path))) + highest = int(max(res)) + 1 + new_path = f'{current_path}/{highest}' + os.mkdir(new_path) + ext = os.path.splitext(files_in_assign[a_ind])[1] + shutil.copy2(f'assignments/{files_in_assign[a_ind]}', f'{new_path}/{hash_prefix}_{a_ind}{ext}') + a_ind += 1 + if(a_ind == num_to_place): + raise SystemExit From fc3ade292ead2095e536843636cce538394b2bdb Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Tue, 24 Mar 2020 15:00:21 -0400 Subject: [PATCH 6/9] tweaks --- tools/assignment_placer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/assignment_placer.py b/tools/assignment_placer.py index 336b132..b842e27 100644 --- a/tools/assignment_placer.py +++ b/tools/assignment_placer.py @@ -27,6 +27,7 @@ def generateHashPrefix(nbytes = 8): a_ind = 0 hash_prefix = generateHashPrefix() + print(f'Assignment prefix is: {hash_prefix} (regex: {hash_prefix}_*)') for user_id in users_for_placement: current_path = f'{gradeable_path}/{user_id}' res = list(filter(lambda x: os.path.isdir(f'{current_path}/{x}'), os.listdir(current_path))) From 3701c2f64019f4480446c459fc03e586709d31d8 Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Tue, 24 Mar 2020 15:23:17 -0400 Subject: [PATCH 7/9] small twekas --- tools/assignment_placer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/assignment_placer.py b/tools/assignment_placer.py index b842e27..2d3b17a 100644 --- a/tools/assignment_placer.py +++ b/tools/assignment_placer.py @@ -5,6 +5,7 @@ def getArgs(): parser = argparse.ArgumentParser() + parser.add_argument("semester", help="The semester_id where assignments will be placed (i.e. s20).") parser.add_argument("course", help="The course_id where assignments will be placed (i.e. sample).") parser.add_argument("gradeable", help="The gradeable_id where assignments will be placed (i.e. grades_released_homework_autohiddenEC).") args = parser.parse_args() @@ -23,7 +24,7 @@ def generateHashPrefix(nbytes = 8): files_in_assign = os.listdir(assignments_path) users_for_placement = os.listdir(gradeable_path) - num_to_place = min(len(users_for_placement)), len(files_in_assign)) + num_to_place = min(len(users_for_placement), len(files_in_assign)) a_ind = 0 hash_prefix = generateHashPrefix() @@ -31,7 +32,7 @@ def generateHashPrefix(nbytes = 8): for user_id in users_for_placement: current_path = f'{gradeable_path}/{user_id}' res = list(filter(lambda x: os.path.isdir(f'{current_path}/{x}'), os.listdir(current_path))) - highest = int(max(res)) + 1 + highest = len(res) + 1 new_path = f'{current_path}/{highest}' os.mkdir(new_path) ext = os.path.splitext(files_in_assign[a_ind])[1] From 9b093aa6d3020363692e940e415d01c1bd6404a0 Mon Sep 17 00:00:00 2001 From: Andrew Aikens Date: Tue, 24 Mar 2020 16:27:58 -0400 Subject: [PATCH 8/9] fix hardcode semester --- tools/assignment_placer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/assignment_placer.py b/tools/assignment_placer.py index 2d3b17a..488b9e0 100644 --- a/tools/assignment_placer.py +++ b/tools/assignment_placer.py @@ -16,7 +16,7 @@ def generateHashPrefix(nbytes = 8): if __name__ == "__main__": args = getArgs() - gradeable_path = f'/var/local/submitty/courses/s20/{args.course}/submissions/{args.gradeable}' + gradeable_path = f'/var/local/submitty/courses/{args.semester}/{args.course}/submissions/{args.gradeable}' assignments_path = f'{os.path.dirname(os.path.realpath(__file__))}/assignments' if not os.path.isdir(assignments_path) or not os.path.isdir(gradeable_path): From deda325357364757a8c264456444cdfd41265420 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 24 Mar 2020 20:34:34 -0400 Subject: [PATCH 9/9] Update assignment_placer.py --- tools/assignment_placer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/assignment_placer.py b/tools/assignment_placer.py index 488b9e0..09e599d 100644 --- a/tools/assignment_placer.py +++ b/tools/assignment_placer.py @@ -38,5 +38,5 @@ def generateHashPrefix(nbytes = 8): ext = os.path.splitext(files_in_assign[a_ind])[1] shutil.copy2(f'assignments/{files_in_assign[a_ind]}', f'{new_path}/{hash_prefix}_{a_ind}{ext}') a_ind += 1 - if(a_ind == num_to_place): - raise SystemExit + if a_ind == num_to_place: + break