support deinit
This commit is contained in:
parent
37c0ee8938
commit
9ff2f70284
3 changed files with 41 additions and 9 deletions
|
|
@ -34,7 +34,7 @@ class Weboob(object):
|
||||||
WORKDIR = os.path.join(os.path.expanduser('~'), '.weboob')
|
WORKDIR = os.path.join(os.path.expanduser('~'), '.weboob')
|
||||||
BACKENDS_FILENAME = 'backends'
|
BACKENDS_FILENAME = 'backends'
|
||||||
|
|
||||||
def __init__(self, workdir=WORKDIR, backends_filename=None, scheduler=None):
|
def __init__(self, workdir=WORKDIR, backends_filename=None, scheduler=None, storage=None):
|
||||||
self.workdir = workdir
|
self.workdir = workdir
|
||||||
self.backend_instances = {}
|
self.backend_instances = {}
|
||||||
|
|
||||||
|
|
@ -59,8 +59,20 @@ class Weboob(object):
|
||||||
backends_filename = os.path.join(self.workdir, backends_filename)
|
backends_filename = os.path.join(self.workdir, backends_filename)
|
||||||
self.backends_config = BackendsConfig(backends_filename)
|
self.backends_config = BackendsConfig(backends_filename)
|
||||||
|
|
||||||
|
# Storage
|
||||||
|
self.storage = storage
|
||||||
|
|
||||||
|
def __deinit__(self):
|
||||||
|
self.deinit()
|
||||||
|
|
||||||
|
def deinit(self):
|
||||||
|
self.unload_backends()
|
||||||
|
|
||||||
def load_backends(self, caps=None, names=None, storage=None):
|
def load_backends(self, caps=None, names=None, storage=None):
|
||||||
loaded = {}
|
loaded = {}
|
||||||
|
if storage is None:
|
||||||
|
storage = self.storage
|
||||||
|
|
||||||
self.backends_loader.load_all()
|
self.backends_loader.load_all()
|
||||||
for backend_name, backend in self.backends_loader.loaded.iteritems():
|
for backend_name, backend in self.backends_loader.loaded.iteritems():
|
||||||
if caps is not None and not backend.has_caps(caps) or \
|
if caps is not None and not backend.has_caps(caps) or \
|
||||||
|
|
@ -72,6 +84,9 @@ class Weboob(object):
|
||||||
|
|
||||||
def load_configured_backends(self, caps=None, names=None, storage=None):
|
def load_configured_backends(self, caps=None, names=None, storage=None):
|
||||||
loaded = {}
|
loaded = {}
|
||||||
|
if storage is None:
|
||||||
|
storage = self.storage
|
||||||
|
|
||||||
for instance_name, backend_name, params in self.backends_config.iter_backends():
|
for instance_name, backend_name, params in self.backends_config.iter_backends():
|
||||||
if '_enabled' in params and not params['_enabled']:
|
if '_enabled' in params and not params['_enabled']:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -115,12 +115,16 @@ class BaseApplication(object):
|
||||||
self._parser.add_option_group(logging_options)
|
self._parser.add_option_group(logging_options)
|
||||||
self._parser.add_option('--shell-completion', action='store_true', help=optparse.SUPPRESS_HELP)
|
self._parser.add_option('--shell-completion', action='store_true', help=optparse.SUPPRESS_HELP)
|
||||||
|
|
||||||
def create_storage(self, path=None, klass=None):
|
def deinit(self):
|
||||||
|
self.weboob.deinit()
|
||||||
|
|
||||||
|
def create_storage(self, path=None, klass=None, localonly=False):
|
||||||
"""
|
"""
|
||||||
Create a storage object.
|
Create a storage object.
|
||||||
|
|
||||||
@param path [str] an optional specific path.
|
@param path [str] an optional specific path.
|
||||||
@param klass [IStorage] what klass to instance.
|
@param klass [IStorage] what klass to instance.
|
||||||
|
@param localonly [bool] if True, do not set it on the Weboob object.
|
||||||
@return a IStorage object
|
@return a IStorage object
|
||||||
"""
|
"""
|
||||||
if klass is None:
|
if klass is None:
|
||||||
|
|
@ -135,6 +139,10 @@ class BaseApplication(object):
|
||||||
storage = klass(path)
|
storage = klass(path)
|
||||||
self.storage = ApplicationStorage(self.APPNAME, storage)
|
self.storage = ApplicationStorage(self.APPNAME, storage)
|
||||||
self.storage.load(self.STORAGE)
|
self.storage.load(self.STORAGE)
|
||||||
|
|
||||||
|
if not localonly:
|
||||||
|
self.weboob.storage = storage
|
||||||
|
|
||||||
return storage
|
return storage
|
||||||
|
|
||||||
def load_config(self, path=None, klass=None):
|
def load_config(self, path=None, klass=None):
|
||||||
|
|
@ -258,6 +266,7 @@ class BaseApplication(object):
|
||||||
|
|
||||||
app._handle_app_options()
|
app._handle_app_options()
|
||||||
|
|
||||||
|
try:
|
||||||
try:
|
try:
|
||||||
sys.exit(app.main(args))
|
sys.exit(app.main(args))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
@ -266,3 +275,5 @@ class BaseApplication(object):
|
||||||
except ConfigError, e:
|
except ConfigError, e:
|
||||||
print 'Configuration error: %s' % e
|
print 'Configuration error: %s' % e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
finally:
|
||||||
|
app.deinit()
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,12 @@ class BaseBackend(object):
|
||||||
self.storage = BackendStorage(self.name, storage)
|
self.storage = BackendStorage(self.name, storage)
|
||||||
self.storage.load(self.STORAGE)
|
self.storage.load(self.STORAGE)
|
||||||
|
|
||||||
|
def deinit(self):
|
||||||
|
"""
|
||||||
|
This abstract method is called when the backend is unloaded.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def browser(self):
|
def browser(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue