Rev1821, Show progress bar on publishing
This commit is contained in:
parent
b68424f008
commit
2dc981496b
3 changed files with 21 additions and 7 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 = 1818
|
self.rev = 1821
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
|
|
@ -398,7 +398,7 @@ class Site(object):
|
||||||
gevent.joinall(content_threads)
|
gevent.joinall(content_threads)
|
||||||
|
|
||||||
# Publish worker
|
# Publish worker
|
||||||
def publisher(self, inner_path, peers, published, limit, event_done=None, diffs={}):
|
def publisher(self, inner_path, peers, published, limit, diffs={}, event_done=None, cb_progress=None):
|
||||||
file_size = self.storage.getSize(inner_path)
|
file_size = self.storage.getSize(inner_path)
|
||||||
content_json_modified = self.content_manager.contents[inner_path]["modified"]
|
content_json_modified = self.content_manager.contents[inner_path]["modified"]
|
||||||
body = self.storage.read(inner_path)
|
body = self.storage.read(inner_path)
|
||||||
|
@ -457,6 +457,8 @@ class Site(object):
|
||||||
|
|
||||||
if result and "ok" in result:
|
if result and "ok" in result:
|
||||||
published.append(peer)
|
published.append(peer)
|
||||||
|
if cb_progress and len(published) <= limit:
|
||||||
|
cb_progress(len(published), limit)
|
||||||
self.log.info("[OK] %s: %s %s/%s" % (peer.key, result["ok"], len(published), limit))
|
self.log.info("[OK] %s: %s %s/%s" % (peer.key, result["ok"], len(published), limit))
|
||||||
else:
|
else:
|
||||||
if result == {"exception": "Timeout"}:
|
if result == {"exception": "Timeout"}:
|
||||||
|
@ -466,7 +468,7 @@ class Site(object):
|
||||||
|
|
||||||
# Update content.json on peers
|
# Update content.json on peers
|
||||||
@util.Noparallel()
|
@util.Noparallel()
|
||||||
def publish(self, limit="default", inner_path="content.json", diffs={}):
|
def publish(self, limit="default", inner_path="content.json", diffs={}, cb_progress=None):
|
||||||
published = [] # Successfully published (Peer)
|
published = [] # Successfully published (Peer)
|
||||||
publishers = [] # Publisher threads
|
publishers = [] # Publisher threads
|
||||||
|
|
||||||
|
@ -498,7 +500,7 @@ class Site(object):
|
||||||
|
|
||||||
event_done = gevent.event.AsyncResult()
|
event_done = gevent.event.AsyncResult()
|
||||||
for i in range(min(len(peers), limit, threads)):
|
for i in range(min(len(peers), limit, threads)):
|
||||||
publisher = gevent.spawn(self.publisher, inner_path, peers, published, limit, event_done, diffs)
|
publisher = gevent.spawn(self.publisher, inner_path, peers, published, limit, diffs, event_done, cb_progress)
|
||||||
publishers.append(publisher)
|
publishers.append(publisher)
|
||||||
|
|
||||||
event_done.get() # Wait for done
|
event_done.get() # Wait for done
|
||||||
|
|
|
@ -346,6 +346,7 @@ class UiWebsocket(object):
|
||||||
thread.linked = True
|
thread.linked = True
|
||||||
if called_instantly: # Allowed to call instantly
|
if called_instantly: # Allowed to call instantly
|
||||||
# At the end callback with request id and thread
|
# At the end callback with request id and thread
|
||||||
|
self.cmd("progress", ["publish", _["Content published to {0}/{1} peers."].format(0, 5), 0])
|
||||||
thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=notification))
|
thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=notification))
|
||||||
else:
|
else:
|
||||||
self.cmd(
|
self.cmd(
|
||||||
|
@ -357,15 +358,27 @@ class UiWebsocket(object):
|
||||||
thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=False))
|
thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=False))
|
||||||
|
|
||||||
def doSitePublish(self, site, inner_path):
|
def doSitePublish(self, site, inner_path):
|
||||||
|
def cbProgress(published, limit):
|
||||||
|
progress = int(float(published) / limit * 100)
|
||||||
|
self.cmd("progress", [
|
||||||
|
"publish",
|
||||||
|
_["Content published to {0}/{1} peers."].format(published, limit),
|
||||||
|
progress
|
||||||
|
])
|
||||||
diffs = site.content_manager.getDiffs(inner_path)
|
diffs = site.content_manager.getDiffs(inner_path)
|
||||||
return site.publish(limit=5, inner_path=inner_path, diffs=diffs)
|
back = site.publish(limit=5, inner_path=inner_path, diffs=diffs, cb_progress=cbProgress)
|
||||||
|
if back == 0: # Failed to publish to anyone
|
||||||
|
self.cmd("progress", ["publish", _["Content publish failed."], -100])
|
||||||
|
else:
|
||||||
|
cbProgress(back, back)
|
||||||
|
return back
|
||||||
|
|
||||||
# Callback of site publish
|
# Callback of site publish
|
||||||
def cbSitePublish(self, to, site, thread, notification=True, callback=True):
|
def cbSitePublish(self, to, site, thread, notification=True, callback=True):
|
||||||
published = thread.value
|
published = thread.value
|
||||||
if published > 0: # Successfully published
|
if published > 0: # Successfully published
|
||||||
if notification:
|
if notification:
|
||||||
self.cmd("notification", ["done", _["Content published to {0} peers."].format(published), 5000])
|
# self.cmd("notification", ["done", _["Content published to {0} peers."].format(published), 5000])
|
||||||
site.updateWebsocket() # Send updated site data to local websocket clients
|
site.updateWebsocket() # Send updated site data to local websocket clients
|
||||||
if callback:
|
if callback:
|
||||||
self.response(to, "ok")
|
self.response(to, "ok")
|
||||||
|
@ -388,7 +401,6 @@ class UiWebsocket(object):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if notification:
|
if notification:
|
||||||
self.cmd("notification", ["error", _["Content publish failed."]])
|
|
||||||
self.response(to, {"error": "Content publish failed."})
|
self.response(to, {"error": "Content publish failed."})
|
||||||
|
|
||||||
# Write a file to disk
|
# Write a file to disk
|
||||||
|
|
Loading…
Reference in a new issue