refactor: Separate full sync into multiple files
This commit is contained in:
parent
abfd3ba1fe
commit
e94bb778c0
28
src/ankisyncd/full_sync/__init__.py
Normal file
28
src/ankisyncd/full_sync/__init__.py
Normal 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()
|
||||
@ -1,18 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import os
|
||||
from sqlite3 import dbapi2 as sqlite
|
||||
import shutil
|
||||
import sys
|
||||
from sqlite3 import dbapi2 as sqlite
|
||||
from webob.exc import HTTPBadRequest
|
||||
|
||||
from anki.db import DB
|
||||
from anki.collection import Collection
|
||||
|
||||
logger = logging.getLogger("ankisyncd.media")
|
||||
logger.setLevel(1)
|
||||
|
||||
|
||||
class FullSyncManager:
|
||||
def test_db(self, db: DB):
|
||||
@ -77,24 +69,3 @@ class FullSyncManager:
|
||||
col.media.connect()
|
||||
|
||||
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()
|
||||
Loading…
Reference in New Issue
Block a user