From b66317fa7dd7d1d9653b641545be315e2a90547f Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sun, 4 Dec 2016 18:57:08 +0100 Subject: [PATCH] Rev1761, Update ZeroNet from ZeroNet network --- src/Config.py | 4 +++- update.py | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Config.py b/src/Config.py index 2b76c687..cdf6f3f0 100644 --- a/src/Config.py +++ b/src/Config.py @@ -9,7 +9,7 @@ class Config(object): def __init__(self, argv): self.version = "0.5.1" - self.rev = 1758 + self.rev = 1761 self.argv = argv self.action = None self.config_file = "zeronet.conf" @@ -146,6 +146,8 @@ class Config(object): nargs='?', const="default_browser", metavar='browser_name') self.parser.add_argument('--homepage', help='Web interface Homepage', default='1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D', metavar='address') + self.parser.add_argument('--updatesite', help='Source code update site', default='1UPDatEDxnvHDo7TXvq6AEBARfNkyfxsp', + metavar='address') self.parser.add_argument('--size_limit', help='Default site size limit in MB', default=10, type=int, metavar='size') self.parser.add_argument('--connected_limit', help='Max connected peer per site', default=10, type=int, metavar='connected_limit') diff --git a/update.py b/update.py index fb7258e6..822b3574 100644 --- a/update.py +++ b/update.py @@ -5,13 +5,13 @@ import ssl import httplib import socket import re +import json import cStringIO as StringIO from gevent import monkey monkey.patch_all() - -def update(): +def download(): from src.util import helper urls = [ @@ -46,6 +46,27 @@ def update(): print "Downloaded." + return zipdata + + +def update(): + from Config import config + updatesite_path = config.data_dir + "/" + config.updatesite + sites_json = json.load(open(config.data_dir + "/sites.json")) + updatesite_bad_files = sites_json.get(config.updatesite, {}).get("cache", {}).get("bad_files", {}) + print "Update site path: %s, bad_files: %s" % (updatesite_path, len(updatesite_bad_files)) + if os.path.isfile(updatesite_path + "/content.json") and len(updatesite_bad_files) == 0 and sites_json.get(config.updatesite, {}).get("serving"): + # Update site exists and no broken file + print "Updating using site %s" % config.updatesite + zipdata = False + inner_paths = json.load(open(updatesite_path + "/content.json"))["files"].keys() + # Keep file only in ZeroNet directory + inner_paths = [inner_path for inner_path in inner_paths if inner_path.startswith("ZeroNet/")] + else: + # Fallback to download + zipdata = download() + inner_paths = zipdata.namelist() + # Checking plugins plugins_enabled = [] plugins_disabled = [] @@ -58,12 +79,12 @@ def update(): print "Plugins enabled:", plugins_enabled, "disabled:", plugins_disabled print "Extracting...", - for inner_path in zipdata.namelist(): + for inner_path in inner_paths: if ".." in inner_path: continue inner_path = inner_path.replace("\\", "/") # Make sure we have unix path print ".", - dest_path = re.sub("^[^/]*-master.*?/", "", inner_path) # Skip root zeronet-master-... like directories + dest_path = re.sub("^([^/]*-master.*?|ZeroNet)/", "", inner_path) # Skip root zeronet-master-... like directories dest_path = dest_path.lstrip("/") if not dest_path: continue @@ -84,7 +105,11 @@ def update(): os.makedirs(dest_dir) if dest_dir != dest_path.strip("/"): - data = zipdata.read(inner_path) + if zipdata: + data = zipdata.read(inner_path) + else: + data = open(updatesite_path + "/" + inner_path).read() + try: open(dest_path, 'wb').write(data) except Exception, err: