Changeset - c9b0c7cf50ed
[Not reviewed]
0 6 0
Lance Edgar (lance) - 11 years ago 2013-12-18 23:50:37
lance@edbob.org
Removed reliance on `edbob.db.engines`.
6 files changed with 32 insertions and 30 deletions:
0 comments (0 inline, 0 general)
rattail/commands.py
Show inline comments
 
@@ -35,6 +35,7 @@ from edbob.commands import Subcommand
 

	
 
from ._version import __version__
 
from .db import model
 
from .console import Progress
 

	
 

	
 
class Command(commands.Command):
 
@@ -159,7 +160,6 @@ class Dump(Subcommand):
 
    def run(self, args):
 
        from .db import get_session_class
 
        from .db.dump import dump_data
 
        from .console import Progress
 

	
 
        if hasattr(model, args.model):
 
            cls = getattr(model, args.model)
 
@@ -302,17 +302,16 @@ class LoadHostDataCommand(Subcommand):
 
    description = "Load data from host database"
 

	
 
    def run(self, args):
 
        from .console import Progress
 
        from rattail.db import load
 
        from .db import get_engines
 
        from .db import load
 

	
 
        edbob.init_modules(['edbob.db'])
 

	
 
        if 'host' not in edbob.engines:
 
            print "Host engine URL not configured."
 
            return
 
        engines = get_engines(edbob.config)
 
        if 'host' not in engines:
 
            sys.stderr.write("Host engine URL not configured.\n")
 
            sys.exit(1)
 

	
 
        proc = load.LoadProcessor()
 
        proc.load_all_data(edbob.engines['host'], Progress)
 
        proc.load_all_data(engines['host'], Progress)
 

	
 

	
 
class MakeConfigCommand(Subcommand):
rattail/db/sync/__init__.py
Show inline comments
 
@@ -39,25 +39,25 @@ from sqlalchemy.exc import OperationalError
 

	
 
import edbob
 

	
 
from rattail.db import model
 
from .. import model
 
from .. import get_engines
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
def get_sync_engines():
 
    edbob.init_modules(['edbob.db'])
 

	
 
    keys = edbob.config.get('rattail.db', 'syncs')
 
    if not keys:
 
        return None
 

	
 
    engines = {}
 
    engines = get_engines(edbob.config)
 
    sync_engines = {}
 
    for key in keys.split(','):
 
        key = key.strip()
 
        engines[key] = edbob.engines[key]
 
    log.debug("get_sync_engines: Found engine keys: %s" % ','.join(engines.keys()))
 
    return engines
 
        sync_engines[key] = engines[key]
 
    log.debug("get_sync_engines: Found engine keys: %s" % ','.join(sync_engines.keys()))
 
    return sync_engines
 

	
 

	
 
class Synchronizer(object):
rattail/db/sync/linux.py
Show inline comments
 
@@ -27,9 +27,9 @@
 
"""
 

	
 
import edbob
 
from edbob import db
 

	
 
from ...daemon import Daemon
 
from .. import get_default_engine
 
from . import get_sync_engines, synchronize_changes
 

	
 

	
 
@@ -38,7 +38,8 @@ class SyncDaemon(Daemon):
 
    def run(self):
 
        remote_engines = get_sync_engines()
 
        if remote_engines:
 
            synchronize_changes(db.engine, remote_engines)
 
            local_engine = get_default_engine(edbob.config)
 
            synchronize_changes(local_engine, remote_engines)
 

	
 

	
 
def get_daemon(pidfile=None):
rattail/db/sync/win32.py
Show inline comments
 
@@ -31,10 +31,10 @@ import logging
 
import threading
 

	
 
import edbob
 
from edbob import db
 

	
 
from rattail.win32.service import Service
 
from rattail.db.sync import get_sync_engines, synchronize_changes
 
from ...win32.service import Service
 
from .. import get_default_engine
 
from . import get_sync_engines, synchronize_changes
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -61,14 +61,13 @@ class DatabaseSynchronizerService(Service):
 
        if not Service.Initialize(self):
 
            return False
 

	
 
        edbob.init_modules(['rattail.db'])
 

	
 
        local_engine = get_default_engine(edbob.config)
 
        remote_engines = get_sync_engines()
 
        if not remote_engines:
 
            return False
 

	
 
        thread = threading.Thread(target=synchronize_changes,
 
                                  args=(db.engine, remote_engines))
 
                                  args=(local_engine, remote_engines))
 
        thread.daemon = True
 
        thread.start()
 
        return True
tests/db/sync/test_init.py
Show inline comments
 
@@ -354,15 +354,15 @@ class SynchronizerTests(SyncTestCase):
 

	
 
class ModuleTests(TestCase):
 

	
 
    @patch('rattail.db.sync.edbob')
 
    def test_get_sync_engines(self, edbob):
 
    @patch.multiple('rattail.db.sync', edbob=DEFAULT, get_engines=DEFAULT)
 
    def test_get_sync_engines(self, edbob, get_engines):
 

	
 
        # nothing configured
 
        edbob.config.get.return_value = None
 
        self.assertIsNone(sync.get_sync_engines())
 

	
 
        # fake config with 2 out of 3 engines synced
 
        edbob.engines = {
 
        get_engines.return_value = {
 
            'one': 'first',
 
            'two': 'second',
 
            'three': 'third',
tests/db/sync/test_linux.py
Show inline comments
 
@@ -8,10 +8,11 @@ from rattail.db.sync import linux
 
class SyncDaemonTests(TestCase):
 

	
 
    @patch.multiple('rattail.db.sync.linux',
 
                    db=DEFAULT,
 
                    edbob=DEFAULT,
 
                    get_default_engine=DEFAULT,
 
                    get_sync_engines=DEFAULT,
 
                    synchronize_changes=DEFAULT)
 
    def test_run(self, db, get_sync_engines, synchronize_changes):
 
    def test_run(self, edbob, get_default_engine, get_sync_engines, synchronize_changes):
 

	
 
        daemon = linux.SyncDaemon('/tmp/rattail_dbsync.pid')
 

	
 
@@ -19,12 +20,14 @@ class SyncDaemonTests(TestCase):
 
        get_sync_engines.return_value = None
 
        daemon.run()
 
        get_sync_engines.assert_called_once_with()
 
        self.assertFalse(get_default_engine.called)
 
        self.assertFalse(synchronize_changes.called)
 

	
 
        # with remote engines configured
 
        get_sync_engines.return_value = 'fake_remotes'
 
        get_default_engine.return_value = 'fake_local'
 
        daemon.run()
 
        synchronize_changes.assert_called_once_with(db.engine, 'fake_remotes')
 
        synchronize_changes.assert_called_once_with('fake_local', 'fake_remotes')
 

	
 

	
 
class ModuleTests(TestCase):
0 comments (0 inline, 0 general)