diff options
author | Matias Linares <matias@deprecated.org> | 2024-10-05 09:58:26 -0300 |
---|---|---|
committer | Matias Linares <matias@deprecated.org> | 2024-10-05 09:58:26 -0300 |
commit | 7eec6ea7ee8607b8f46af941dab2e585ad348f03 (patch) | |
tree | 687e55c4817ae0736ad87880f622e5b511785c11 /kodereviewer | |
parent | e9c7736ff83b9003eba960edebd2653bd5a4021f (diff) | |
download | kodereviewer-7eec6ea7ee8607b8f46af941dab2e585ad348f03.tar.gz |
Add logger models/project.py
Diffstat (limited to 'kodereviewer')
-rw-r--r-- | kodereviewer/models/project.py | 14 |
1 files 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) |