MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / getDb

Method getDb

src/Site/SiteStorage.py:67–92  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

65
66 # Return db class
67 def getDb(self):
68 if not self.db:
69 self.log.debug("No database, waiting for dbschema.json...")
70 self.site.needFile("dbschema.json", priority=3)
71 self.has_db = self.isFile("dbschema.json") # Recheck if dbschema exist
72 if self.has_db:
73 schema = self.getDbSchema()
74 db_path = self.getPath(schema["db_file"])
75 if not os.path.isfile(db_path) or os.path.getsize(db_path) == 0:
76 try:
77 self.rebuildDb()
78 except Exception as err:
79 self.log.error(err)
80 pass
81
82 if self.db:
83 self.db.close()
84 self.db = self.openDb(close_idle=True)
85 try:
86 changed_tables = self.db.checkTables()
87 if changed_tables:
88 self.rebuildDb(delete_db=False) # TODO: only update the changed table datas
89 except sqlite3.OperationalError:
90 pass
91
92 return self.db
93
94 def updateDbFile(self, inner_path, file=None, cur=None):
95 path = self.getPath(inner_path)

Callers 4

updateDbFileMethod · 0.95
queryMethod · 0.95
onUpdatedMethod · 0.95
actionDbReloadMethod · 0.80

Calls 9

isFileMethod · 0.95
getDbSchemaMethod · 0.95
getPathMethod · 0.95
rebuildDbMethod · 0.95
openDbMethod · 0.95
errorMethod · 0.80
needFileMethod · 0.45
closeMethod · 0.45
checkTablesMethod · 0.45

Tested by

no test coverage detected