(self)
| 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) |
no test coverage detected