Display database rebuilding progressbar

This commit is contained in:
shortcutme 2017-05-07 18:14:13 +02:00
parent d346a532ff
commit 728e497057
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
3 changed files with 25 additions and 6 deletions

View file

@ -230,7 +230,7 @@ class SiteStoragePlugin(object):
# content.json file itself
if merged_site.storage.isFile(content_inner_path): # Missing content.json file
merged_inner_path = "merged-%s/%s/%s" % (merged_type, merged_site.address, content_inner_path)
yield merged_inner_path, merged_site.storage.open(content_inner_path)
yield merged_inner_path, merged_site.storage.getPath(content_inner_path)
else:
merged_site.log.error("[MISSING] %s" % content_inner_path)
# Data files in content.json
@ -242,7 +242,7 @@ class SiteStoragePlugin(object):
file_inner_path = file_inner_path.strip("/") # Strip leading /
if merged_site.storage.isFile(file_inner_path):
merged_inner_path = "merged-%s/%s/%s" % (merged_type, merged_site.address, file_inner_path)
yield merged_inner_path, merged_site.storage.open(file_inner_path)
yield merged_inner_path, merged_site.storage.getPath(file_inner_path)
else:
merged_site.log.error("[MISSING] %s" % file_inner_path)

View file

@ -1064,6 +1064,13 @@ class Site(object):
for ws in self.websockets:
ws.event("siteChanged", self, param)
def messageWebsocket(self, message, type="info", progress=None):
for ws in self.websockets:
if progress is None:
ws.cmd("notification", [type, message])
else:
ws.cmd("progress", [type, message, progress])
# File download started
@util.Noparallel(blocking=False)
def fileStarted(self):

View file

@ -13,6 +13,7 @@ from Debug import Debug
from Config import config
from util import helper
from Plugin import PluginManager
from Translate import translate as _
@PluginManager.acceptPlugins
@ -78,7 +79,7 @@ class SiteStorage(object):
for content_inner_path, content in self.site.content_manager.contents.iteritems():
# content.json file itself
if self.isFile(content_inner_path):
yield content_inner_path, self.open(content_inner_path)
yield content_inner_path, self.getPath(content_inner_path)
else:
self.log.error("[MISSING] %s" % content_inner_path)
# Data files in content.json
@ -89,7 +90,7 @@ class SiteStorage(object):
file_inner_path = content_inner_path_dir + file_relative_path # File Relative to site dir
file_inner_path = file_inner_path.strip("/") # Strip leading /
if self.isFile(file_inner_path):
yield file_inner_path, self.open(file_inner_path)
yield file_inner_path, self.getPath(file_inner_path)
else:
self.log.error("[MISSING] %s" % file_inner_path)
@ -120,16 +121,27 @@ class SiteStorage(object):
cur.logging = False
found = 0
s = time.time()
db_files = list(self.getDbFiles())
try:
for file_inner_path, file in self.getDbFiles():
if len(db_files) > 100:
self.site.messageWebsocket(_["Database rebuilding...<br>Imported {0} of {1} files..."].format("0000", len(db_files)), "rebuild", 0)
for file_inner_path, file_path in db_files:
try:
if self.updateDbFile(file_inner_path, file=file, cur=cur):
if self.updateDbFile(file_inner_path, file=open(file_path, "rb"), cur=cur):
found += 1
except Exception, err:
self.log.error("Error importing %s: %s" % (file_inner_path, Debug.formatException(err)))
if found and found % 100 == 0:
self.site.messageWebsocket(
_["Database rebuilding...<br>Imported {0} of {1} files..."].format(found, len(db_files)),
"rebuild",
int(float(found) / len(db_files) * 100)
)
finally:
cur.execute("END")
if len(db_files) > 100:
self.site.messageWebsocket(_["Database rebuilding...<br>Imported {0} of {1} files..."].format(found, len(db_files)), "rebuild", 100)
self.log.info("Imported %s data file in %ss" % (found, time.time() - s))
self.event_db_busy.set(True) # Event done, notify waiters
self.event_db_busy = None # Clear event