当前位置: 首页>>代码示例>>Python>>正文


Python PluginManager.action方法代码示例

本文整理汇总了Python中pluginmanager.PluginManager.action方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.action方法的具体用法?Python PluginManager.action怎么用?Python PluginManager.action使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pluginmanager.PluginManager的用法示例。


在下文中一共展示了PluginManager.action方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WicdDaemon

# 需要导入模块: from pluginmanager import PluginManager [as 别名]
# 或者: from pluginmanager.PluginManager import action [as 别名]
class WicdDaemon(dbus.service.Object):
    def __init__(self, bus_name, options, object_path="/org/wicd/daemon"):
        ''' Creates a new WicdDaemon object. '''
        dbus.service.Object.__init__(self, bus_name=bus_name,
                                     object_path=object_path)
        self.options = options
        self.interface_manager = InterfaceManager(self.StatusChange,
                                                  self.StateChange)
        self.plugin_manager = PluginManager(self)
        import wglobals
        wglobals.daemon = self
        wglobals.plugin_manager = self.plugin_manager
        if not options.no_load_configuration:
            self.LoadConfiguration()
        self.plugin_manager.action('start')
    @dbus.service.method('org.wicd.daemon')
    def GetVersion(self):
        """ Returns the version number. """
        version = 'VeryPluggableBackends SVN'
        return version
    @dbus.service.method('org.wicd.daemon.interface')
    def ListInterfaces(self):
        ''' Returns the names of all the interfaces. '''
        data = self.interface_manager.get_all_names()
        if data in [(), [], {}]:
            data = ('',)
        return data
    @dbus.service.method('org.wicd.daemon.interface')
    def CreateInterface(self, type, name):
        self.interface_manager.create(type, name)
    def _has_data(self, data_tuple):
        ''' Used to convert tuples sent over DBus to real tuples. '''
        if data_tuple in [('dbusdoesntallowemptytuples',), None, ()]:
            return None
        else:
            return data_tuple
    @dbus.service.method('org.wicd.daemon.interface')
    def GetInterfaceData(self, interface_name, method_name, data):
        ''' Gets the specified data from the specified interface. '''
        data = self.interface_action(interface_name, method_name, data, 'get_')
        if data in [(), [], {}]:
            data = ('dbusdoesntallowemptytuples',)
        logging.debug( 'returning %s', data )
        return data
    @dbus.service.method('org.wicd.daemon.interface')
    def SetInterfaceData(self, interface_name, method_name, data):
        ''' Sets the specified data on the specified interface. '''
        self.interface_action(interface_name, method_name, data, 'set_')
    @dbus.service.method('org.wicd.daemon.interface')
    def DoInterfaceAction(self, interface_name, method_name, data):
        ''' Runs the specified command on the specified interface. '''
        self.interface_action(interface_name, method_name, data, 'do_')
    def interface_action(self, interface_name, method_name, data, prefix=''):
        ''' Runs a specified action on a specified method that starts with prefix. '''
        if not self.interface_manager.exists(interface_name):
            raise WicdError('Specified interface does not exist')
        interface = self.interface_manager.get(interface_name)
        if not hasattr(interface, (prefix + method_name)):
            raise WicdError('%s: method does not exist' % (prefix + method_name))
        self.plugin_manager.action('starting_action', (interface_name,
                                                      (prefix + method_name),
                                                      self._has_data(data)))
        method = getattr(interface, prefix + method_name)
        logging.debug( '%s interface action calling %s' % (prefix[:-1], method) )
        return_data = None
        if self._has_data(data):
            return_data = method(*data)
        else:
            return_data = method()
        self.plugin_manager.action('finished_action', (interface_name,
                                                      (prefix + method_name),
                                                      self._has_data(data),
                                                      return_data))
        return return_data
    @dbus.service.method('org.wicd.daemon')
    def SaveConfiguration(self):
        ''' Saves the state of the daemon. '''
        logging.debug( 'saving configuration...' )
        self.interface_manager.save()
    @dbus.service.method('org.wicd.daemon')
    def LoadConfiguration(self):
        ''' Loads the saved state of the daemon. '''
        logging.debug( 'loading configuration...' )
        self.interface_manager.load()
    @dbus.service.signal('org.wicd.daemon')
    def StatusChange(self, interface_name, previous_status, status):
        logging.debug( '%s: status changed from %s to %s', interface_name, previous_status, status)
        self.plugin_manager.action('signal_%s' % status, (previous_status, interface_name))
        self.plugin_manager.action('signal_%s_from_%s' % (status, previous_status), (interface_name, ))
    @dbus.service.signal('org.wicd.daemon')
    def StateChange(self, interface_name, state):
        logging.debug( '%s: status changed to %s', interface_name, state)
        self.plugin_manager.action('state_%s' % state, (interface_name, ))
    @dbus.service.signal('org.wicd.daemon')
    def Closing(self):
        logging.debug('Daemon shutting down...')
        self.plugin_manager.action('closing')
开发者ID:,项目名称:,代码行数:99,代码来源:


注:本文中的pluginmanager.PluginManager.action方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。