Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _provide_domain_slave_mapper():
from stoqlib.gui.interfaces import IDomainSlaveMapper
from stoqlib.gui.slaves.domainslavemapper import DefaultDomainSlaveMapper
provide_utility(IDomainSlaveMapper, DefaultDomainSlaveMapper(),
replace=True)
def _provide_current_user():
default_store = get_default_store()
user = default_store.find(LoginUser, username=u'admin').one()
assert user
provide_utility(ICurrentUser, user, replace=True)
def _provide_app_info():
from stoqlib.lib.interfaces import IAppInfo
from stoqlib.lib.appinfo import AppInfo
info = AppInfo()
info.set(u"name", u"Stoqlib")
info.set(u"version", u"1.0.0")
provide_utility(IAppInfo, info)
def testGet(self):
self.assertEqual(None, get_utility(IBanana, None))
provide_utility(IBanana, o)
self.assertRaises(TypeError, get_utility, object)
self.assertEqual(get_utility(IBanana), o)
def register_config(config):
from kiwi.component import provide_utility
global _config
_config = config
try:
provide_utility(IStoqConfig, config, replace=True)
except NoConfigurationError:
msg = _(u"Error: Stoq configuration is not avaiable. Check that the "
"current user has a configuration file (~/.stoq/stoq.conf).")
if os.geteuid() == 0:
msg += _('\n\nYou are running stoq using sudo. That is not '
'recommended.')
raise SystemExit(msg)
def set_station_by_name(self, name):
"""
Set the currently station by given name.
:param name: name of the station
"""
station = BranchStation.selectOneBy(name=name, connection=self.conn)
# We can't use set_current_branch_station because we want to
# replace the current utilities in some cases
if station:
log.info("Setting BranchStation to %s" % (station.name, ))
provide_utility(ICurrentBranchStation, station, replace=True)
provide_utility(ICurrentBranch, station.branch, replace=True)
def get_plugin_manager():
"""Provides and returns the plugin manager
@attention: Try to always use this instead of getting the utillity
by hand, as that could not have been provided before.
:returns: an :class:`PluginManager` instance
"""
manager = get_utility(IPluginManager, None)
if not manager:
manager = PluginManager()
provide_utility(IPluginManager, manager)
return manager
def get_payment_operation_manager():
"""Returns the payment operation manager"""
pmm = get_utility(IPaymentOperationManager, None)
if not pmm:
from stoqlib.lib.payment import PaymentOperationManager
pmm = PaymentOperationManager()
provide_utility(IPaymentOperationManager, pmm)
return pmm
logger.info('_create_station')
if self.create_examples:
branch = api.sysparam.get_object(store, 'MAIN_COMPANY')
assert branch
provide_utility(ICurrentBranch, branch)
else:
branch = None
station_name = get_hostname()
if store.find(BranchStation, branch=branch, name=station_name).one():
return
station = BranchStation(store=store,
is_active=True,
branch=branch,
name=station_name)
provide_utility(ICurrentBranchStation, station)