10
10
import sys
11
11
import time
12
12
import fnmatch
13
+ from pathlib import Path
13
14
14
15
IGNORED_FILES = [
15
16
".submit.timestamp"
@@ -35,7 +36,7 @@ def getConcatFilesInDir(input_dir, regex_patterns):
35
36
absolute_path = os .path .join (my_dir , my_file )
36
37
# print a separator & filename
37
38
with open (absolute_path , encoding = 'ISO-8859-1' ) as tmp :
38
- result += f"=============== { my_file } =========== ====\n "
39
+ result += f"==== { my_file } ====\n "
39
40
# append the contents of the file
40
41
result += tmp .read () + "\n "
41
42
return result
@@ -70,6 +71,7 @@ def main():
70
71
users_to_ignore = config ["ignore_submissions" ]
71
72
regex_patterns = config ["regex" ].split (',' )
72
73
regex_dirs = config ["regex_dirs" ]
74
+ prior_term_gradeables = config ["prior_term_gradeables" ]
73
75
74
76
# ==========================================================================
75
77
# Error checking
@@ -80,6 +82,22 @@ def main():
80
82
print ('ERROR! Invalid path component ".." in regex' )
81
83
exit (1 )
82
84
85
+ for ptg in prior_term_gradeables :
86
+ for field in ptg :
87
+ if ".." in field :
88
+ print ('ERROR! Invalid path component ".." in prior_term_gradeable field' )
89
+ exit (1 )
90
+
91
+ # check permissions to make sure we have access to the prior term gradeables
92
+ my_course_group_perms = Path (args .basepath ).group ()
93
+ for ptg in prior_term_gradeables :
94
+ if Path (args .datapath , ptg ["prior_semester" ], ptg ["prior_course" ]).group ()\
95
+ != my_course_group_perms :
96
+ print (f"Error: Invalid permissions to access course { ptg ['prior_semester' ]} "
97
+ f"/{ ptg ['prior_course' ]} " )
98
+ exit (1 )
99
+
100
+ # make sure the regex directory is one of the acceptable directories
83
101
for dir in regex_dirs :
84
102
if dir not in ["submissions" , "results" , "checkout" ]:
85
103
print ("ERROR! " , dir , " is not a valid input directory for Lichen" )
@@ -124,6 +142,50 @@ def main():
124
142
concatenated_contents = getConcatFilesInDir (version_path , regex_patterns )
125
143
output_file .write (concatenated_contents )
126
144
145
+ # ==========================================================================
146
+ # loop over all of the other prior term gradeables and concatenate their submissions
147
+ for other_gradeable in prior_term_gradeables :
148
+ for dir in regex_dirs :
149
+ other_gradeable_path = os .path .join (args .datapath ,
150
+ other_gradeable ["prior_semester" ],
151
+ other_gradeable ["prior_course" ],
152
+ dir ,
153
+ other_gradeable ["prior_gradeable" ])
154
+ # loop over each user
155
+ for other_user in sorted (os .listdir (other_gradeable_path )):
156
+ other_user_path = os .path .join (other_gradeable_path , other_user )
157
+ if not os .path .isdir (other_user_path ):
158
+ continue
159
+
160
+ if version_mode == "active_version" :
161
+ # get the user's active version from their settings file
162
+ other_submissions_details_path = os .path .join (other_user_path ,
163
+ 'user_assignment_settings.json' )
164
+
165
+ with open (other_submissions_details_path ) as other_details_file :
166
+ other_details_json = json .load (other_details_file )
167
+ my_active_version = int (other_details_json ["active_version" ])
168
+
169
+ # loop over each version
170
+ for other_version in sorted (os .listdir (other_user_path )):
171
+ other_version_path = os .path .join (other_user_path , other_version )
172
+ if not os .path .isdir (other_version_path ):
173
+ continue
174
+
175
+ other_output_file_path = os .path .join (args .basepath , "other_gradeables" ,
176
+ f"{ other_gradeable ['prior_semester' ]} __{ other_gradeable ['prior_course' ]} __{ other_gradeable ['prior_gradeable' ]} " , # noqa: E501
177
+ other_user , other_version ,
178
+ "submission.concatenated" )
179
+
180
+ if not os .path .exists (os .path .dirname (other_output_file_path )):
181
+ os .makedirs (os .path .dirname (other_output_file_path ))
182
+
183
+ # append to concatenated file
184
+ with open (other_output_file_path , "a" ) as other_output_file :
185
+ other_concatenated_contents = getConcatFilesInDir (other_version_path ,
186
+ regex_patterns )
187
+ other_output_file .write (other_concatenated_contents )
188
+
127
189
# ==========================================================================
128
190
# iterate over all of the created submissions, checking to see if they are empty
129
191
# and adding a message to the top if so (to differentiate empty files from errors in the UI)
@@ -136,6 +198,21 @@ def main():
136
198
if my_cf .read () == "" :
137
199
my_cf .write ("Error: No files matched provided regex in selected directories" )
138
200
201
+ # do the same for the other gradeables
202
+ for other_gradeable in prior_term_gradeables :
203
+ other_gradeable_dir_name = f"{ other_gradeable ['prior_semester' ]} __{ other_gradeable ['prior_course' ]} __{ other_gradeable ['prior_gradeable' ]} " # noqa: E501
204
+ for other_user in os .listdir (os .path .join (args .basepath , "other_gradeables" ,
205
+ other_gradeable_dir_name )):
206
+ other_user_path = os .path .join (args .basepath , "other_gradeables" ,
207
+ other_gradeable_dir_name , other_user )
208
+ for other_version in os .listdir (other_user_path ):
209
+ other_version_path = os .path .join (other_user_path , other_version )
210
+ my_concatenated_file = os .path .join (other_version_path , "submission.concatenated" )
211
+ with open (my_concatenated_file , "r+" ) as my_cf :
212
+ if my_cf .read () == "" :
213
+ my_cf .write ("Error: No files matched provided regex in"
214
+ "selected directories" )
215
+
139
216
# ==========================================================================
140
217
# concatenate provided code
141
218
with open (os .path .join (args .basepath , "provided_code" ,
0 commit comments