Coverage for janitoo.bus : 63%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
A physical bus : i2c, 1-wire, ... """
This file is part of Janitoo.
Janitoo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Janitoo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Janitoo. If not, see <http://www.gnu.org/licenses/>.
"""
#~ logging.getLogger(__name__).addHandler(logging.NullHandler())
############################################################## #Check that we are in sync with the official command classes #Must be implemented for non-regression
##############################################################
"""A bus holds components A bus is mapped in a controller node
Bus aggregation --------------- A master bus can aggregate multiple bus to hold different compenents on the same bus.
Look at janitoo_raspberry_fishtank, janitoo_lapinoo, ...
Bus extension --------------- A bus can be extended to add new features, shared resource, ...
Look at janitoo_raspberry_spi, janitoo_raspberry_i2c and janitoo_raspberry_i2c_pca9865, janitoo_events and janitoo_events_cron, ...
""" """Initialise the bus A bus can define values to configure itself. A bus can agregate other bus. Values from the buss are exported to the master. So they must be prefixed by the oid of the bus (in a hard way not usinf self.oid)
:param oid: The oid implemented by the bus. :type oid: str """ except: """The options""" """The product name of the node""" """The product type of the node""" """The name"""
""" """ except: pass
'''Retrieve a bus's private value. Take care of exported buses This is the preferred way to retrieve a value of the bus ''' #~ if self._export_prefix is not None: #~ value_uuid = "%s%s"%(self._export_prefix, value_uuid) #~ logger.debug("[%s] - Look for value %s on bus %s", self.__class__.__name__, value_uuid, self) if value_uuid in self.values: return self.values[value_uuid]
'''Export values to all targets''' logger.debug("[%s] - Export value %s to bus %s", self.__class__.__name__, value, target)
'''Export object to all targets''' logger.debug("[%s] - Export attrs to all buses", self.__class__.__name__) if hasattr(target, objname):
'''Clean exported object from all targets''' for target in self._masters: delattr(target, objname) else: logger.warning("[%s] - Missing attribute found %s when cleaning. Continue anyway.", self.__class__.__name__, objname)
'''Update object to all targets''' for target in self._masters: setattr(target, objname, obj)
"""Start the bus Components will be started by the nodemanager after retrieving configuration. """
"""Stop the bus and components"""
def uuid(self): """Return an uuid for the bus. Must be the same as the section name to retrieve the hadd of the controller
"""
"""Loop Don't do long task in loop. Use a separated thread to not perturbate the nodeman
"""
"""Add a component on the bus
"""
"""Find components using an oid """ components = [ self.components[addr] for addr in self.components if self.components[addr].oid == component_oid ] return components
"""Find a value using its uuid and the component oid """ components = self.find_components(component_oid) if len(components)==0: return [] vuuid='%s'%(value_uuid) res = [] for component in components: if component.node is not None: for value in component.node.values: if component.node.values[value].uuid == value_uuid: res.append(component.node.values[value]) return res
"""Create a node associated to this bus """ cmd_classes=self.cmd_classes, hadd=hadd, name=name, product_name=self.product_name, product_type=self.product_type, oid=self.oid, **kwargs) #~ self.check_heartbeat = self.node.check_heartbeat
"""Check that the bus is 'available'. Is replaced by the node one when it's creates
""" return False
""""Extend the bus with methods found in entrypoints """ if eps is None: return for entrypoint in iter_entry_points(group = '%s.extensions'%oid): if entrypoint.name in eps: logger.info('[%s] - Extend bus %s with %s', self.__class__.__name__, oid, entrypoint.module_name ) extend = entrypoint.load() extend( self )
""""Load extensions from config file. """ logger.debug('[%s] - Load bus extensions %s with in section %s', self.__class__.__name__, oid, self.oid ) try: exts = self.options.get_option(self.oid, 'extensions', default="").split(',') except: logger.warning("[%s] - Can't load_extensions", self.__class__.__name__, exc_info=True) exts = [] self.extend_from_entry_points(oid, exts)
"""Load a kernel module. Needs to be root (raspberry)
:param str module: the kernel module to load :param str params: module parameters """ try: cmd = '/sbin/modprobe %s %s' % (module, params) process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() stdout = [x for x in stdout.split("\n") if x != ""] if process.returncode < 0 or len(stderr): for error in stderr: logger.error(error) else: return True except : logger.exception("Can't load kernel module %s", module)
"""Remove a kernel module. Needs to be root (raspberry)
:param str module: the kernel module to remove """ try: cmd = '/sbin/rmmod %s' % (module) process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() stdout = [x for x in stdout.split("\n") if x != ""] stderr = [x for x in stderr.split("\n") if x != ""] if process.returncode < 0 or len(stderr): for error in stderr: logger.error(error) else: return True except : logger.exception("Can't remove kernel module %s", module) |