From 7ecd3c9501a16da6c1872ed7521f93df9a8da7f5 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Wed, 20 Apr 2022 23:41:56 -0600 Subject: mayor bugfix in the database writer database was writing only one of the file info, effectively deleting all db --- src/pyssg/database.py | 34 ++++++++++++++++++++-------------- src/pyssg/pyssg.py | 3 ++- 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/pyssg/database.py b/src/pyssg/database.py index c13df89..66c7087 100644 --- a/src/pyssg/database.py +++ b/src/pyssg/database.py @@ -1,6 +1,10 @@ import os import sys from logging import Logger, getLogger +from configparser import ConfigParser +from tabnanny import check + +from .utils import get_checksum log: Logger = getLogger(__name__) @@ -9,9 +13,11 @@ log: Logger = getLogger(__name__) class Database: __COLUMN_NUM: int = 4 - def __init__(self, db_path: str): + def __init__(self, db_path: str, + config: ConfigParser): log.debug('initializing the page db on path "%s"', db_path) self.db_path: str = db_path + self.config: ConfigParser = config self.e: dict[str, tuple[float, float, list[str]]] = dict() @@ -87,19 +93,19 @@ class Database: def write(self) -> None: log.debug('writing db') - for k, v in self.e.items(): - log.debug('parsing row for page "%s"', k) - t: str = None - row: str = None - if len(v[2]) == 0: - t = '-' - else: - t = ','.join(v[2]) - - row = f'{k} {v[0]} {v[1]} {t}' - - log.debug('writing row: "%s\\n"', row) - with open(self.db_path, 'w') as file: + with open(self.db_path, 'w') as file: + for k, v in self.e.items(): + log.debug('parsing row for page "%s"', k) + t: str = None + row: str = None + if len(v[2]) == 0: + t = '-' + else: + t = ','.join(v[2]) + + row = f'{k} {v[0]} {v[1]} {t}' + + log.debug('writing row: "%s\\n"', row) file.write(f'{row}\n') diff --git a/src/pyssg/pyssg.py b/src/pyssg/pyssg.py index 931a55f..af7b166 100644 --- a/src/pyssg/pyssg.py +++ b/src/pyssg/pyssg.py @@ -76,7 +76,8 @@ def main() -> None: if args['build']: log.debug('building the html files') - db: Database = Database(os.path.join(config.get('path', 'src'), '.files')) + db_path: str = os.path.join(config.get('path', 'src'), '.files') + db: Database = Database(db_path, config) db.read() builder: Builder = Builder(config, db) -- cgit v1.2.3-70-g09d2