예제 #1
0
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()
예제 #2
0
def test_1():
    """Create network that matches test definition file 1"""
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)

    [SW1, SW2, SW3, SW4, D1, CK1, XOR1] = \
        names.lookup(["SW1", "SW2", "SW3", "SW4", "D1", "CK1", "XOR1"])
    print(names.query("SW1"))
    devices.make_device(SW1, devices.SWITCH, 1)
    devices.make_device(SW2, devices.SWITCH, 1)
    devices.make_device(SW3, devices.SWITCH, 1)
    devices.make_device(SW4, devices.SWITCH, 0)
    devices.make_device(D1, devices.D_TYPE)
    devices.make_device(CK1, devices.CLOCK, 2)
    devices.make_device(XOR1, devices.XOR)

    network.make_connection(SW1, None, XOR1, names.query("I1"))
    network.make_connection(SW2, None, XOR1, names.query("I2"))
    network.make_connection(XOR1, None, D1, names.query("DATA"))
    network.make_connection(CK1, None, D1, names.query("CLK"))
    network.make_connection(SW3, None, D1, names.query("SET"))
    network.make_connection(SW4, None, D1, names.query("CLEAR"))

    monitors.make_monitor(D1, names.query("Q"))
    monitors.make_monitor(D1, names.query("QBAR"))

    return names, devices, network, monitors
예제 #3
0
def test_2():
    """Create network that matches test definition file 2"""
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)

    CK1, CK2, AND1, NAND1, OR1, NOR1 = names.lookup(
        ["CK1", "CK2", "AND1", "NAND1", "OR1", "NOR1"])
    devices.make_device(CK1, devices.CLOCK, 2)
    devices.make_device(CK2, devices.CLOCK, 1)
    devices.make_device(AND1, devices.AND, 2)
    devices.make_device(NAND1, devices.NAND, 2)
    devices.make_device(OR1, devices.OR, 2)
    devices.make_device(NOR1, devices.NOR, 2)

    network.make_connection(CK1, None, AND1, names.query("I1"))
    network.make_connection(CK2, None, AND1, names.query("I2"))
    network.make_connection(CK2, None, NAND1, names.query("I2"))
    network.make_connection(CK2, None, OR1, names.query("I2"))
    network.make_connection(CK2, None, NOR1, names.query("I2"))
    network.make_connection(AND1, None, NAND1, names.query("I1"))
    network.make_connection(NAND1, None, OR1, names.query("I1"))
    network.make_connection(OR1, None, NOR1, names.query("I1"))

    monitors.make_monitor(NOR1, None)
    return names, devices, network, monitors
예제 #4
0
파일: engine.py 프로젝트: alan412/CheckMeIn
    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])
예제 #5
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)
예제 #6
0
   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")
예제 #7
0
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)
예제 #8
0
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
예제 #9
0
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
예제 #10
0
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()
예제 #11
0
    def GetPairedDevices(a):
        """returns all devices paired to the local interface"""
        devices = Devices()
        a = devices.returnPairedDevices()

        #     for pDevice in a:
        #        print pDevice

        return a
예제 #12
0
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:
예제 #13
0
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) 
예제 #14
0
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)
예제 #15
0
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
예제 #16
0
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
예제 #17
0
 def separar_en_metodos(self):
     #Filtrar dispositivos basado en especificos sensores
     for (groupName, groupId) in self.groupsTemp.items():
         print(groupName)
         for (sensorKey, sensorValue) in Globals.sensors.items():
             print("\t" + sensorKey)
             if (sensorKey == "Storage"):
                 pass
             self.group = Devices(groupId)
             self.group.addDevices()
             self.group.agregarSensores()
             self.devicesOverThreshold = Devices(self.group.id)
             self.devicesNotContains = Devices(self.group.id)
             self.devicesFiltered = Devices(self.group.id)
             self.devicesWithoutSensors = Devices(self.group.id)
             self.filterDevicesBySensor(sensorValue)
             self.devicesFiltered.getGroupAverages(sensorValue, sensorKey)
             #Dispositivos con sensores no permitidos
             self.agrupa_no_permitidos()
             self.printResults("json", sensorKey, groupName)
예제 #18
0
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
예제 #19
0
    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
예제 #20
0
    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)
예제 #21
0
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
예제 #22
0
def network_with_devices():
    """Return a Network class instance with three devices in the network."""
    new_names = Names()
    new_devices = Devices(new_names)
    new_network = Network(new_names, new_devices)

    [SW1_ID, SW2_ID, OR1_ID] = new_names.lookup(["Sw1", "Sw2", "Or1"])

    # Add devices
    new_devices.make_device(SW1_ID, new_devices.SWITCH, 0)
    new_devices.make_device(SW2_ID, new_devices.SWITCH, 0)
    new_devices.make_device(OR1_ID, new_devices.OR, 2)

    return new_network
예제 #23
0
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)
예제 #24
0
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
예제 #25
0
파일: gui.py 프로젝트: suton5/logicsim
    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()
예제 #26
0
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
예제 #27
0
 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)
예제 #28
0
    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, "")
예제 #29
0
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()
예제 #30
0
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)