diff --git a/src/Config.py b/src/Config.py index 6f366551..2fa48a47 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 = 1818 + self.rev = 1821 self.argv = argv self.action = None self.config_file = "zeronet.conf" diff --git a/src/Site/Site.py b/src/Site/Site.py index 36023527..e5a9cfb9 100644 --- a/src/Site/Site.py +++ b/src/Site/Site.py @@ -398,7 +398,7 @@ class Site(object): gevent.joinall(content_threads) # 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) content_json_modified = self.content_manager.contents[inner_path]["modified"] body = self.storage.read(inner_path) @@ -457,6 +457,8 @@ class Site(object): if result and "ok" in result: 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)) else: if result == {"exception": "Timeout"}: @@ -466,7 +468,7 @@ class Site(object): # Update content.json on peers @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) publishers = [] # Publisher threads @@ -498,7 +500,7 @@ class Site(object): event_done = gevent.event.AsyncResult() 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) event_done.get() # Wait for done diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py index b2717b27..cd860893 100644 --- a/src/Ui/UiWebsocket.py +++ b/src/Ui/UiWebsocket.py @@ -346,6 +346,7 @@ class UiWebsocket(object): thread.linked = True if called_instantly: # Allowed to call instantly # 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)) else: self.cmd( @@ -357,15 +358,27 @@ class UiWebsocket(object): thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=False)) 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) - 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 def cbSitePublish(self, to, site, thread, notification=True, callback=True): published = thread.value if published > 0: # Successfully published 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 if callback: self.response(to, "ok") @@ -388,7 +401,6 @@ class UiWebsocket(object): else: if notification: - self.cmd("notification", ["error", _["Content publish failed."]]) self.response(to, {"error": "Content publish failed."}) # Write a file to disk