@@ -44,30 +44,34 @@ def main():
44
44
regex_expressions = lichen_config_data ["regex" ].split (',' )
45
45
regex_dirs = lichen_config_data ["regex_dirs" ]
46
46
47
+ # ==========================================================================
48
+ # error checking
49
+ course_dir = os .path .join (SUBMITTY_DATA_DIR , "courses" , semester , course )
50
+ if not os .path .isdir (course_dir ):
51
+ print ("ERROR! " , course_dir , " is not a valid course directory" )
52
+ exit (1 )
53
+
47
54
for e in regex_expressions :
48
55
# Check for backwards crawling
49
56
if ".." in e :
50
57
print ('ERROR! Invalid path component ".." in regex' )
51
58
exit (1 )
52
59
53
- # =========================================================================
54
- # error checking
55
- course_dir = os .path .join (SUBMITTY_DATA_DIR , "courses" , semester , course )
56
- if not os .path .isdir (course_dir ):
57
- print ("ERROR! " , course_dir , " is not a valid course directory" )
58
- exit (1 )
60
+ for dir in regex_dirs :
61
+ if dir not in ["submissions" , "results" , "checkout" ]:
62
+ print ("ERROR! " , dir , " is not a valid input directory for Lichen" )
63
+ exit (1 )
59
64
60
- # =========================================================================
65
+ # ==========================================================================
61
66
# create the directory
62
67
concatenated_dir = os .path .join (course_dir , "lichen" , "concatenated" , gradeable )
63
68
if not os .path .isdir (concatenated_dir ):
64
69
os .makedirs (concatenated_dir )
65
70
66
- for dir in regex_dirs :
67
- if dir not in ["submissions" , "results" , "checkout" ]:
68
- print ("ERROR! " , dir , " is not a valid input directory for Lichen" )
69
- exit (1 )
71
+ # ==========================================================================
72
+ count_total_files = 0
70
73
74
+ for dir in regex_dirs :
71
75
submission_dir = os .path .join (course_dir , dir , gradeable )
72
76
73
77
# more error checking
@@ -85,15 +89,13 @@ def main():
85
89
continue
86
90
87
91
# -----------------------------------------------------------------
88
- # concatenate all files for this submisison into a single file
92
+ # concatenate all files for this submissison into a single file
89
93
my_concatenated_dir = os .path .join (concatenated_dir , user , version )
90
94
if not os .path .isdir (my_concatenated_dir ):
91
95
os .makedirs (my_concatenated_dir )
92
96
my_concatenated_file = os .path .join (my_concatenated_dir , "submission.concatenated" )
93
- total_concat = 0
94
- with open (my_concatenated_file , 'a+' ) as my_cf :
95
- if len (my_cf .read ()) > 0 :
96
- total_concat = 1
97
+
98
+ with open (my_concatenated_file , 'a' ) as my_cf :
97
99
# loop over all files in all subdirectories
98
100
base_path = os .path .join (submission_dir , user , version )
99
101
for my_dir , _dirs , my_files in os .walk (base_path ):
@@ -106,28 +108,30 @@ def main():
106
108
files_filtered .extend (fnmatch .filter (files , e .strip ()))
107
109
files = files_filtered
108
110
109
- total_concat += len (files )
110
111
for my_file in files :
111
112
# exclude any files we have ignored for all submissions
112
113
if my_file in IGNORED_FILES :
113
114
continue
114
115
absolute_path = os .path .join (my_dir , my_file )
115
116
# print a separator & filename
116
- my_cf .write (f"==========={ my_file } ===========\n " )
117
+ my_cf .write (f"=============== { my_file } ==== ===========\n " )
117
118
with open (absolute_path , encoding = 'ISO-8859-1' ) as tmp :
118
119
# append the contents of the file
119
120
my_cf .write (tmp .read ())
120
121
my_cf .write ("\n " )
121
- # Remove concat file if there no content...
122
- if total_concat == 0 :
123
- os .remove (my_concatenated_file )
124
- # FIXME: is this the correct path?
125
- p2 = os .path .join (course_dir , "lichen" , "tokenized" , gradeable , user , version )
126
- if os .path .isdir (p2 ):
127
- shutil .rmtree (p2 )
128
- os .rmdir (my_concatenated_dir )
129
-
130
- # =========================================================================
122
+ count_total_files += 1
123
+ # ==========================================================================
124
+ # iterate over all of the created submissions, checking to see if they are
125
+ # and adding a message to the top if so (to differentiate empty files from errors in the UI)
126
+ for user in os .listdir (concatenated_dir ):
127
+ for version in os .listdir (os .path .join (concatenated_dir , user )):
128
+ my_concatenated_file = os .path .join (concatenated_dir ,
129
+ user , version , "submission.concatenated" )
130
+ with open (my_concatenated_file , "r+" ) as my_cf :
131
+ if my_cf .read () == "" :
132
+ my_cf .write ("Error: No files matched provided regex in selected directories" )
133
+
134
+ # ==========================================================================
131
135
# concatenate any files in the provided_code directory
132
136
provided_code_path = os .path .join (course_dir , "lichen" , "provided_code" , gradeable )
133
137
output_dir = os .path .join (course_dir , "lichen" , "concatenated" ,
@@ -147,7 +151,9 @@ def main():
147
151
# append the contents of the file
148
152
of .write (tmp .read ())
149
153
154
+ # ==========================================================================
150
155
print ("done" )
156
+ print (f"{ count_total_files } files concatenated" )
151
157
152
158
153
159
if __name__ == "__main__" :
0 commit comments