Display database rebuilding progressbar
This commit is contained in:
parent
d346a532ff
commit
728e497057
3 changed files with 25 additions and 6 deletions
|
@ -230,7 +230,7 @@ class SiteStoragePlugin(object):
|
||||||
# content.json file itself
|
# content.json file itself
|
||||||
if merged_site.storage.isFile(content_inner_path): # Missing content.json file
|
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)
|
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:
|
else:
|
||||||
merged_site.log.error("[MISSING] %s" % content_inner_path)
|
merged_site.log.error("[MISSING] %s" % content_inner_path)
|
||||||
# Data files in content.json
|
# Data files in content.json
|
||||||
|
@ -242,7 +242,7 @@ class SiteStoragePlugin(object):
|
||||||
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
||||||
if merged_site.storage.isFile(file_inner_path):
|
if merged_site.storage.isFile(file_inner_path):
|
||||||
merged_inner_path = "merged-%s/%s/%s" % (merged_type, merged_site.address, 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:
|
else:
|
||||||
merged_site.log.error("[MISSING] %s" % file_inner_path)
|
merged_site.log.error("[MISSING] %s" % file_inner_path)
|
||||||
|
|
||||||
|
|
|
@ -1064,6 +1064,13 @@ class Site(object):
|
||||||
for ws in self.websockets:
|
for ws in self.websockets:
|
||||||
ws.event("siteChanged", self, param)
|
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
|
# File download started
|
||||||
@util.Noparallel(blocking=False)
|
@util.Noparallel(blocking=False)
|
||||||
def fileStarted(self):
|
def fileStarted(self):
|
||||||
|
|
|
@ -13,6 +13,7 @@ from Debug import Debug
|
||||||
from Config import config
|
from Config import config
|
||||||
from util import helper
|
from util import helper
|
||||||
from Plugin import PluginManager
|
from Plugin import PluginManager
|
||||||
|
from Translate import translate as _
|
||||||
|
|
||||||
|
|
||||||
@PluginManager.acceptPlugins
|
@PluginManager.acceptPlugins
|
||||||
|
@ -78,7 +79,7 @@ class SiteStorage(object):
|
||||||
for content_inner_path, content in self.site.content_manager.contents.iteritems():
|
for content_inner_path, content in self.site.content_manager.contents.iteritems():
|
||||||
# content.json file itself
|
# content.json file itself
|
||||||
if self.isFile(content_inner_path):
|
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:
|
else:
|
||||||
self.log.error("[MISSING] %s" % content_inner_path)
|
self.log.error("[MISSING] %s" % content_inner_path)
|
||||||
# Data files in content.json
|
# 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 = content_inner_path_dir + file_relative_path # File Relative to site dir
|
||||||
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
||||||
if self.isFile(file_inner_path):
|
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:
|
else:
|
||||||
self.log.error("[MISSING] %s" % file_inner_path)
|
self.log.error("[MISSING] %s" % file_inner_path)
|
||||||
|
|
||||||
|
@ -120,16 +121,27 @@ class SiteStorage(object):
|
||||||
cur.logging = False
|
cur.logging = False
|
||||||
found = 0
|
found = 0
|
||||||
s = time.time()
|
s = time.time()
|
||||||
|
db_files = list(self.getDbFiles())
|
||||||
try:
|
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:
|
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
|
found += 1
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.log.error("Error importing %s: %s" % (file_inner_path, Debug.formatException(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:
|
finally:
|
||||||
cur.execute("END")
|
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.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.set(True) # Event done, notify waiters
|
||||||
self.event_db_busy = None # Clear event
|
self.event_db_busy = None # Clear event
|
||||||
|
|
Loading…
Reference in a new issue