Exemplo n.º 1
0
 def clearFiles(self,prefix):
     if path.exists("logs"):
         files = Glob(f"logs/*{prefix}.log")
         for f in files:
             Remove(f)
     else:
         mkdir("logs")
Exemplo n.º 2
0
 def changeStatus(self, status='ready'):
     if self.status == status:
         return
     oldStatus = self.status
     session = Glob.dbSession()
     self.setStatus(status)
     session.add(self)
     session.commit()
     session.close()
     Glob.logger.info("zone %s  %s -> %s" %
                      (self.zone_name, oldStatus, status))
Exemplo n.º 3
0
 def setStatusRecursively(self, status='armed'):
     session = Glob.dbSession()
     self.setStatus(status)
     exploredSubzones = set()
     for subzone in self._subzones:
         if subzone not in exploredSubzones:
             zoneObj = Glob.zones.getZone(subzone)
             session.add(zoneObj)
             zoneObj.setStatus(status)
             exploredSubzones.update(subzone)
     session.commit()
     session.close()
Exemplo n.º 4
0
 def noSensor(self, interval=30):
     '''
         return boolean - true if there is no sensor event in previous "interval" in minutes
     '''
     session = Glob.dbSession()
     for deviceName in self.getDevices():
         device = Glob.devices.getDevice(deviceName)
         if device is not None:
             session.add(device)
             if device.hasSensorEvent(interval):
                 session.close()
                 return False
     session.close()
     return True
Exemplo n.º 5
0
 def createDeviceInstance(self, unit, deviceId, deviceType, deviceName):
     '''
         initialize device driver and store it in self.devices dictionary
     '''
     deviceClass = self.oasisDeviceDriverClass(deviceType)
     module = importlib.import_module('drivers.' + deviceClass.lower())
     class_ = getattr(module, deviceClass)
     # get_or_create driver object
     session = Glob.dbSession()
     driverObj = turhousedb.get_or_create(
         session, class_, device_name=deviceName)
     driverObj.init()
     driverObj.setUnit(self.units[unit])
     driverObj.setOptions(Glob.config.getDeviceOptions(unit, deviceName))
     session.commit()
     session.close()
     # create lookup records
     self.devices[deviceId] = driverObj
     Glob.devices.registerDevice(deviceName, driverObj)
     if deviceType == 'RC-86K':
         id2 = deviceId ^ 1 << 20
         self.devices[id2] = driverObj
     return driverObj
Exemplo n.º 6
0
    def __init__(self):
        BaseManager.__init__(self)
        # init alarm zones
        session = Glob.dbSession()
        zones = Glob.config.getAlarmZones()
        for zoneName in zones:
            zone = turhousedb.get_or_create(session,
                                            AlarmZone,
                                            zone_name=zoneName)
            zone.init()
            session.add(zone)
            Glob.zones.registerZone(zoneName, zone)
            if 'status' in zones[zoneName]:
                zone.setStatus(zones[zoneName]['status'])
            if 'devices' in zones[zoneName]:
                for device in zones[zoneName]['devices']:
                    zone.addDevice(device)
            if 'subzones' in zones[zoneName]:
                for subzoneName in zones[zoneName]['subzones']:
                    if subzoneName in zones:
                        zone.addSubzone(subzoneName)
                    else:
                        Glob.logger.error("Unknown subzone %s -> %s " %
                                          (zoneName, subzoneName))
        session.commit()
        session.close()
        # atach event handlers
        self.sensorEvent += self.sensorEventHandler
        self.tamperEvent += self.tamperEventHandler
        self.controllerEvent += self.controllerEventHandler
        self.buttonEvent += self.buttonEventHandler

        for zoneName in zones:
            zone = Glob.zones.getZone(zoneName)
            Glob.logger.info("Zone %s devices: %s " %
                             (zoneName, zone.getDevices()))
Exemplo n.º 7
0
#"/home/michael/hw/morphforge/doc"
doc_src_dir = os.path.normpath( os.path.join(root, "doc") )

examples_dst_dir =  os.path.join(root, "doc/srcs_generated_examples")
examples_dst_dir_images =  os.path.join(root, "doc/srcs_generated_examples/images/")

examples_build_dir = os.path.join( LocMgr.get_tmp_path(), "mf_doc_build")
examples_build_dir_image_out = os.path.join( examples_build_dir,  "images/")


dirs = ['morphology', 'singlecell_simulation', 'multicell_simulation', 'advanced_examples']#, 'assorted' ]
example_subdirs = [ d for d in os.listdir(examples_src_dir) if d.startswith("""exset""") ]
dirs = sorted(example_subdirs)

example_srcs = list( itertools.chain( *[ sorted(Glob( Join(examples_src_dir, dir) + "/*.py") ) for dir in dirs] ) )




def clear_directory(d):
    if os.path.exists(d):
        shutil.rmtree(d)
    os.mkdir(d)




def parse_src_file(filename, docstring):
    d = open(filename, 'r').read()
Exemplo n.º 8
0
 def clearFiles(self, prefix):
     files = Glob(f"logs/*{prefix}.log")
     for f in files:
         Remove(f)
Exemplo n.º 9
0
 def processMessageSession(self, msgDict):
     session = Glob.dbSession()
     session.add(self)
     self.processMessage(msgDict)
     session.commit()
     session.close()
Exemplo n.º 10
0
 def processMessageSession(self, msgDict):
     session = Glob.dbSession()
     session.add(self)
     self.processMessage(msgDict)
     session.commit()
     session.close()