def scan(): transport = TransportBluepy() registry = SkoobotRegistry() rawDevices = transport.findRawDevices() skoobots = [] for device in rawDevices: scanList = device.getScanData() for scanItem in scanList: if scanItem[0] == 9 and scanItem[2] == "Skoobot": skoobots.append(device) for skoobot in skoobots: # print(transport.rawDeviceInfoStr(skoobot)) addr = skoobot.addr registry.addSkoobot(addr) name = registry.getSkoobotsByAddress(addr)[0][1] if registry.getDefaultName() == None: registry.setDefault(name) defaultText = " (default)" if registry.getDefaultName() == name else "" msg = "Added Skoobot {0:s} to registry with name {1:s}{2:s}" print(msg.format(addr, name, defaultText)) print("Saving to list of Skoobots to registry {0:s}".format( registry.registryPath)) registry.save() shutil.chown(registry.registryPath, os.getlogin())
def testSave(self): """ Tests for the save() method Make sure that save() works, except when the registry is marked invalid. """ registry = SkoobotRegistry(self.tempPath) altSkooAddr = "aa:aa:aa:aa:aa:aa" altSkooName = "Alt" extraSkooAddr = "ee:ee:ee:ee:ee:ee" extraSkooName = "Extra" with self.subTest("Undo alterations"): registry.addSkoobot(altSkooAddr, altSkooName) registry.setDefault(altSkooAddr) self.assertEqual(4, len(registry.registry)) registry.load() self.assertEqual(3, len(registry.registry)) self.assertEqual(self.skooName, registry.getDefaultName()) with self.subTest("Alter and save"): registry.addSkoobot(altSkooAddr, altSkooName) registry.setDefault(altSkooAddr) self.assertEqual(4, len(registry.registry)) # Save the state with the AltSkootbot entry registry.save() registry.addSkoobot(extraSkooAddr, extraSkooName) registry.setDefault(extraSkooAddr) self.assertEqual(5, len(registry.registry)) self.assertEqual(extraSkooName, registry.getDefaultName()) # Restore to the save() state registry.load() self.assertEqual(4, len(registry.registry)) self.assertEqual(altSkooName, registry.getDefaultName()) with self.subTest("Don't save invalid"): registry.addSkoobot(extraSkooAddr, altSkooName) registry.setDefault(extraSkooAddr) self.assertEqual(5, len(registry.registry)) registry.valid = False # Fail to save the state with the Extra entry registry.save() # Restore to the previous save() state registry.load() self.assertEqual(4, len(registry.registry)) self.assertEqual(altSkooName, registry.getDefaultName())