51
51
from distutils .errors import DistutilsError
52
52
from distutils .dir_util import copy_tree , remove_tree
53
53
54
- def execute_command (cmd ):
55
- if os .system (cmd ) != 0 :
56
- raise Exception ('Command ( %s ) failed!' % cmd )
54
+
55
+ def delete_folder_except (folder_path , excepts ):
56
+ """
57
+ Delete a folder excepts some files/subfolders, `excepts` doesn't recursively which means it can not include
58
+ `subfoler/file1`. `excepts` is an array.
59
+ """
60
+ for file in os .listdir (folder_path ):
61
+ if (file in excepts ):
62
+ continue
63
+
64
+ full_path = os .path .join (folder_path , file )
65
+ if os .path .isdir (full_path ):
66
+ shutil .rmtree (full_path )
67
+ else :
68
+ os .remove (full_path )
69
+
57
70
58
71
class UnrecognizedFormat :
59
72
def __init__ (self , prompt ):
@@ -242,9 +255,10 @@ def load_json_file(self, file_path):
242
255
data = json .load (data_file )
243
256
return data
244
257
245
- def clean_external_folder (self ):
258
+ def clean_external_folder (self , external_folder ):
246
259
print ('==> Cleaning cocos2d-x/external folder ...' )
247
- execute_command ('git clean -fdx external' )
260
+ # remove external except 'config.json'
261
+ delete_folder_except (external_folder , ['config.json' ])
248
262
249
263
def run (self , workpath , folder_for_extracting , remove_downloaded , force_update , download_only ):
250
264
if not force_update and not self .need_to_update ():
@@ -262,7 +276,7 @@ def run(self, workpath, folder_for_extracting, remove_downloaded, force_update,
262
276
if not os .path .exists (folder_for_extracting ):
263
277
os .mkdir (folder_for_extracting )
264
278
265
- self .clean_external_folder ()
279
+ self .clean_external_folder (folder_for_extracting )
266
280
print ("==> Copying files..." )
267
281
distutils .dir_util .copy_tree (self ._extracted_folder_name , folder_for_extracting )
268
282
if self ._move_dirs is not None :
0 commit comments