mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6564 from dumganhar/v3
Updates download-dep.py, linux, mac and windows work ok
This commit is contained in:
commit
81ced0fc9f
|
@ -14,7 +14,10 @@ import os.path,zipfile
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
import distutils
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
from distutils.errors import DistutilsError
|
||||||
|
from distutils.dir_util import copy_tree, remove_tree
|
||||||
|
|
||||||
prefix = 'https://codeload.github.com/minggo/cocos2d-x-resources/zip/'
|
prefix = 'https://codeload.github.com/minggo/cocos2d-x-resources/zip/'
|
||||||
filename = 'cocos2d-x-deps-v3-1'
|
filename = 'cocos2d-x-deps-v3-1'
|
||||||
|
@ -41,40 +44,69 @@ def download_file(url, file_name):
|
||||||
#print(status),
|
#print(status),
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def unzip(src,dst):
|
def default_filter(src,dst):
|
||||||
zf = zipfile.ZipFile(src)
|
"""The default progress/filter callback; returns True for all files"""
|
||||||
for file in zf.filelist:
|
return dst
|
||||||
name = file.filename
|
|
||||||
perm = ((file.external_attr >> 16L) & 0777)
|
|
||||||
|
|
||||||
|
def ensure_directory(target):
|
||||||
|
if not os.path.exists(target):
|
||||||
|
os.mkdir(target)
|
||||||
|
|
||||||
|
def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):
|
||||||
|
"""Unpack zip `filename` to `extract_dir`
|
||||||
|
|
||||||
|
Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined
|
||||||
|
by ``zipfile.is_zipfile()``). See ``unpack_archive()`` for an explanation
|
||||||
|
of the `progress_filter` argument.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not zipfile.is_zipfile(filename):
|
||||||
|
raise UnrecognizedFormat("%s is not a zip file" % (filename,))
|
||||||
|
|
||||||
|
z = zipfile.ZipFile(filename)
|
||||||
|
try:
|
||||||
|
for info in z.infolist():
|
||||||
|
name = info.filename
|
||||||
|
|
||||||
|
# don't extract absolute paths or ones with .. in them
|
||||||
|
if name.startswith('/') or '..' in name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
target = os.path.join(extract_dir, *name.split('/'))
|
||||||
|
target = progress_filter(name, target)
|
||||||
|
if not target:
|
||||||
|
continue
|
||||||
if name.endswith('/'):
|
if name.endswith('/'):
|
||||||
outfile = os.path.join(dst, name)
|
# directory
|
||||||
if not os.path.exists(outfile):
|
ensure_directory(target)
|
||||||
os.mkdir(outfile, perm)
|
|
||||||
else:
|
else:
|
||||||
outfile = os.path.join(dst, name)
|
# file
|
||||||
fh = os.open(outfile, os.O_CREAT | os.O_WRONLY, perm)
|
ensure_directory(target)
|
||||||
os.write(fh, zf.read(name))
|
data = z.read(info.filename)
|
||||||
os.close(fh)
|
f = open(target,'wb')
|
||||||
zf.close()
|
try:
|
||||||
|
f.write(data)
|
||||||
def copy_files(src, dst):
|
finally:
|
||||||
for item in os.listdir(src):
|
f.close()
|
||||||
path = os.path.join(src, item)
|
del data
|
||||||
if os.path.isfile(path):
|
unix_attributes = info.external_attr >> 16
|
||||||
shutil.copy(path, dst)
|
if unix_attributes:
|
||||||
elif os.path.isdir(path):
|
os.chmod(target, unix_attributes)
|
||||||
new_dst = os.path.join(dst, item)
|
finally:
|
||||||
if not os.path.exists(new_dst):
|
z.close()
|
||||||
os.mkdir(new_dst)
|
|
||||||
copy_files(path, new_dst)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
download_file(prefix+filename, filename+'.zip')
|
download_file(prefix+filename, filename+'.zip')
|
||||||
workpath = os.path.dirname(os.path.realpath(__file__))
|
workpath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
if os.path.exists(extracted_folder_name):
|
||||||
|
shutil.rmtree(extracted_folder_name)
|
||||||
|
|
||||||
print("Extracting files, please wait ...")
|
print("Extracting files, please wait ...")
|
||||||
unzip(filename+'.zip', workpath)
|
unpack_zipfile(filename+'.zip', workpath)
|
||||||
copy_files(extracted_folder_name, workpath)
|
print("Extraction done!")
|
||||||
|
print("Copying files ...")
|
||||||
|
distutils.dir_util.copy_tree(extracted_folder_name, workpath)
|
||||||
print("Cleaning ...")
|
print("Cleaning ...")
|
||||||
if os.path.isfile(filename+'.zip'):
|
if os.path.isfile(filename+'.zip'):
|
||||||
os.remove(filename+'.zip')
|
os.remove(filename+'.zip')
|
||||||
|
|
Loading…
Reference in New Issue