Skip to content

Commit 7fe4196

Browse files
author
minggo
authored
do not use git command (#17677)
the script may be used in a folder that is not a git repo
1 parent 56ae741 commit 7fe4196

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

download-deps.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,22 @@
5151
from distutils.errors import DistutilsError
5252
from distutils.dir_util import copy_tree, remove_tree
5353

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+
5770

5871
class UnrecognizedFormat:
5972
def __init__(self, prompt):
@@ -242,9 +255,10 @@ def load_json_file(self, file_path):
242255
data = json.load(data_file)
243256
return data
244257

245-
def clean_external_folder(self):
258+
def clean_external_folder(self, external_folder):
246259
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'])
248262

249263
def run(self, workpath, folder_for_extracting, remove_downloaded, force_update, download_only):
250264
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,
262276
if not os.path.exists(folder_for_extracting):
263277
os.mkdir(folder_for_extracting)
264278

265-
self.clean_external_folder()
279+
self.clean_external_folder(folder_for_extracting)
266280
print("==> Copying files...")
267281
distutils.dir_util.copy_tree(self._extracted_folder_name, folder_for_extracting)
268282
if self._move_dirs is not None:

0 commit comments

Comments
 (0)