def __init__(self, dbPath, dbName): self.database = dbPath + dbName self.dataPath = dbPath self.visits = Visits() self.guests = Guests() self.reports = Reports(self) self.teams = Teams() self.accounts = Accounts() self.devices = Devices() self.unlocks = Unlocks() # needs path since it will open read only self.customReports = CustomReports(self.database) self.certifications = Certifications() self.members = Members() self.logEvents = LogEvents() if not os.path.exists(self.database): if not os.path.exists(dbPath): os.mkdir(dbPath) with self.dbConnect() as c: self.migrate(c, 0) else: with self.dbConnect() as c: data = c.execute('PRAGMA schema_version').fetchone() if data[0] != SCHEMA_VERSION: self.migrate(c, data[0])
def run_parser(self, file_path): """Call parse_network() from path specified. To do so first reinitzialize all modules and cycles_completed. """ # clear all at the begging self.cycles_completed = 0 self.names = Names() self.devices = Devices(self.names) self.network = Network(self.names, self.devices) self.monitors = Monitors(self.names, self.devices, self.network) self.scanner = Scanner(file_path, self.names) self.parser = Parser(self.names, self.devices, self.network, self.monitors, self.scanner) # Capture the stdout from parse_network() captured_stdout = io.StringIO() with redirect_stdout(captured_stdout): if self.parser.parse_network(): self.parse_success = True self.log_message(_("Succesfully parsed network.")) else: self.parse_success = False self.log_message(_("Failed to parse network.")) # Show error messages captured in activity log self.log_message(captured_stdout.getvalue(), self.MONOSPACE_FONT)
def GetPairedDevices(a): """returns all devices paired to the local interface""" devices = Devices() a = devices.returnPairedDevices() # for pDevice in a: # print pDevice return a
def GetPairedDevices(a): """returns all devices paired to the local interface""" print("Call to Get Paired Devices was made") devices = Devices() a = devices.returnPairedDevices() for pDevice in a: print pDevice return a
def PairDevice(self, s): print("Attempting to pair device at address: %s" % s) devices = Devices() devices.pairDevice(s) pairedDevices = devices.returnPairedDevices() for d in pairedDevices: if d == s: print("Device Paired") session.NotifyHost(1, d) return print("Problem pairing device") session.NotifyHost(-1, "")
def HostToAgentMessage(self, s): print ("A message came in from the host: "), print (s) if self.m_device != None: if s == 'YES': set_trusted(self.m_device) pairedDeviceAddress = dbus.String(Devices().returnFirstPairedDevice()) print(">>>>> PAIRED DEVICE IS TYPE: "), print(type(pairedDeviceAddress)) print(pairedDeviceAddress) agent.AgentToNotifyHost(2, "CC:44:63:20:D0:5F") # FIXME: WHY IS THIS NOT WORKING??? dbus.String(pariredDeviceAddress)) # #agent.AgentToNotifyHost(2, dbus.String(pariredDeviceAddress)) # No Longer need agent, call exit thread: x = threading.Thread(target=ExitLoopThread) x.start() return else: msg = "Pairing failed" agent.AgentToNotifyHost(-1, msg) raise Rejected("Device Rejected") else: msg = "Pairing failed" agent.AgentToNotifyHost(-1, msg) raise Rejected("Device Rejected")
def new_parser(path): """Return a new instance of the Parser class.""" new_names = Names() new_scan = Scanner(path, new_names) new_devices = Devices(new_names) new_network = Network(new_names, new_devices) new_monitors = Monitors(new_names, new_devices, new_network) return Parser(new_names, new_devices, new_network, new_monitors, new_scan)
def main(): json_data = open('config.json') config = json.load(json_data) print "Sensors" sensors = Sensors(config) readout = sensors.readall() for read in readout: print read print " Temp: " + str(readout[read]['temp']) print " Humidity: " + str(readout[read]['humidity']) print "Devices" devices = Devices(config) readout = devices.readall() for read in readout: print read['name']
def startup_parser(data): new_names = Names() new_scan = Scanner(data, new_names, True) new_devices = Devices(new_names) new_network= Network(new_names, new_devices) new_monitors = Monitors(new_names, new_devices, new_network) parse = Parser(new_names, new_devices, new_network, new_monitors, new_scan) return parse
def move(message): commands = [ [Motors.backward_left, Motors.static_left, Motors.forward_left], [Motors.backward, Motors.stop, Motors.forward], [Motors.backward_right, Motors.static_right, Motors.forward_right] ] x, y = map(lambda k: int(message['data'][k]), ['x', 'y']) commands[x + 1][y + 1](Devices.get_device_instance(Motors))
def main(): display = Screen('marvinconfig.txt', parser) menu = Pages('marvinconfig.txt', parser) artifacts = Items('marvinconfig.txt', parser) players = Users('marvinconfig.txt', parser) universe = Devices('marvinconfig.txt', parser) while True: '''TODO:
def create_parser(path): """Create a new parser for every test""" names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) return parser
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ usage_message = ("Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface: logsim.py <file path>") try: options, arguments = getopt.getopt(arg_list, "hc:") except getopt.GetoptError: print("Error: invalid command line arguments\n") print(usage_message) sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() if not options: # no option given, use the graphical user interface if len(arguments) != 1: # wrong number of arguments print("Error: one file path required\n") print(usage_message) sys.exit() [path] = arguments scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the gui.Gui() class app = wx.App() builtins._ = wx.GetTranslation locale = wx.Locale() locale.Init(wx.LANGUAGE_DEFAULT) locale.AddCatalogLookupPathPrefix('./locale') locale.AddCatalog('zh_CN') gui = Gui("Logic Simulator", path, names, devices, network, monitors) gui.Show(True) app.MainLoop()
def new_parser(): """Return a new parser instance.""" file_name = 'file.txt' new_names = Names() new_devices = Devices(new_names) new_network = Network(new_names, new_devices) new_monitors = Monitors(new_names, new_devices, new_network) new_scanner = Scanner(file_name, new_names) return Parser(new_names, new_devices, new_network, new_monitors, new_scanner)
def create_parser(input_file): """Return a new parser instance.""" path = "./test_specfiles/test_parse/" + input_file # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) scanner = Scanner(path, names) return Parser(names, devices, network, monitors, scanner)
def new_parser(): # Build a fixture and all the following tests uses it path = 'test_def.txt' names = Names() scanner = Scanner(path, names) devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) new_parser = Parser(names, devices, network, monitors, scanner) return new_parser
def parser_device(): """Return a new instance of the Parse class.""" names = Names() scanner = Scanner(file_device, names) devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) new_parser = Parser(names, devices, network, monitors, scanner) return new_parser
def devices_with_items(): """Return a Devices class instance with three devices in the network.""" new_names = Names() new_devices = Devices(new_names) [AND1_ID, NOR1_ID, SW1_ID] = new_names.lookup(["And1", "Nor1", "Sw1"]) new_devices.make_device(AND1_ID, new_devices.AND, 2) new_devices.make_device(NOR1_ID, new_devices.NOR, 16) new_devices.make_device(SW1_ID, new_devices.SWITCH, 0) return new_devices
def new_parser_with_errors(): """Return a new instance of the Parse class.""" new_names = Names() new_scanner = Scanner(file_errors, new_names) new_devices = Devices(new_names) new_network = Network(new_names, new_devices) new_monitors = Monitors(new_names, new_devices, new_network) new_parser = Parser(new_names, new_devices, new_network, new_monitors, new_scanner) return new_parser
def get4extra(sequence, user_id): """ :param sequence: 设备UUID, 获取连续红包时必须连接设备 :param user_id: 用户ID :return: 红包金额,说明信息,是否成功 在本月内, 根据剩余金额和红包限额获取红包, 并创建新的红包(请求状态) """ # configurations = RedEnvelopeConfiguration.get_configuration() RedEnvelopeConfiguration.set_red_envelope_configuration() extra_threshold = RedEnvelopeConfiguration.RED_ENVELOPE_EXTRA_THRESHOLD result = {} device = Devices.get(sequence) rd_type = RedEnvelopes.RED_ENVELOPE_TYPE_EXTRA rd_state = RedEnvelopes.RED_ENVELOPE_STATE_REQUEST can = RedEnvelopes.can_get_extra(user_id) if not device or not can: result["bonus"] = 0 result["info"] = "no device or no extra red envelope" result["success"] = True return result try: time_limit = Datetimes.get_month_range() start = time_limit["start"] end = time_limit["end"] given_bonus = RedEnvelopes.get_valid_and_request_bonus(start, end, RedEnvelopes.RED_ENVELOPE_TYPE_EXTRA) rest = extra_threshold - given_bonus factor = RedEnvelopeConfiguration.RED_ENVELOPE_FACTOR min_money = RedEnvelopeConfiguration.RED_ENVELOPE_EXTRA_MIN max_money = RedEnvelopeConfiguration.RED_ENVELOPE_EXTRA_MAX min_value = min_money * factor max_value = max_money * factor possibility = RedEnvelopeConfiguration.RED_ENVELOPE_EXTRA_POSSIBILITY bonus = RedEnvelopes.compute_red_envelope( rest, min_money, min_value, max_value, possibility, factor ) if bonus == 0: result["bonus"] = bonus result["info"] = "no bonus it is possible" result["success"] = True else: RedEnvelopes.generate(bonus, user_id, device.id, rd_type, rd_state) result["bonus"] = bonus result["info"] = "OK" result["success"] = True except Exception as e: result["bonus"] = 0 result["info"] = e.message result["success"] = False return result
def __init__(self): super().__init__() self.setupUi(self) self.enableItems(False) self.data = settings.value('data') # print(self.data) self.__fworker = FWorker() self.__devices = Devices() self.__USBDevices = self.__devices.findUSBDevices() if len(self.__USBDevices) != 0: self.enableItems(True) for item in self.__USBDevices: self.comboBox.addItems([item['Path'] + ':/']) # Load settings self.loadSettings() self.pushButton_saveSettings.clicked.connect(self.saveSettings) self.pushButton_sync.clicked.connect( lambda: self.__fworker.syncDevices(self.__USBDevices[ self.comboBox.currentIndex()])) # 1 - PC, 2 - Device self.pushButton_selectPcPath.clicked.connect( lambda: self.selectPath(1)) self.pushButton_selectDevicePath.clicked.connect( lambda: self.selectPath(2)) self.pushButton_clearPcFolder.clicked.connect( lambda: self.clearPath(1)) self.pushButton_clearDeviceFolder.clicked.connect( lambda: self.clearPath(2)) # When user changes disk self.comboBox.currentIndexChanged.connect(self.loadSettings)
def __init__(self, instruction, fullscreen=False): chromedriver = os.path.dirname( os.path.realpath(__file__)) + '/chromedriver' sc_width, sc_height = Devices().get(instruction.device) options = Options() options.add_argument(f'window-size={sc_width}x{sc_height}') options.headless = instruction.headless options.add_argument('disable_infobars') self.sc_width = sc_width self.sc_height = sc_height self.driver = webdriver.Chrome(chromedriver, options=options)
def main(): # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) [s1, s2] = devices.names.lookup(["S1", "S2"]) devices.make_switch(s1, 0) devices.make_switch(s2, 0) devices.make_gate(1, devices.names.query("NAND"), 2) devices.make_gate(2, devices.names.query("NAND"), 2) network.make_connection(s1, None, 1, devices.names.query("I1")) network.make_connection(s2, None, 2, devices.names.query("I2")) network.make_connection(1, None, 2, devices.names.query("I1")) network.make_connection(2, None, 1, devices.names.query("I2")) print(network.check_network()) print(monitors.make_monitor(1, None)) monitors.display_signals() userint = UserInterface(names, devices, network, monitors) userint.command_interface()
def test_4(): """Create network that matches test definition file 4, a ripple counter""" names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) SW, CK, D1, D2, D3, D4 = names.lookup(["SW", "CK", "D1", "D2", "D3", "D4"]) devices.make_device(SW, devices.SWITCH, 0) devices.make_device(CK, devices.CLOCK, 1) devices.make_device(D1, devices.D_TYPE) devices.make_device(D2, devices.D_TYPE) devices.make_device(D3, devices.D_TYPE) devices.make_device(D4, devices.D_TYPE) network.make_connection(SW, None, D1, names.query("SET")) network.make_connection(SW, None, D1, names.query("CLEAR")) network.make_connection(SW, None, D2, names.query("SET")) network.make_connection(SW, None, D2, names.query("CLEAR")) network.make_connection(SW, None, D3, names.query("SET")) network.make_connection(SW, None, D3, names.query("CLEAR")) network.make_connection(SW, None, D4, names.query("SET")) network.make_connection(SW, None, D4, names.query("CLEAR")) network.make_connection(CK, None, D1, names.query("CLK")) network.make_connection(D1, names.query("QBAR"), D2, names.query("CLK")) network.make_connection(D2, names.query("QBAR"), D3, names.query("CLK")) network.make_connection(D3, names.query("QBAR"), D4, names.query("CLK")) network.make_connection(D1, names.query("QBAR"), D1, names.query("DATA")) network.make_connection(D2, names.query("QBAR"), D2, names.query("DATA")) network.make_connection(D3, names.query("QBAR"), D3, names.query("DATA")) network.make_connection(D4, names.query("QBAR"), D4, names.query("DATA")) monitors.make_monitor(CK, None) monitors.make_monitor(D1, names.query("Q")) monitors.make_monitor(D2, names.query("Q")) monitors.make_monitor(D3, names.query("Q")) monitors.make_monitor(D4, names.query("Q")) return names, devices, network, monitors
def deviceline_parser(): """Return a new instance of the Parser module, using a test description file.""" new_names = Names() new_scanner = Scanner("test_def_files/for_check_deviceline.txt", new_names) new_devices = Devices(new_names) new_network = Network(new_names, new_devices) new_monitors = Monitors(new_names, new_devices, new_network) return Parser( new_names, new_devices, new_network, new_monitors, new_scanner)
def parser_connect(): """Return a new instance of the Parse class.""" names = Names() scanner = Scanner(file_connect, names) devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) new_parser = Parser(names, devices, network, monitors, scanner) [clk, dt] = new_parser.names.lookup(["CLK", "D1"]) new_parser.devices.make_device(clk, devices.CLOCK, 10) new_parser.devices.make_device(dt, devices.D_TYPE) return new_parser
def on_menu(self, event): """Handle the event when the user selects a menu item.""" Id = event.GetId() if Id == 103: exitconf = self.exitconfirmation.ShowModal() if exitconf == wx.ID_YES: self.Close(True) if Id == 102: wx.MessageBox( _(u"Display the signal traces at different monitored outputs. \nRed trace represents '1', blue trace represents '0'.\nOutputs to be monitored can be selected by clicking 'Monitor'.\nSwitches levels can be selected by clicking 'Set Switches'" ), _(u"About Logsim"), wx.ICON_INFORMATION | wx.OK) if Id == wx.ID_OPEN: with wx.FileDialog(self) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return path = fileDialog.GetPath() self.Close(True) app = wx.App() error = ErrorFrame() names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) self.names = names self.devices = devices self.network = network self.monitors = monitors self.scanner = Scanner(path, self.names) self.parser = Parser(self.names, self.devices, self.network, self.monitors, self.scanner) global global_cycles_completed global hold global hold_monitor global_cycles_completed = 0 hold = {} hold_monitor = {} try: self.parser.parse_network() gui = Gui("LogicSim", path, self.names, self.devices, self.network, self.monitors) gui.Show(True) except: pass error.ShowModal() app.MainLoop()
def parser_io(): """Return a new instance of the Parse class.""" names = Names() scanner = Scanner(file_io, names) devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) new_parser = Parser(names, devices, network, monitors, scanner) # Initially populate new_devices with some devices [new_parser.DT] = new_parser.names.lookup(["d1"]) new_parser.devices.make_device(new_parser.DT, devices.D_TYPE) return new_parser
def make_parser(self): """Initialise a parser for the testcase.""" if self.parser is not None: return None names = Names() scanner = Scanner(self.testfile_name, names) devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) self.parser = Parser(names, devices, network, monitors, scanner, test_mode=True)
def test_parse_network_correct(): """Test the overall parse.py flow with a complicated enough but correct definition file.""" my_names = Names() my_scanner = Scanner("test_def_files/sequential.txt", my_names) my_devices = Devices(my_names) my_network = Network(my_names, my_devices) my_monitors = Monitors(my_names, my_devices, my_network) my_parser = Parser( my_names, my_devices, my_network, my_monitors, my_scanner) # Check that no semantic or syntax errors were made assert my_parser.parse_network()
def new_parser(filename): """Return a new instance of the Parser class and parse the definition file. Parameters ---------- filename: The name of the definition file in the specfiles directory """ SPECFILES_DIR = "testfiles/parser/" path = SPECFILES_DIR + filename names = Names() scanner = Scanner(path, names) devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) return Parser(names, devices, network, monitors, scanner)
def test_parse_network_incorrect_semantics12(): """Test the overall parse.py flow with a definition file with incorrect semantics. Basically, this file opens a block comment but does not close it. Ensure that parser does not get stuck in infinite loop.""" my_names = Names() my_scanner = Scanner("test_def_files/for_check_infiniteloop.txt", my_names) my_devices = Devices(my_names) my_network = Network(my_names, my_devices) my_monitors = Monitors(my_names, my_devices, my_network) my_parser = Parser( my_names, my_devices, my_network, my_monitors, my_scanner) # Check that parse_network() returns False assert not my_parser.parse_network()
def set_device_publish_state(sequence): result = dict() try: device = Devices.get(sequence) if device: device.is_published = True device.save() result["info"] = "set is_published successfully" result["success"] = True else: result["success"] = False result["info"] = "device does not exist" except Exception as ex: Logs.print_current_function_name_and_line_number(ex) result["success"] = False result["info"] = ex.message return result
def get4device(sequence, user_id): """ 新用户(第一次发布的用户)和 新设备(第一次发布的设备)获取设备红包 :param sequence: 设备UUID :param user_id: 用户ID :return: 红包数据,获取红包是否成功,说明信息 """ result = {} # configuration = RedEnvelopeConfiguration.get_configuration() RedEnvelopeConfiguration.set_red_envelope_configuration() device = Devices.get(sequence) rd_type = RedEnvelopes.RED_ENVELOPE_TYPE_DEVICE rd_state = RedEnvelopes.RED_ENVELOPE_STATE_REQUEST bonus = RedEnvelopeConfiguration.RED_ENVELOPE_BY_DEVICE if not device: result["bonus"] = 0 result["info"] = "the device does not exist" result["success"] = False return result if device: publishes_device = Publishes.get_publishes_by_device(device.id) else: publishes_device = None if user_id: publishes_user = Publishes.get_publishes_by_user(user_id) else: publishes_user = None if not publishes_device and not publishes_user: RedEnvelopes.generate(bonus, user_id, device.id, rd_type, rd_state) result["bonus"] = bonus result["info"] = "OK" result["success"] = True else: if publishes_device: result["bonus"] = 0 result["info"] = "the device has got a bonus" result["success"] = True else: result["bonus"] = 0 result["info"] = "the user has published before" result["success"] = False return result
def get4rain(sequence, user_id): """ :param sequence: 设备UUID :param user_id: 用户ID :return: 红包雨 -- 是否成功, 说明信息,红包金额 查看红包雨是否已经发放了足够数量; 查看今天是否获取了请求红包或有效红包; """ result = {} RedEnvelopeConfiguration.set_red_envelope_configuration() bonus = 0 user = Users.get_user_by_id(user_id) phone = user.username if SpecialActivity.exist_in_99(phone): today = Datetimes.get_now() today_start = Datetimes.get_day_start(today) today_end = Datetimes.get_day_end(today) today_red_envelope = RedEnvelopes.get_valid_or_request_red_envelope( today_start, today_end, RedEnvelopes.RED_ENVELOPE_TYPE_RAIN) rest = 0.27 - today_red_envelope min_money = 0.01 min_value = 1 max_value = 27 possibility = 1 factor = 100 bonus = RedEnvelopes.compute_red_envelope( rest, min_money, min_value, max_value, possibility, factor ) elif SpecialActivity.exist_in_119(phone): today = Datetimes.get_now() today_start = Datetimes.get_day_start(today) today_end = Datetimes.get_day_end(today) today_red_envelope = RedEnvelopes.get_valid_or_request_red_envelope( today_start, today_end, RedEnvelopes.RED_ENVELOPE_TYPE_RAIN) rest = 0.32 - today_red_envelope min_money = 0.01 min_value = 1 max_value = 32 possibility = 1 factor = 100 bonus = RedEnvelopes.compute_red_envelope( rest, min_money, min_value, max_value, possibility, factor ) else: count = RedEnvelopes.get_rain_count(user_id) if count >= RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_COUNT: result["success"] = False result["info"] = "the rain stopped" result["bonus"] = 0 return result if RedEnvelopes.has_got_rain(user_id): result["success"] = False result["info"] = "you have got the rain today" result["bonus"] = 0 return result device = Devices.get(sequence) if not device: result["success"] = False result["info"] = "There is no device" result["bonus"] = 0 return result rd_type = RedEnvelopes.RED_ENVELOPE_TYPE_RAIN rd_state = RedEnvelopes.RED_ENVELOPE_STATE_REQUEST start_and_end = RedEnvelopes.get_rain_start_and_end() start = start_and_end["start"] end = start_and_end["end"] given_bonus = RedEnvelopes.get_valid_and_request_bonus(start, end, rd_type) rest = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_THRESHOLD - given_bonus factor = RedEnvelopeConfiguration.RED_ENVELOPE_FACTOR min_money = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_MIN min_value = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_MIN * factor max_value = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_MAX * factor bonus = RedEnvelopes.compute_red_envelope( rest, min_money, min_value, max_value, RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_POSSIBILITY, factor ) result["bonus"] = bonus if bonus == 0: result["success"] = False result["info"] = "There is no enough money for red envelope or it is possible" else: RedEnvelopes.generate(bonus, user_id, device.id, rd_type, rd_state) result["success"] = True result["info"] = "OK" return result