[Sync] + Settings sync
This commit is contained in:
1 parent
16a8719927
commit
952eaab69b
3 files changed
+72
No files matched your search
@@ -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')
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 '<Settings hash={} file={} id={}>'.format(self.hash, self.file, self.id)
|
||||
Reference in new issue
Block a user