summaryrefslogtreecommitdiff
path: root/kodereviewer/models/project.py
diff options
context:
space:
mode:
Diffstat (limited to 'kodereviewer/models/project.py')
-rw-r--r--kodereviewer/models/project.py14
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)