From 7eec6ea7ee8607b8f46af941dab2e585ad348f03 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 5 Oct 2024 09:58:26 -0300 Subject: Add logger models/project.py --- kodereviewer/models/project.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kodereviewer/models/project.py b/kodereviewer/models/project.py index c676157..cb380da 100644 --- a/kodereviewer/models/project.py +++ b/kodereviewer/models/project.py @@ -1,5 +1,6 @@ import json -from os import path +import logging +from os import path, makedirs from typing import Any from PySide6.QtCore import QAbstractListModel, QByteArray, QModelIndex, QObject, QPersistentModelIndex, QStandardPaths, QUrl, Qt, Signal, Slot, Property @@ -10,6 +11,7 @@ from kodereviewer.project import Project QML_IMPORT_NAME = "org.deprecated.kodereviewer" QML_IMPORT_MAJOR_VERSION = 1 +logger = logging.getLogger(__name__) @QmlElement class ProjectModel(QAbstractListModel): @@ -31,8 +33,8 @@ class ProjectModel(QAbstractListModel): data = json.load(fp) if isinstance(data, list): self._load_projects(data) - except OSError as e: - pass + except OSError: + logger.exception(f'Cannot open {project_config}') def _project_file(self) -> str: app_data = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation) @@ -81,7 +83,11 @@ class ProjectModel(QAbstractListModel): project_config = self._project_file() data = [{'name': project.name, 'owner': project.owner, 'url': project.url} for project in self.projects] - with open(self._project_file(), 'w') as fp: + if not path.exists(project_config): + dir = path.dirname(project_config) + makedirs(dir) + + with open(project_config, 'w') as fp: json.dump(data, fp) @Slot(str, str, str) -- cgit v1.2.3-70-g09d2