From 8b545383e75cd9aaaf85c1207315267b030ae2f1 Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Fri, 6 May 2016 11:18:22 +0200 Subject: [PATCH] Gitlab and Gogs source for updates --- update.py | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/update.py b/update.py index 0e2afc62..fb7258e6 100644 --- a/update.py +++ b/update.py @@ -14,15 +14,36 @@ monkey.patch_all() def update(): from src.util import helper - print "Downloading.", - req = helper.httpRequest("https://github.com/HelloZeroNet/ZeroNet/archive/master.zip") - data = StringIO.StringIO() - while True: - buff = req.read(1024 * 16) - if not buff: - break - data.write(buff) - print ".", + urls = [ + "https://github.com/HelloZeroNet/ZeroNet/archive/master.zip", + "https://gitlab.com/HelloZeroNet/ZeroNet/repository/archive.zip?ref=master", + "https://try.gogs.io/ZeroNet/ZeroNet/archive/master.zip" + ] + + zipdata = None + for url in urls: + print "Downloading from:", url, + try: + req = helper.httpRequest(url) + data = StringIO.StringIO() + while True: + buff = req.read(1024 * 16) + if not buff: + break + data.write(buff) + print ".", + try: + zipdata = zipfile.ZipFile(data) + break # Success + except Exception, err: + data.seek(0) + print "Unpack error", err, data.read(256) + except Exception, err: + print "Error downloading update from %s: %s" % (url, err) + + if not zipdata: + raise err + print "Downloaded." # Checking plugins @@ -37,18 +58,13 @@ def update(): print "Plugins enabled:", plugins_enabled, "disabled:", plugins_disabled print "Extracting...", - try: - zip = zipfile.ZipFile(data) - except Exception, err: - data.seek(0) - print "Unpack error", err, data.read() - return False - for inner_path in zip.namelist(): + for inner_path in zipdata.namelist(): if ".." in inner_path: continue inner_path = inner_path.replace("\\", "/") # Make sure we have unix path print ".", - dest_path = inner_path.replace("ZeroNet-master/", "") + dest_path = re.sub("^[^/]*-master.*?/", "", inner_path) # Skip root zeronet-master-... like directories + dest_path = dest_path.lstrip("/") if not dest_path: continue @@ -68,7 +84,7 @@ def update(): os.makedirs(dest_dir) if dest_dir != dest_path.strip("/"): - data = zip.read(inner_path) + data = zipdata.read(inner_path) try: open(dest_path, 'wb').write(data) except Exception, err: