forked from OCA/hr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fallback to standard cloning when github archive returns error 500
- Loading branch information
Showing
1 changed file
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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('[email protected]:'): | ||
url = url.replace('[email protected]:', '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) |