Rev1761, Update ZeroNet from ZeroNet network
This commit is contained in:
parent
c69f70bdb0
commit
b66317fa7d
2 changed files with 33 additions and 6 deletions
|
@ -9,7 +9,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.5.1"
|
self.version = "0.5.1"
|
||||||
self.rev = 1758
|
self.rev = 1761
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
@ -146,6 +146,8 @@ class Config(object):
|
||||||
nargs='?', const="default_browser", metavar='browser_name')
|
nargs='?', const="default_browser", metavar='browser_name')
|
||||||
self.parser.add_argument('--homepage', help='Web interface Homepage', default='1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D',
|
self.parser.add_argument('--homepage', help='Web interface Homepage', default='1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D',
|
||||||
metavar='address')
|
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('--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')
|
self.parser.add_argument('--connected_limit', help='Max connected peer per site', default=10, type=int, metavar='connected_limit')
|
||||||
|
|
||||||
|
|
35
update.py
35
update.py
|
@ -5,13 +5,13 @@ import ssl
|
||||||
import httplib
|
import httplib
|
||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
import cStringIO as StringIO
|
import cStringIO as StringIO
|
||||||
|
|
||||||
from gevent import monkey
|
from gevent import monkey
|
||||||
monkey.patch_all()
|
monkey.patch_all()
|
||||||
|
|
||||||
|
def download():
|
||||||
def update():
|
|
||||||
from src.util import helper
|
from src.util import helper
|
||||||
|
|
||||||
urls = [
|
urls = [
|
||||||
|
@ -46,6 +46,27 @@ def update():
|
||||||
|
|
||||||
print "Downloaded."
|
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
|
# Checking plugins
|
||||||
plugins_enabled = []
|
plugins_enabled = []
|
||||||
plugins_disabled = []
|
plugins_disabled = []
|
||||||
|
@ -58,12 +79,12 @@ def update():
|
||||||
print "Plugins enabled:", plugins_enabled, "disabled:", plugins_disabled
|
print "Plugins enabled:", plugins_enabled, "disabled:", plugins_disabled
|
||||||
|
|
||||||
print "Extracting...",
|
print "Extracting...",
|
||||||
for inner_path in zipdata.namelist():
|
for inner_path in inner_paths:
|
||||||
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 = 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("/")
|
dest_path = dest_path.lstrip("/")
|
||||||
if not dest_path:
|
if not dest_path:
|
||||||
continue
|
continue
|
||||||
|
@ -84,7 +105,11 @@ def update():
|
||||||
os.makedirs(dest_dir)
|
os.makedirs(dest_dir)
|
||||||
|
|
||||||
if dest_dir != dest_path.strip("/"):
|
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:
|
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