本文整理汇总了Python中stoqlib.lib.pluginmanager.get_plugin_manager函数的典型用法代码示例。如果您正苦于以下问题:Python get_plugin_manager函数的具体用法?Python get_plugin_manager怎么用?Python get_plugin_manager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_plugin_manager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_plugin_manager
def test_get_plugin_manager(self):
# PluginManager should be a singleton
self.assertEqual(self._manager, get_plugin_manager())
self.assertEqual(id(self._manager), id(get_plugin_manager()))
# Just check if it really provides IPluginManager
self.assertTrue(IPluginManager.providedBy(self._manager))
self.assertTrue(isinstance(self._manager, PluginManager))
示例2: run_embedded
def run_embedded(self, appdesc, app_window, params=None):
app = self._load_app(appdesc, app_window)
app.launcher = app_window
self._current_app = app
self._appname = appdesc.name
if appdesc.name in self._blocked_apps:
app_window.show()
return
app.run(params)
# Possibly correct window position (livecd workaround for small
# screens)
from stoqlib.lib.pluginmanager import get_plugin_manager
manager = get_plugin_manager()
from stoqlib.api import api
if (api.sysparam(api.get_default_store()).DEMO_MODE
and manager.is_active(u'ecf')):
pos = app.main_window.toplevel.get_position()
if pos[0] < 220:
app.main_window.toplevel.move(220, pos[1])
return app
示例3: setUp
def setUp(self):
super(TestPluginManager, self).setUp()
# Generate 2 instances of plugins that will be used for testing later.
# '_dependent_plugin' will require 'independent_plugin' activation prior
# to it's own.
self._independent_plugin = _TestPlugin()
self._dependent_plugin = _TestDependentPlugin()
# Since the plugins are commited inside pluginmanager, try to remove
# it first, or we will have problems if STOQLIB_TEST_QUICK is set.
store = new_store()
plugins = set(InstalledPlugin.get_plugin_names(store=self.store))
expected = set([u'ecf', u'nfe', u'optical'])
self.assertTrue(expected.issubset(plugins))
ind_name = self._independent_plugin.name
dep_name = self._dependent_plugin.name
plugin_names = [ind_name, dep_name]
test_plugins = store.find(InstalledPlugin,
InstalledPlugin.plugin_name.is_in(plugin_names))
for plugin in test_plugins:
store.remove(plugin)
store.commit()
store.close()
self._manager = get_plugin_manager()
self._register_test_plugin()
示例4: cmd_help
def cmd_help(self, options):
"""Show available commands help"""
cmds = []
max_len = 0
for attr in dir(self):
if not attr.startswith('cmd_'):
continue
name = attr[4:]
doc = getattr(self, attr).__doc__ or ''
max_len = max(max_len, len(name))
cmds.append((name, doc.split(r'\n')[0]))
max_len = max_len + 2
print('Usage: stoqdbadmin [plugin] <command> [<args>]')
print()
print('Available commands:')
for name, doc in cmds:
print(' %s%s' % (name.ljust(max_len), doc))
self._read_config(options, load_plugins=False,
register_station=False)
from stoqlib.lib.pluginmanager import get_plugin_manager
manager = get_plugin_manager()
for plugin_name in manager.installed_plugins_names:
plugin = manager.get_plugin(plugin_name)
for command in plugin.get_dbadmin_commands():
print(' %s %s' % (plugin_name, command))
return 0
示例5: run_command
def run_command(self, options, cmd, args):
func = getattr(self, 'cmd_' + cmd, None)
if func is None:
self._read_config(options, load_plugins=False,
register_station=False)
from stoqlib.lib.pluginmanager import get_plugin_manager
manager = get_plugin_manager()
if cmd in manager.installed_plugins_names:
if not len(args):
raise SystemExit(
"%s: %s requires at least 2 argument(s)" % (
self.prog_name, cmd))
plugin = manager.get_plugin(cmd)
return plugin.handle_dbadmin_command(args[0], options, args[1:])
else:
print("%s: Invalid command: `%s' type `%s help' for usage." % (
self.prog_name, cmd, self.prog_name))
return 1
nargs = func.func_code.co_argcount - 2
if len(args) < nargs:
raise SystemExit(
"%s: %s requires at least %d argument(s)" % (
self.prog_name, cmd, nargs))
self.args = args
return func(options, *args)
示例6: _start_tasks
def _start_tasks(self):
tasks = [
_Task(start_backup_scheduler),
_Task(start_server),
_Task(start_rtc),
]
if start_xmlrpc_server not in [t.func for t in
self._get_children()]:
tasks.append(_Task(start_xmlrpc_server, self._xmlrpc_conn2))
manager = get_plugin_manager()
for plugin_name in manager.installed_plugins_names:
plugin = manager.get_plugin(plugin_name)
if not hasattr(plugin, 'get_server_tasks'):
continue
# FIXME: Check that the plugin implements IPluginTask when
# we Stoq 1.11 is released
for plugin_task in plugin.get_server_tasks():
task_name = plugin_task.name
kwargs = {}
if plugin_task.handle_actions:
conn1, conn2 = multiprocessing.Pipe(True)
self._plugins_pipes[(plugin_name, task_name)] = conn1
kwargs['pipe_connection'] = conn2
tasks.append(_Task(plugin_task.start, **kwargs))
for t in tasks:
t.start()
示例7: checkout
def checkout(self, cancel_clear=False):
"""Initiates the sale wizard to confirm sale.
:param cancel_clear: If cancel_clear is true, the sale will be cancelled
if the checkout is cancelled.
"""
assert len(self.sale_items) >= 1
if self._current_store:
store = self._current_store
savepoint = 'before_run_fiscalprinter_confirm'
store.savepoint(savepoint)
else:
store = api.new_store()
savepoint = None
if self._trade:
if self._get_subtotal() < self._trade.returned_total:
info(_("Traded value is greater than the new sale's value. "
"Please add more items or return it in Sales app, "
"then make a new sale"))
return
sale = self._create_sale(store)
self._trade.new_sale = sale
self._trade.trade()
else:
sale = self._create_sale(store)
if sysparam.get_bool('CONFIRM_SALES_ON_TILL'):
sale.order()
store.commit()
else:
assert self._coupon
ordered = self._coupon.confirm(sale, store, savepoint,
subtotal=self._get_subtotal())
# Dont call store.confirm() here, since coupon.confirm()
# above already did it
if not ordered:
# FIXME: Move to TEF plugin
manager = get_plugin_manager()
if manager.is_active('tef') or cancel_clear:
self._cancel_order(show_confirmation=False)
elif not self._current_store:
# Just do that if a store was created above and
# if _cancel_order wasn't called (it closes the connection)
store.rollback(close=True)
return
log.info("Checking out")
self._coupon = None
POSConfirmSaleEvent.emit(sale, self.sale_items[:])
# We must close the connection only after the event is emmited, since it
# may use value from the sale that will become invalid after it is
# closed
store.close()
self._clear_order()
示例8: _setup_widgets
def _setup_widgets(self):
self._calc = CalculatorPopup(self.price, CalculatorPopup.MODE_SUB)
self.sale.set_text(unicode(self.model.sale.identifier))
self.description.set_text(self.model.sellable.get_description())
self.original_price.update(self.model.base_price)
self.price.set_adjustment(gtk.Adjustment(lower=0, upper=MAX_INT,
step_incr=1, page_incr=10))
unit = self.model.sellable.unit
digits = QUANTITY_PRECISION if unit and unit.allow_fraction else 0
for widget in [self.quantity, self.reserved]:
widget.set_digits(digits)
widget.set_adjustment(gtk.Adjustment(lower=0, upper=MAX_INT,
step_incr=1, page_incr=10))
manager = get_plugin_manager()
self.nfe_is_active = manager.is_active('nfe')
if not self.nfe_is_active:
self.cfop_label.hide()
self.cfop.hide()
if not self._can_reserve():
self.reserved.hide()
self.reserved_lbl.hide()
# We populate this even if it's hidden because we need a default value
# selected to add to the sale item
cfop_items = CfopData.get_for_sale(self.store)
self.cfop.prefill(api.for_combo(cfop_items))
self._update_total()
self.reserved.get_adjustment().set_upper(self.quantity_model.quantity)
示例9: _enable_plugins
def _enable_plugins():
manager = get_plugin_manager()
for plugin in [u'nfe', u'ecf']:
if not manager.is_installed(plugin):
# STOQLIB_TEST_QUICK won't let dropdb on testdb run. Just a
# precaution to avoid trying to install it again
manager.install_plugin(plugin)
示例10: close_till
def close_till(self, close_db=True, close_ecf=True):
"""Closes the till
There are 3 possibilities for parameters combination:
* *total close*: Both *close_db* and *close_ecf* are ``True``.
The till on both will be closed.
* *partial close*: Both *close_db* and *close_ecf* are ``False``.
It's more like a till verification. The actual user will do it
to check and maybe remove money from till, leaving it ready
for the next one. Note that this will not emit
'till-status-changed' event, since the till will not
really close.
* *fix conflicting status*: *close_db* and *close_ecf* are
different. Use this only if you need to fix a conflicting
status, like if the DB is open but the ECF is closed, or
the other way around.
:param close_db: If the till in the DB should be closed
:param close_ecf: If the till in the ECF should be closed
:returns: True if the till was closed, otherwise False
"""
is_partial = not close_db and not close_ecf
manager = get_plugin_manager()
# This behavior is only because of ECF
if not is_partial and not self._previous_day:
if (manager.is_active('ecf') and
not yesno(_("You can only close the till once per day. "
"You won't be able to make any more sales today.\n\n"
"Close the till?"),
Gtk.ResponseType.NO, _("Close Till"), _("Not now"))):
return
elif not is_partial:
# When closing from a previous day, close only what is needed.
close_db = self._close_db
close_ecf = self._close_ecf
if close_db:
till = Till.get_last_opened(self.store)
assert till
store = api.new_store()
editor_class = TillVerifyEditor if is_partial else TillClosingEditor
model = run_dialog(editor_class, self._parent, store,
previous_day=self._previous_day, close_db=close_db,
close_ecf=close_ecf)
if not model:
store.confirm(model)
store.close()
return
# TillClosingEditor closes the till
retval = store.confirm(model)
store.close()
if retval and not is_partial:
self._till_status_changed(closed=True, blocked=False)
return retval
示例11: setup_widgets
def setup_widgets(self):
marker('Setting up widgets')
# Only quotes have expire date.
self.expire_date.hide()
self.expire_label.hide()
# Hide client category widgets
self.client_category_lbl.hide()
self.client_category.hide()
# if the NF-e plugin is active, the client is mandantory in this
# wizard (in this situation, we have only quote sales).
if self.model.status == Sale.STATUS_QUOTE:
manager = get_plugin_manager()
mandatory_client = manager.is_active('nfe')
self.client.set_property('mandatory', mandatory_client)
marker('Filling sales persons')
salespersons = self.store.find(SalesPerson)
self.salesperson.prefill(api.for_person_combo(salespersons))
marker('Finished filling sales persons')
marker('Read parameter')
change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
if change_salesperson == ChangeSalespersonPolicy.ALLOW:
self.salesperson.grab_focus()
elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
self.salesperson.set_sensitive(False)
elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
self.model.salesperson = None
self.salesperson.grab_focus()
else:
raise AssertionError
marker('Finished reading parameter')
self._setup_clients_widget()
self._fill_transporter_combo()
self._fill_cost_center_combo()
if sysparam.get_bool('ASK_SALES_CFOP'):
self._fill_cfop_combo()
else:
self.cfop_lbl.hide()
self.cfop.hide()
self.create_cfop.hide()
# the maximum number allowed for an invoice is 999999999.
self.invoice_number.set_adjustment(
gtk.Adjustment(lower=1, upper=999999999, step_incr=1))
if not self.model.invoice_number:
new_invoice_number = Invoice.get_next_invoice_number(self.store)
self.invoice_model.invoice_number = new_invoice_number
else:
new_invoice_number = self.model.invoice_number
self.invoice_model.invoice_number = new_invoice_number
self.invoice_number.set_sensitive(False)
self.invoice_model.original_invoice = new_invoice_number
marker('Finished setting up widgets')
示例12: __init__
def __init__(self, store, model):
manager = get_plugin_manager()
self.nfe_is_active = manager.is_active('nfe')
self.proxy = None
self.icms_slave = None
self.ipi_slave = None
BaseEditor.__init__(self, store, model)
示例13: _on_EditorCreateEvent
def _on_EditorCreateEvent(self, editor, model, store, *args):
from stoqlib.gui.dialogs.saledetails import SaleDetailsDialog
manager = get_plugin_manager()
nfe_active = manager.is_active('nfe')
if not nfe_active and isinstance(editor, SaleDetailsDialog):
# Only display the coupon number if the nfe is not active.
editor.invoice_label.set_text(_('Coupon Number'))
editor.invoice_number.update(model.coupon_id)
示例14: _start_tasks
def _start_tasks(self):
tasks = [
Task('_xmlrpc', start_xmlrpc_server, self._xmlrpc_conn2),
# This is not working nice when using NTK lib (maybe related to the multiprocess lib).
# Must be executed as a separate process for now.
#Task('_flask', start_flask_server),
Task('_updater', start_plugins_update_scheduler,
self._updater_event, self._doing_backup),
Task('_backup', start_backup_scheduler, self._doing_backup),
]
# TODO: Make those work on windows
if not _is_windows:
tasks.extend([
Task('_htsql', start_htsql, self._htsql_port),
Task('_server', start_server),
Task('_rtc', start_rtc),
])
manager = get_plugin_manager()
for plugin_name in manager.installed_plugins_names:
plugin = manager.get_plugin(plugin_name)
if not hasattr(plugin, 'get_server_tasks'):
continue
# FIXME: Check that the plugin implements IPluginTask when
# we Stoq 1.11 is released
for plugin_task in plugin.get_server_tasks():
task_name = plugin_task.name
name = _get_plugin_task_name(plugin_name, task_name)
if self._manager.is_running(name):
continue
kwargs = {}
if plugin_task.handle_actions:
conn1, conn2 = multiprocessing.Pipe(True)
self._plugins_pipes[name] = conn1
kwargs['pipe_connection'] = conn2
# Since Windows has no os.fork, multiprocessing will actually
# run the process again and pass the required objects by
# pickling them. For some reason, passing a plugin task will
# break some places, since the it will make some objects
# like PluginManager be pickled/unpicled, and when unlicking
# it will run its contructor again, but it should wait
# to do that until we have configured the database.
func = (plugin_name, task_name)
tasks.append(Task(name, func, **kwargs))
for task in tasks:
if not self._manager.is_running(task.name):
self._manager.run_task(task)
# Close the default store because it not functioning anymore since the
# forked processes closed its "clone", but open a new one later
# or else Stoq will not be able to find this instance
set_default_store(None)
get_default_store()
示例15: __init__
def __init__(self, store):
header = _(u'Select the plugin you want to activate and click in '
'the apply button.')
BasicDialog.__init__(self, hide_footer=False,
size=PluginManagerDialog.size,
title=PluginManagerDialog.title,
header_text=header)
self.store = store
self._manager = get_plugin_manager()
self._setup_widgets()