diff --git a/travis/git_submodule_update.py b/travis/git_submodule_update.py index f5b582f6643..c3e0299249c 100755 --- a/travis/git_submodule_update.py +++ b/travis/git_submodule_update.py @@ -22,7 +22,9 @@ os.system('git submodule init') for sub in Repo('.').submodules: - if sub.path not in private_repos: + print "Getting submodule %s" % sub.path + use_archive = sub.path not in private_repos + if use_archive: url = sub.url if url.startswith('git@github.com:'): url = url.replace('git@github.com:', 'https://github.com/') @@ -31,11 +33,24 @@ url = url[:-4] archive_url = "%s/archive/%s.zip" % (url, sub.hexsha) urlretrieve(archive_url, ZIP_PATH) - with zipfile.ZipFile(ZIP_PATH) as zf: - zf.extractall(DL_DIR) - os.remove(ZIP_PATH) - os.removedirs(sub.path) - submodule_dir = os.listdir(DL_DIR)[0] - shutil.move(os.path.join(DL_DIR, submodule_dir), sub.path) - else: + try: + with zipfile.ZipFile(ZIP_PATH) as zf: + zf.extractall(DL_DIR) + except zf.BadZipfile: + # fall back to standard download + use_archive = False + with open(ZIP_PATH) as f: + print ("Getting archive failed with error %s. Falling back to " + "git clone." % f.read()) + os.remove(ZIP_PATH) + except Exception as e: + use_archive = False + print ("Getting archive failed with error %s. Falling back to " + "git clone." % e.message) + else: + os.remove(ZIP_PATH) + os.removedirs(sub.path) + submodule_dir = os.listdir(DL_DIR)[0] + shutil.move(os.path.join(DL_DIR, submodule_dir), sub.path) + if not use_archive: os.system('git submodule update %s' % sub.path)