Formatting

This commit is contained in:
shortcutme 2019-11-19 02:11:19 +01:00
parent 74d7fb7835
commit 57f2a43864
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -159,7 +159,11 @@ class SiteStorage(object):
self.log.info("Importing data...") self.log.info("Importing data...")
try: try:
if num_total > 100: if num_total > 100:
self.site.messageWebsocket(_["Database rebuilding...<br>Imported {0} of {1} files (error: {2})..."].format("0000", num_total, num_error), "rebuild", 0) self.site.messageWebsocket(
_["Database rebuilding...<br>Imported {0} of {1} files (error: {2})..."].format(
"0000", num_total, num_error
), "rebuild", 0
)
for file_inner_path, file_path in db_files: for file_inner_path, file_path in db_files:
try: try:
if self.updateDbFile(file_inner_path, file=open(file_path, "rb"), cur=cur): if self.updateDbFile(file_inner_path, file=open(file_path, "rb"), cur=cur):
@ -170,16 +174,21 @@ class SiteStorage(object):
if num_imported and num_imported % 100 == 0: if num_imported and num_imported % 100 == 0:
self.site.messageWebsocket( self.site.messageWebsocket(
_["Database rebuilding...<br>Imported {0} of {1} files (error: {2})..."].format(num_imported, num_total, num_error), _["Database rebuilding...<br>Imported {0} of {1} files (error: {2})..."].format(
"rebuild", num_imported, num_total, num_error
int(float(num_imported) / num_total * 100) ),
"rebuild", int(float(num_imported) / num_total * 100)
) )
time.sleep(0.001) # Context switch to avoid UI block time.sleep(0.001) # Context switch to avoid UI block
finally: finally:
cur.close() cur.close()
if num_total > 100: if num_total > 100:
self.site.messageWebsocket(_["Database rebuilding...<br>Imported {0} of {1} files (error: {2})..."].format(num_imported, num_total, num_error), "rebuild", 100) self.site.messageWebsocket(
_["Database rebuilding...<br>Imported {0} of {1} files (error: {2})..."].format(
num_imported, num_total, num_error
), "rebuild", 100
)
self.log.info("Imported %s data file in %.3fs" % (num_imported, time.time() - s)) self.log.info("Imported %s data file in %.3fs" % (num_imported, 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
@ -305,13 +314,14 @@ class SiteStorage(object):
# Site content updated # Site content updated
def onUpdated(self, inner_path, file=None): def onUpdated(self, inner_path, file=None):
# Update Sql cache # Update Sql cache
should_load_to_db = inner_path.endswith(".json") or inner_path.endswith(".json.gz")
if inner_path == "dbschema.json": if inner_path == "dbschema.json":
self.has_db = self.isFile("dbschema.json") self.has_db = self.isFile("dbschema.json")
# Reopen DB to check changes # Reopen DB to check changes
if self.has_db: if self.has_db:
self.closeDb() self.closeDb()
self.getDb() self.getDb()
elif not config.disable_db and (inner_path.endswith(".json") or inner_path.endswith(".json.gz")) and self.has_db: # Load json file to db elif not config.disable_db and should_load_to_db and self.has_db: # Load json file to db
if config.verbose: if config.verbose:
self.log.debug("Loading json file to db: %s (file: %s)" % (inner_path, file)) self.log.debug("Loading json file to db: %s (file: %s)" % (inner_path, file))
try: try:
@ -335,7 +345,7 @@ class SiteStorage(object):
path = self.getPath(inner_path) path = self.getPath(inner_path)
try: try:
return os.path.getsize(path) return os.path.getsize(path)
except: except Exception:
return 0 return 0
# File exist # File exist