113 def clean_epocroot(): |
113 def clean_epocroot(): |
114 """ |
114 """ |
115 This method walks through epocroot and cleans every file and folder that is |
115 This method walks through epocroot and cleans every file and folder that is |
116 not present in the manifest file |
116 not present in the manifest file |
117 """ |
117 """ |
118 print "Cleaning Epocroot..." |
118 epocroot = os.path.abspath(os.environ['EPOCROOT']).replace('\\','/') |
|
119 print "Cleaning Epocroot: %s" % epocroot |
119 all_files = {} # dictionary to hold all files |
120 all_files = {} # dictionary to hold all files |
120 folders = [] # holds all unique folders in manifest |
121 folders = [] # holds all unique folders in manifest |
121 host_platform = os.environ["HOSTPLATFORM_DIR"] |
122 host_platform = os.environ["HOSTPLATFORM_DIR"] |
122 try: |
123 try: |
123 mani = "./epocroot/manifest" |
124 mani = "$(EPOCROOT)/manifest" |
124 manifest = open(ReplaceEnvs(mani), "r") |
125 manifest = open(ReplaceEnvs(mani), "r") |
|
126 le = len(epocroot) |
125 for line in manifest: |
127 for line in manifest: |
126 line = line.replace("$(HOSTPLATFORM_DIR)", host_platform) |
128 line = line.replace("$(HOSTPLATFORM_DIR)", host_platform) |
|
129 line = line.replace("./", epocroot+"/").rstrip("\n") |
127 # Get rid of newline char and add to dictionary |
130 # Get rid of newline char and add to dictionary |
128 all_files[line.rstrip("\n")] = True |
131 all_files[line] = True |
129 # This bit makes a record of unique folders into a list |
132 # This bit makes a record of unique folders into a list |
130 end = 0 |
133 pos = line.rfind("/", le) |
131 while end != -1: # Look through the parent folders |
134 while pos > le: # Look through the parent folders |
132 end = line.rfind("/") |
135 f = line[:pos] |
133 line = line[:end] |
136 if f not in folders: |
134 if line not in folders: |
137 folders.append(f) |
135 folders.append(line) |
138 pos = line.rfind("/", le, pos) |
|
139 |
|
140 |
136 # This algorithm walks through epocroot and handles files and folders |
141 # This algorithm walks through epocroot and handles files and folders |
137 walkpath = "./epocroot" |
142 walkpath = "$(EPOCROOT)" |
138 for (root, dirs, files) in os.walk(ReplaceEnvs(walkpath), topdown = |
143 for (root, dirs, files) in os.walk(ReplaceEnvs(walkpath), topdown = |
139 False): |
144 False): |
|
145 if root.find(".hg") != -1: |
|
146 continue |
|
147 |
140 # This loop handles all files |
148 # This loop handles all files |
141 for name in files: |
149 for name in files: |
142 name = os.path.join(root, name).replace("\\", "/") |
150 name = os.path.join(root, name).replace("\\", "/") |
143 name = name.replace("./epocroot/", "./") |
|
144 |
151 |
145 if name not in all_files: |
152 if name not in all_files: |
146 try: |
153 try: |
147 name = ReplaceEnvs(name.replace("./", "./epocroot/")) |
|
148 os.remove(name) |
154 os.remove(name) |
149 except: |
155 except: |
150 # chmod to rw and try again |
156 # chmod to rw and try again |
151 try: |
157 try: |
152 os.chmod(name, stat.S_IRWXU) |
158 os.chmod(name, stat.S_IRWXU) |
158 traceback.print_tb(sys.exc_traceback) |
164 traceback.print_tb(sys.exc_traceback) |
159 |
165 |
160 # This loop handles folders |
166 # This loop handles folders |
161 for name in dirs: |
167 for name in dirs: |
162 name = os.path.join(root, name).replace("\\", "/") |
168 name = os.path.join(root, name).replace("\\", "/") |
163 name = name.replace("./epocroot/", "./") |
|
164 if name not in all_files and name not in folders: |
169 if name not in all_files and name not in folders: |
165 # Remove the folder fully with no errors if full |
170 # Remove the folder fully with no errors if full |
166 try: |
171 try: |
167 rmtree(ReplaceEnvs(name.replace("./", "./epocroot/"))) |
172 rmtree(ReplaceEnvs(name)) |
168 except: |
173 except: |
169 print "\nEPOCROOT-CLEAN ERROR:" |
174 print "\nEPOCROOT-CLEAN ERROR:" |
170 print (sys.exc_type.__name__ + ":"), \ |
175 print (sys.exc_type.__name__ + ":"), \ |
171 sys.exc_value, "\n", \ |
176 sys.exc_value, "\n", \ |
172 traceback.print_tb(sys.exc_traceback) |
177 traceback.print_tb(sys.exc_traceback) |