Gitlab and Gogs source for updates
This commit is contained in:
parent
ba24ad31d8
commit
8b545383e7
1 changed files with 34 additions and 18 deletions
52
update.py
52
update.py
|
@ -14,15 +14,36 @@ monkey.patch_all()
|
||||||
def update():
|
def update():
|
||||||
from src.util import helper
|
from src.util import helper
|
||||||
|
|
||||||
print "Downloading.",
|
urls = [
|
||||||
req = helper.httpRequest("https://github.com/HelloZeroNet/ZeroNet/archive/master.zip")
|
"https://github.com/HelloZeroNet/ZeroNet/archive/master.zip",
|
||||||
data = StringIO.StringIO()
|
"https://gitlab.com/HelloZeroNet/ZeroNet/repository/archive.zip?ref=master",
|
||||||
while True:
|
"https://try.gogs.io/ZeroNet/ZeroNet/archive/master.zip"
|
||||||
buff = req.read(1024 * 16)
|
]
|
||||||
if not buff:
|
|
||||||
break
|
zipdata = None
|
||||||
data.write(buff)
|
for url in urls:
|
||||||
print ".",
|
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."
|
print "Downloaded."
|
||||||
|
|
||||||
# Checking plugins
|
# Checking plugins
|
||||||
|
@ -37,18 +58,13 @@ def update():
|
||||||
print "Plugins enabled:", plugins_enabled, "disabled:", plugins_disabled
|
print "Plugins enabled:", plugins_enabled, "disabled:", plugins_disabled
|
||||||
|
|
||||||
print "Extracting...",
|
print "Extracting...",
|
||||||
try:
|
for inner_path in zipdata.namelist():
|
||||||
zip = zipfile.ZipFile(data)
|
|
||||||
except Exception, err:
|
|
||||||
data.seek(0)
|
|
||||||
print "Unpack error", err, data.read()
|
|
||||||
return False
|
|
||||||
for inner_path in zip.namelist():
|
|
||||||
if ".." in inner_path:
|
if ".." in inner_path:
|
||||||
continue
|
continue
|
||||||
inner_path = inner_path.replace("\\", "/") # Make sure we have unix path
|
inner_path = inner_path.replace("\\", "/") # Make sure we have unix path
|
||||||
print ".",
|
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:
|
if not dest_path:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -68,7 +84,7 @@ def update():
|
||||||
os.makedirs(dest_dir)
|
os.makedirs(dest_dir)
|
||||||
|
|
||||||
if dest_dir != dest_path.strip("/"):
|
if dest_dir != dest_path.strip("/"):
|
||||||
data = zip.read(inner_path)
|
data = zipdata.read(inner_path)
|
||||||
try:
|
try:
|
||||||
open(dest_path, 'wb').write(data)
|
open(dest_path, 'wb').write(data)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
|
|
Loading…
Reference in a new issue