do not use git command (#17679)

the script may be used in a folder that is not a git repo
This commit is contained in:
minggo 2017-04-10 17:07:08 +08:00 committed by GitHub
parent 8acf8f84ed
commit 9c9fd875a4
1 changed files with 20 additions and 6 deletions

View File

@ -51,9 +51,22 @@ from sys import stdout
from distutils.errors import DistutilsError
from distutils.dir_util import copy_tree, remove_tree
def execute_command(cmd):
if os.system(cmd) != 0:
raise Exception('Command ( %s ) failed!' % cmd)
def delete_folder_except(folder_path, excepts):
"""
Delete a folder excepts some files/subfolders, `excepts` doesn't recursively which means it can not include
`subfoler/file1`. `excepts` is an array.
"""
for file in os.listdir(folder_path):
if (file in excepts):
continue
full_path = os.path.join(folder_path, file)
if os.path.isdir(full_path):
shutil.rmtree(full_path)
else:
os.remove(full_path)
class UnrecognizedFormat:
def __init__(self, prompt):
@ -242,9 +255,10 @@ class CocosZipInstaller(object):
data = json.load(data_file)
return data
def clean_external_folder(self):
def clean_external_folder(self, external_folder):
print('==> Cleaning cocos2d-x/external folder ...')
execute_command('git clean -fdx external')
# remove external except 'config.json'
delete_folder_except(external_folder, ['config.json'])
def run(self, workpath, folder_for_extracting, remove_downloaded, force_update, download_only):
if not force_update and not self.need_to_update():
@ -262,7 +276,7 @@ class CocosZipInstaller(object):
if not os.path.exists(folder_for_extracting):
os.mkdir(folder_for_extracting)
self.clean_external_folder()
self.clean_external_folder(folder_for_extracting)
print("==> Copying files...")
distutils.dir_util.copy_tree(self._extracted_folder_name, folder_for_extracting)
if self._move_dirs is not None: