refactor: Separate full sync into multiple files

This commit is contained in:
Vikash Kothary 2022-10-14 23:31:47 +01:00
parent abfd3ba1fe
commit e94bb778c0
2 changed files with 29 additions and 30 deletions

View File

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from ankisyncd import logging
from ankisyncd.full_sync.manager import FullSyncManager
logger = logging.get_logger(__name__)
logger.setLevel(1)
def get_full_sync_manager(config):
if (
"full_sync_manager" in config and config["full_sync_manager"]
): # load from config
import importlib
import inspect
module_name, class_name = config["full_sync_manager"].rsplit(".", 1)
module = importlib.import_module(module_name.strip())
class_ = getattr(module, class_name.strip())
if not FullSyncManager in inspect.getmro(class_):
raise TypeError(
""""full_sync_manager" found in the conf file but it doesn''t
inherit from FullSyncManager"""
)
return class_(config)
else:
return FullSyncManager()

View File

@ -1,18 +1,10 @@
# -*- coding: utf-8 -*-
import logging
import os
from sqlite3 import dbapi2 as sqlite
import shutil import shutil
import sys from sqlite3 import dbapi2 as sqlite
from webob.exc import HTTPBadRequest from webob.exc import HTTPBadRequest
from anki.db import DB from anki.db import DB
from anki.collection import Collection from anki.collection import Collection
logger = logging.getLogger("ankisyncd.media")
logger.setLevel(1)
class FullSyncManager: class FullSyncManager:
def test_db(self, db: DB): def test_db(self, db: DB):
@ -77,24 +69,3 @@ class FullSyncManager:
col.media.connect() col.media.connect()
return data return data
def get_full_sync_manager(config):
if (
"full_sync_manager" in config and config["full_sync_manager"]
): # load from config
import importlib
import inspect
module_name, class_name = config["full_sync_manager"].rsplit(".", 1)
module = importlib.import_module(module_name.strip())
class_ = getattr(module, class_name.strip())
if not FullSyncManager in inspect.getmro(class_):
raise TypeError(
""""full_sync_manager" found in the conf file but it doesn''t
inherit from FullSyncManager"""
)
return class_(config)
else:
return FullSyncManager()