def loadzones(): fp = defs.ZONES_INDEX_FILE # if file exists if createNewFile(fp) == None: with open(fp, "r") as f: for line in f: line = line[:-1] if line == "": continue delim = line.find(':') zid = int(line[:delim]) filename = line[delim + 1:] # check to make sure zone id doesn't already exist if zid in hub.zones.keys(): print "Zone ID %d already exists!" % int(zid) continue # construct zone with zone id num, and filename tzone = zone.zone(zid, filename) # update zone dict hub.zones.update({zid: tzone})
def instantiate_entity(self, e, soap_client): """Instantiate an appropriate python class given an entity returned from a SOAP call. :param e: SOAP entity. :param soap_client: BAM SOAP client connection for the entity instance to use when accessing the API. :return: A type specific instance object of the SOAP entity or generic entity object. None if there is no type. """ if 'type' in e: t = e['type'] if t == entity.Configuration: return configuration(self, e, soap_client) elif t == entity.User: return user(self, e, soap_client) elif t == entity.Zone: return zone(self, e, soap_client) elif t == entity.View: return view(self, e, soap_client) elif t == entity.IP4Block: return ip4_block(self, e, soap_client) elif t == entity.IP4Network: return ip4_network(self, e, soap_client) elif t == entity.HostRecord: return host_record(self, e, soap_client) elif t == entity.AliasRecord: return alias_record(self, e, soap_client) elif t == entity.MXRecord: return mx_record(self, e, soap_client) elif t == entity.TXTRecord: return text_record(self, e, soap_client) elif t == entity.HINFORecord: return host_info_record(self, e, soap_client) elif t == entity.SRVRecord: return srv_record(self, e, soap_client) elif t == entity.NAPTRRecord: return naptr_record(self, e, soap_client) elif t == entity.ExternalHostRecord: return external_host_record(self, e, soap_client) elif t == entity.GenericRecord: return generic_record(self, e, soap_client) elif t == entity.EnumZone: return enum_zone(self, e, soap_client) elif t == entity.EnumNumber: return enum_number(self, e, soap_client) elif t in deployment_role.roles: return deployment_role(self, e, soap_client) elif t == entity.IP4Address: return ip4_address(self, e, soap_client) elif t == entity.Server: return server(self, e, soap_client) else: return entity(self, e, soap_client) else: return None
def hubinit(): # clear lists hub.clients = [] # load persistent data file loadpersistentdata() # load accounts hub.accounts = account.accountmanager() # load commands hub.cmds_main = command.initmaincommands() hub.cmds_main.setinvalidfunction(command.maingameinvalid) # timer hub.timer = timer.timer() print "Timer start:%f" % hub.timer.getstarttime() # load items loaditems() # load mobs loadmobs() # load zones loadzones() # if zone 0 room 0 does not exist try: troom = hub.zones[0].getroom(0) except: print "Zone 0 - Room 0 does not exist! Creating default.." newzone = zone.zone(0, "default.zn", True) newzone.newroom("Default Room") newzone.getroom(0).setdescription("This is a default room.") hub.zones.update({0: newzone}) # init summary print "Loaded %d accounts." % hub.accounts.count() print "Loaded %d common items." % len(hub.commonitems) print "Loaded %d common mobs." % len(hub.commonmobs) print "Loaded %d zones." % len(hub.zones.keys())
def defaultzones(): ##### # ZONES / ROOMS newzone = zone.zone(0, "whiteeagle.zn", True) newzone.newroom("White Eagle Tavern") #0 newzone.newroom("Hallway") #1 newzone.newroom("Store Room") #2 newzone.newroom("Cellar") #3 newzone.newroom("Tatton Road") #4 newzone.newroom("Tatton Road") #5 newzone.newroom("Tatton Road") #6 newzone.newroom("Armorer") #7 newzone.getroom(0).setdescription( "You are standing in a narrow tavern that runs east to west. It smells of sour booze and stale tobacco. A long polished bar runs along the north side of the room. Various crusty regulars sit huddled together in clumps." ) newzone.getroom(0).adddescriptor( {"bar": "The bar looks fairly scuffed up, possibly due to fighting."}) newzone.getroom(0).newspawner(hub.finduidbyname("white eagle sign"), 5000) newzone.getroom(0).newspawner(hub.finduidbyname("dagger"), 5) newzone.getroom(0).getspawners()[-1].setmaxcount(1) newzone.getroom(0).newspawner(hub.finduidbyname("gil"), 5) newzone.getroom(1).newspawner(hub.finduidbyname("rabbit"), 5) newzone.getroom(1).newspawner(hub.finduidbyname("sack"), 5000) newzone.getroom(1).setdescription( "This hallway leads to the various rentable rooms of the tavern.") newzone.getroom(1).additem(hub.commonitems[2].create()) newzone.getroom(2).setdescription( "This is the storeroom of the White Eagle. Various shelves and crates fill the room. It smells slightly musty here but looks pretty well maintained." ) newzone.getroom(2).adddescriptor( {"shelves": "The shelves are lined with various jars."}) newzone.getroom(2).adddescriptor({ "jars": "The jars on the shelves contain various pickled or preserved foods." }) newzone.getroom(2).adddescriptor({ "crates": "Several large crates take up most of the space in the storeroom." }) newzone.getroom(2).newspawner(hub.finduidbyname("bread"), 5) newzone.getroom(2).newspawner(hub.finduidbyname("beer"), 5) newzone.getroom(3).setdescription("A dusty old cellar.") newzone.getroom(3).newspawner(hub.finduidbyname("coin"), 5) newzone.getroom(3).getspawners()[-1].setstack(5) newzone.getroom(4).setdescription( "Tatton road stretches from east to west.") newzone.getroom(5).setdescription( "Tatton road stretches from east to west.") newzone.getroom(6).setdescription( "Tatton road stretches from east to west.") newzone.getroom(7).setdescription( "You are standing in the armorer's shop. It smells of leather and oil." ) newzone.getroom(7).newspawner(hub.finduidbyname("leather jacket"), 5) newzone.connectrooms(newzone.getroom(0), "east", newzone.getroom(1), "west") newzone.connectrooms(newzone.getroom(0), "west", newzone.getroom(2), "east") newzone.connectrooms(newzone.getroom(0), "down", newzone.getroom(3), "up") newzone.connectrooms(newzone.getroom(0), "south", newzone.getroom(4), "north") newzone.connectrooms(newzone.getroom(4), "west", newzone.getroom(5), "east") newzone.connectrooms(newzone.getroom(4), "east", newzone.getroom(6), "west") newzone.connectrooms(newzone.getroom(4), "south", newzone.getroom(7), "north") hub.zones.update({0: newzone})
def test_temperature_40_degree_u_2(self): # make sure the shuffled sequence does not lose any elements self.prova = zone.zone('.\green_test_40_vent') self.prova.T[8,9] self.assertEqual(self.prova.T[8,8], 276.10736259459225)
def test_temperature_closed(self): # make sure the shuffled sequence does not lose any elements self.prova = zone.zone('.\green_test_no_vent') self.prova.T[8,9] self.assertEqual(self.prova.T[8,8], 278.93615489353033)
def setUp(self): self.prova = zone.zone('.\green_test_no_vent')
def handleRead(self, pin, isOpen): zone = self.zones[pin] if zone is not None: if(isOpen and not zone.isOpen): self.sendMessage(zone.name + " opened") zone.isOpen = True elif(not isOpen and zone.isOpen): zone.isOpen = False def sendMessage(self, message): timenow = datetime.datetime.now().time() if(timenow > self.on or timenow < self.off): self.sms.sendMessage(message, self.c["sms_from"], self.c["sms_to"]) def run(self): aio = gpio(list(self.zones.keys()), self.handleRead) aio.run() config = configparser.ConfigParser() config.read_file(open('alertme.cfg')) zones = [ zone(23, "Back door"), zone(24, "Front door") ] app(config, zones).run()