Skip to content

Commit 7d7a25a

Browse files
[Tools] Adds assignment placer to place files in pre-existing submissions (#20)
* Tools * fixed * assign Placer tweak * fix install.sh * update assignment_placer * tweaks * small twekas * fix hardcode semester * Update assignment_placer.py Co-authored-by: Matthew Peveler <[email protected]>
1 parent c0fdcaa commit 7d7a25a

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*~
1+
*~
2+
tools/assignments/*

install_lichen.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fi
3030
# compile & install the tools
3131

3232
mkdir -p ${lichen_installation_dir}/bin
33-
33+
mkdir -p ${lichen_installation_dir}/tools/assignments
3434

3535
#--------------------
3636
# plaintext tool
@@ -64,6 +64,7 @@ cp ${lichen_repository_dir}/tokenizer/java/java_tokenizer.py ${lichen_installati
6464
cp ${lichen_repository_dir}/tokenizer/mips/mips_tokenizer.py ${lichen_installation_dir}/bin/mips_tokenizer.py
6565
cp ${lichen_repository_dir}/tokenizer/data.json ${lichen_installation_dir}/bin/data.json
6666

67+
cp -rf ${lichen_repository_dir}/tools/* ${lichen_installation_dir}/tools
6768

6869
########################################################################################################################
6970
# fix permissions

tools/assignment_placer.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import argparse
3+
import shutil
4+
import secrets
5+
6+
def getArgs():
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("semester", help="The semester_id where assignments will be placed (i.e. s20).")
9+
parser.add_argument("course", help="The course_id where assignments will be placed (i.e. sample).")
10+
parser.add_argument("gradeable", help="The gradeable_id where assignments will be placed (i.e. grades_released_homework_autohiddenEC).")
11+
args = parser.parse_args()
12+
return args
13+
14+
def generateHashPrefix(nbytes = 8):
15+
return secrets.token_hex(nbytes)
16+
17+
if __name__ == "__main__":
18+
args = getArgs()
19+
gradeable_path = f'/var/local/submitty/courses/{args.semester}/{args.course}/submissions/{args.gradeable}'
20+
assignments_path = f'{os.path.dirname(os.path.realpath(__file__))}/assignments'
21+
22+
if not os.path.isdir(assignments_path) or not os.path.isdir(gradeable_path):
23+
raise SystemExit('The assignments directory or the gradeable does not exist. Please create those.')
24+
25+
files_in_assign = os.listdir(assignments_path)
26+
users_for_placement = os.listdir(gradeable_path)
27+
num_to_place = min(len(users_for_placement), len(files_in_assign))
28+
a_ind = 0
29+
30+
hash_prefix = generateHashPrefix()
31+
print(f'Assignment prefix is: {hash_prefix} (regex: {hash_prefix}_*)')
32+
for user_id in users_for_placement:
33+
current_path = f'{gradeable_path}/{user_id}'
34+
res = list(filter(lambda x: os.path.isdir(f'{current_path}/{x}'), os.listdir(current_path)))
35+
highest = len(res) + 1
36+
new_path = f'{current_path}/{highest}'
37+
os.mkdir(new_path)
38+
ext = os.path.splitext(files_in_assign[a_ind])[1]
39+
shutil.copy2(f'assignments/{files_in_assign[a_ind]}', f'{new_path}/{hash_prefix}_{a_ind}{ext}')
40+
a_ind += 1
41+
if a_ind == num_to_place:
42+
break

0 commit comments

Comments
 (0)