diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-03-04 16:00:46 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-03-04 16:00:46 +0100 |
commit | 01a4c2fc4bcbcce26c29dc9771dedeef5256156b (patch) | |
tree | aafea6125f413f6862bb79ad9c9ef5b35a6b7dd3 | |
parent | 9bdf4d104a299577634061bcf698d1c9e5708cce (diff) | |
download | tagit-01a4c2fc4bcbcce26c29dc9771dedeef5256156b.tar.gz tagit-01a4c2fc4bcbcce26c29dc9771dedeef5256156b.tar.bz2 tagit-01a4c2fc4bcbcce26c29dc9771dedeef5256156b.zip |
schema requirements checking
-rw-r--r-- | tagit/__init__.py | 1 | ||||
-rw-r--r-- | tagit/apps/desktop.py | 17 | ||||
-rw-r--r-- | tagit/assets/required_schema.nt (renamed from tagit/apps/port-schema.nt) | 5 | ||||
-rw-r--r-- | tagit/widgets/session.py | 12 |
4 files changed, 13 insertions, 22 deletions
diff --git a/tagit/__init__.py b/tagit/__init__.py index 0e10d7b..b0c602d 100644 --- a/tagit/__init__.py +++ b/tagit/__init__.py @@ -41,6 +41,7 @@ kivy.require('1.9.1') resource_add_path(os.path.join(os.path.dirname(__file__), 'assets', 'icons', 'kivy')) resource_add_path(os.path.join(os.path.dirname(__file__), 'assets', 'fonts', 'kivy')) resource_add_path(os.path.join(os.path.dirname(__file__), 'assets', 'themes')) +resource_add_path(os.path.join(os.path.dirname(__file__), 'assets')) # load font from kivy.core.text import LabelBase diff --git a/tagit/apps/desktop.py b/tagit/apps/desktop.py index b02c8f1..d934649 100644 --- a/tagit/apps/desktop.py +++ b/tagit/apps/desktop.py @@ -10,6 +10,7 @@ import typing # kivy imports from kivy.app import App +from kivy.resources import resource_find from kivy.uix.settings import SettingsWithSidebar # tagit imports @@ -41,21 +42,15 @@ class TagitApp(App): cfg = load_settings(TAGITRC, 0) - # FIXME: mb/port/bsfs # open BSFS storage store = bsfs.Open(cfg('session', 'bsfs')) # check storage schema - # FIXME: Move somewhere else?! - with open(os.path.join(os.path.dirname(__file__), 'port-schema.nt'), 'rt') as ifile: + with open(resource_find('required_schema.nt'), 'rt') as ifile: required_schema = bsfs.schema.from_string(ifile.read()) - # FIXME: Since the store isn't persistent, we migrate to the required one here. - #if not required_schema <= store.schema: - # raise Exception('') - store.migrate(required_schema) - - # FIXME: debug: add some data to the storage - from . import port_data - port_data.add_port_data(store) + if not required_schema.consistent_with(store.schema): + raise Exception("The storage's schema is incompatible with tagit's requirements") + if not required_schema <= store.schema: + store.migrate(required_schema | store.schema) # create widget return desktop.MainWindow(cfg, store, None) # FIXME: expects cfg, stor, log arguments diff --git a/tagit/apps/port-schema.nt b/tagit/assets/required_schema.nt index 2e70cad..d48f0bd 100644 --- a/tagit/apps/port-schema.nt +++ b/tagit/assets/required_schema.nt @@ -32,15 +32,11 @@ xsd:float rdfs:subClassOf bsl:Number . bse:filename rdfs:subClassOf bsfs:Predicate ; rdfs:domain bsn:Entity ; rdfs:range xsd:string ; - rdfs:label "File name"^^xsd:string ; - schema:description "Filename of entity in some filesystem."^^xsd:string ; bsfs:unique "true"^^xsd:boolean . bse:filesize rdfs:subClassOf bsfs:Predicate ; rdfs:domain bsn:Entity ; rdfs:range xsd:integer ; - rdfs:label "File size"^^xsd:string ; - schema:description "File size of entity in some filesystem."^^xsd:string ; bsfs:unique "true"^^xsd:boolean . bse:mime rdfs:subClassOf bsfs:Predicate ; @@ -112,4 +108,3 @@ bsp:asset rdfs:subClassOf bsfs:Predicate ; rdfs:range <https://schema.bsfs.io/ie/Literal/BinaryBlob/JPEG> ; bsfs:unique "true"^^xsd:boolean . - diff --git a/tagit/widgets/session.py b/tagit/widgets/session.py index c233a15..30dfe51 100644 --- a/tagit/widgets/session.py +++ b/tagit/widgets/session.py @@ -68,13 +68,13 @@ class Session(Widget): # open BSFS storage store = bsfs.Open(cfg('session', 'bsfs')) # check storage schema - # FIXME: how to properly load the required schema? - with open(os.path.join(os.path.dirname(__file__), '..', 'apps', 'port-schema.nt'), 'rt') as ifile: + with open(resource_find('required_schema.nt'), 'rt') as ifile: required_schema = bsfs.schema.from_string(ifile.read()) - # FIXME: Since the store isn't persistent, we migrate to the required one here. - #if not required_schema <= store.schema: - # raise Exception('') - store.migrate(required_schema) + if not required_schema.consistent_with(store.schema): + raise Exception("The storage's schema is incompatible with tagit's requirements") + if not required_schema <= store.schema: + store.migrate(required_schema | store.schema) + # replace current with new storage self.storage = store |