@@ -44,30 +44,34 @@ def main():
4444 regex_expressions = lichen_config_data ["regex" ].split (',' )
4545 regex_dirs = lichen_config_data ["regex_dirs" ]
4646
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+
4754 for e in regex_expressions :
4855 # Check for backwards crawling
4956 if ".." in e :
5057 print ('ERROR! Invalid path component ".." in regex' )
5158 exit (1 )
5259
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 )
5964
60- # =========================================================================
65+ # ==========================================================================
6166 # create the directory
6267 concatenated_dir = os .path .join (course_dir , "lichen" , "concatenated" , gradeable )
6368 if not os .path .isdir (concatenated_dir ):
6469 os .makedirs (concatenated_dir )
6570
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
7073
74+ for dir in regex_dirs :
7175 submission_dir = os .path .join (course_dir , dir , gradeable )
7276
7377 # more error checking
@@ -85,15 +89,13 @@ def main():
8589 continue
8690
8791 # -----------------------------------------------------------------
88- # concatenate all files for this submisison into a single file
92+ # concatenate all files for this submissison into a single file
8993 my_concatenated_dir = os .path .join (concatenated_dir , user , version )
9094 if not os .path .isdir (my_concatenated_dir ):
9195 os .makedirs (my_concatenated_dir )
9296 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 :
9799 # loop over all files in all subdirectories
98100 base_path = os .path .join (submission_dir , user , version )
99101 for my_dir , _dirs , my_files in os .walk (base_path ):
@@ -106,28 +108,30 @@ def main():
106108 files_filtered .extend (fnmatch .filter (files , e .strip ()))
107109 files = files_filtered
108110
109- total_concat += len (files )
110111 for my_file in files :
111112 # exclude any files we have ignored for all submissions
112113 if my_file in IGNORED_FILES :
113114 continue
114115 absolute_path = os .path .join (my_dir , my_file )
115116 # print a separator & filename
116- my_cf .write (f"==========={ my_file } ===========\n " )
117+ my_cf .write (f"=============== { my_file } ==== ===========\n " )
117118 with open (absolute_path , encoding = 'ISO-8859-1' ) as tmp :
118119 # append the contents of the file
119120 my_cf .write (tmp .read ())
120121 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+ # ==========================================================================
131135 # concatenate any files in the provided_code directory
132136 provided_code_path = os .path .join (course_dir , "lichen" , "provided_code" , gradeable )
133137 output_dir = os .path .join (course_dir , "lichen" , "concatenated" ,
@@ -147,7 +151,9 @@ def main():
147151 # append the contents of the file
148152 of .write (tmp .read ())
149153
154+ # ==========================================================================
150155 print ("done" )
156+ print (f"{ count_total_files } files concatenated" )
151157
152158
153159if __name__ == "__main__" :
0 commit comments