8
8
import os
9
9
import json
10
10
import sys
11
+ import shutil
11
12
import fnmatch
12
13
13
14
CONFIG_PATH = os .path .join (os .path .dirname (os .path .realpath (__file__ )), '..' , '..' , 'config' )
@@ -71,13 +72,8 @@ def main():
71
72
if not os .path .isdir (my_concatenated_dir ):
72
73
os .makedirs (my_concatenated_dir )
73
74
my_concatenated_file = os .path .join (my_concatenated_dir ,"submission.concatenated" )
75
+ total_concat = 0
74
76
with open (my_concatenated_file ,'w' ) as my_cf :
75
- # print a brief header of information
76
- my_cf .write ("SEMESTER: " + semester + "\n " )
77
- my_cf .write ("COURSE: " + course + "\n " )
78
- my_cf .write ("GRADEABLE: " + gradeable + "\n " )
79
- my_cf .write ("USER: " + user + "\n " )
80
- my_cf .write ("VERSION: " + version + "\n " )
81
77
# loop over all files in all subdirectories
82
78
base_path = os .path .join (submission_dir ,user ,version )
83
79
for my_dir ,dirs ,my_files in os .walk (base_path ):
@@ -88,19 +84,24 @@ def main():
88
84
for e in expressions :
89
85
files_filtered .extend (fnmatch .filter (files , e .strip ()))
90
86
files = files_filtered
87
+ total_concat += len (files )
91
88
for my_file in files :
92
89
# skip the timestep
93
90
if my_file == ".submit.timestamp" :
94
91
continue
95
92
absolute_path = os .path .join (my_dir ,my_file )
96
93
relative_path = absolute_path [len (base_path ):]
97
94
# print a separator & filename
98
- my_cf .write ("----------------------------------------------------\n " )
99
- my_cf .write ("FILE: " + relative_path + "\n \n " )
100
95
with open (absolute_path , encoding = 'ISO-8859-1' ) as tmp :
101
96
# append the contents of the file
102
97
my_cf .write (tmp .read ())
103
- my_cf .write ("\n " )
98
+ # Remove concat file if there no content...
99
+ if total_concat == 0 :
100
+ os .remove (my_concatenated_file )
101
+ p2 = os .path .join (course_dir , "lichen" , "tokenized" , gradeable , user , version )
102
+ if os .path .isdir (p2 ):
103
+ shutil .rmtree (p2 )
104
+ os .rmdir (my_concatenated_dir )
104
105
105
106
print ("done" )
106
107
0 commit comments