diff --git a/utils/Sync/settings.py b/utils/Sync/settings.py index d8ad6de9..80260705 100644 --- a/utils/Sync/settings.py +++ b/utils/Sync/settings.py @@ -119,6 +119,7 @@ date_formats_reverse = [ origin = value('origin') +collection_settings = 'settings' collection_images = 'images' collection_documents = 'documents' collection_awards = 'awards' @@ -133,6 +134,7 @@ provider_root = value('provider')['root'] # env('SYNC_PROVIDER', 'fs') f = abs_fn(provider_root) +dir_settings = f('Settings') dir_documents = f('Documents') dir_awards = f('Awards') dir_schedules = f('Schedules') diff --git a/utils/Sync/sync.py b/utils/Sync/sync.py index c8ec0246..d8713573 100644 --- a/utils/Sync/sync.py +++ b/utils/Sync/sync.py @@ -12,6 +12,7 @@ from sync.models.Article import Article from sync.models.Page import Page from sync.models.Person import Person from sync.models.Schedule import Schedule +from sync.models.Settings import Settings def init_logger(name: str, file: str): @@ -74,6 +75,11 @@ async def run(run_interval=0): model=Album, ) + _settings = Sync( + provider=io(settings.dir_settings), + model=Settings, + ) + while True: await asyncio.wait([ main(documents), @@ -82,6 +88,7 @@ async def run(run_interval=0): main(articles), main(schedules), main(albums), + main(_settings), ]) if run_interval == 0: diff --git a/utils/Sync/sync/models/Settings.py b/utils/Sync/sync/models/Settings.py new file mode 100644 index 00000000..e8c6e757 --- /dev/null +++ b/utils/Sync/sync/models/Settings.py @@ -0,0 +1,63 @@ +from toml import loads as toml_str +from yaml import load as yaml + +import settings +from db import collection +from sync.data import Provider, get_data +from sync.models import Model + +from utils.fn import constant + +store = collection(settings.collection_settings) + + +class Settings(Model): + @staticmethod + async def find(query): + return store.find(query) + + @staticmethod + async def delete(query): + return store.find_one_and_delete(query) + + @staticmethod + async def scan(provider): + documents = provider.type_filter('.', '.yaml') + + documents = [Settings.read(provider, i) for i in documents] + return documents + + @staticmethod + def read(provider, path): + params = yaml(provider.read(path)) + + return Settings( + provider, + path, + params=params, + ) + + def __init__(self, provider, file, params=None): + super().__init__(provider, store, file, params=params) + + def init(self): + pass + self.__set_id() + self.__set_hash() + + def bake(self): + return { + **self.params, + 'id': self.id, + 'hash': self.hash, + 'file': self.file, + } + + def __set_id(self): + self.id = 'settings' + + def __set_hash(self): + self.hash = self.provider.hash(self.file) + + def __str__(self): + return ''.format(self.hash, self.file, self.id)