def handler(event, context): """ Run on AWS Lambda. """ config_file = "config.dev.json" if context.function_name == "autotune-prod-mentalmodels": config_file = "config.prod.json" autotune = Autotune(config_file, event['ID']) memory = Memory(autotune) networking = Networking(autotune) ai_features = dict(memory.ai_features().items() + networking.ai_features().items()) procfs_features = dict(memory.procfs_features().items() + networking.procfs_features().items()) sysfs_features = dict(memory.sysfs_features().items() + networking.sysfs_features().items()) autotune.write_ai_features(ai_features) autotune.write_procfs_features(procfs_features) autotune.write_sysfs_features(sysfs_features) autotune.close() return { 'Message': "OK" }
def choose_server(assets_obj: assets.Assets, ui_obj: assets.UserInterface, networking_obj: networking.Networking): """Choose server screen input handler""" for event in pygame.event.get(): if event.type == pygame.QUIT: print("exit game") pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: if ui_obj.choice > 0: ui_obj.choice -= 1 return if event.key == pygame.K_DOWN: if ui_obj.choice < len(networking_obj.ip_result['found']): ui_obj.choice += 1 return if event.key == pygame.K_RETURN: print( f"Connect to {networking_obj.ip_result['found'][ui_obj.choice]}" ) networking_obj.connect_to_sever( networking_obj.ip_result['found'][ui_obj.choice]) return if event.key == pygame.K_F5: scan_thr = threading.Thread( target=networking_obj.scan_for_server, args=[ui_obj]) scan_thr.start() return if event.key == pygame.K_ESCAPE: networking_obj.network_disconnect(assets_obj, ui_obj) return
def wait_for_client(assets_obj: assets.Assets, ui_obj: assets.UserInterface, networking_obj: networking.Networking): """waiting screen input handler""" for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: print("end hosting") networking_obj.end_hosting(assets_obj, ui_obj)
def create_main_pane(self): """ Create the main pane for the user to connect or wait for connection """ # Create a pane with the choice to connect or listen to others # provide choice to connect or wait for connection rad_connect = QRadioButton("Connect") rad_listen = QRadioButton("Wait for Connection") # initialise the connect radio button as checked rad_connect.setChecked(True) ## The connect pane # Create the ip address txt box for ip input lbl_connection_address = QLabel('IP address') inp_connection_address = QLineEdit() inp_connection_address.setText('localhost') # the button to initiate the connection btn_connect = QPushButton('Connect') btn_connect.clicked.connect(self.btn_connect_clicked) # asseble everything of connection pane into a container layout connect_pane = create_widget_container( [lbl_connection_address, inp_connection_address, btn_connect]) ## The listening pane # Show the ip address of current machine lbl_ip_address = QLabel(Networking.get_ip()) btn_listening = QPushButton("Wait for connection") btn_listening.clicked.connect(self.btn_listen_clicked) # assemble all listening widget into a container listen_pane = create_widget_container([lbl_ip_address, btn_listening]) connection_pane = create_widget_container( [rad_connect, rad_listen, connect_pane, listen_pane]) # set up a method to show or hide based on user choice def show_connect_pane(): """ show the connection pane when user click the connect to radiobutton """ listen_pane.hide() connection_pane.adjustSize() connect_pane.show() def show_listen_pane(): """ show the listening pane when user click the listen radiobutton """ connect_pane.hide() connection_pane.adjustSize() listen_pane.show() rad_connect.clicked.connect(show_connect_pane) rad_listen.clicked.connect(show_listen_pane) show_connect_pane() self.connection_pane = connection_pane self.inp_connection_address = inp_connection_address
def run_model(config_file, event_id): print "Running {}".format(event_id) autotune = Autotune(config_file) autotune.get_id(event_id) memory = Memory(autotune) networking = Networking(autotune) ai_features = dict(memory.ai_features().items() + networking.ai_features().items()) procfs_features = dict(memory.procfs_features().items() + networking.procfs_features().items()) sysfs_features = dict(memory.sysfs_features().items() + networking.sysfs_features().items()) autotune.write_ai_features(ai_features) autotune.write_procfs_features(procfs_features) autotune.write_sysfs_features(sysfs_features) autotune.close()
def btn_connect_clicked(self): """ The method would process when the user click on the connect button """ # when connect button is clicked, show the chat pane self.window.setCentralWidget(self.giver_pane) self.connection = Networking.Connection( self.inp_connection_address.text(), 5000) print("Connecting into port 5000") self.player = 1
def btn_listen_clicked(self): """ The method would process when user click the waiting for connection/listen button """ # When listen button is clicked, show the selection pane self.window.setCentralWidget(self.guesser_pane) self.listener = Networking.Listener(5000) print("Listening on port 5000") self.accepting = True self.player = 2
def setUp(self): self.networking = Networking(5, '127.0.0.1', MagicMock()) self.client = MagicMock() self.networking.client = self.client self.private_connection = MagicMock() self.private_connection.host = ('127.0.0.1', '4444') self.public_connection1 = MagicMock() self.public_connection1.host = ('public_conn1', '1') self.public_connection2 = MagicMock() self.public_connection2.host = ('public_conn2', '2') self.client.connections = { '127.0.0.1': self.private_connection, 'public_conn1': self.public_connection1, 'public_conn2': self.public_connection2, } self.chain = self.networking.chain = MagicMock()
def run_model(config_file, machine_id): print "Running {}".format(machine_id) machine = Machine(config_file) machine.get_id(machine_id) memory = Memory(machine) networking = Networking(machine) ai_features = dict(memory.ai_features().items() + networking.ai_features().items()) procfs_features = dict(memory.procfs_features().items() + networking.procfs_features().items()) sysfs_features = dict(memory.sysfs_features().items() + networking.sysfs_features().items()) machine.write_features('ai_features', ai_features) machine.write_features('procfs', procfs_features) machine.write_features('sysfs', sysfs_features) machine.write_features('quick', { 'Security': 0, 'Stats': len(procfs_features) + len(sysfs_features), })
def server_input(assets_obj: assets.Assets, ui_obj: assets.UserInterface, networking_obj: networking.Networking): """Singleplayer input handler""" for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: assets_obj.player.speed -= assets_obj.player.control_speed if event.key == pygame.K_DOWN: assets_obj.player.speed += assets_obj.player.control_speed if event.key == pygame.K_ESCAPE: print("end hosting") assets_obj.reset() networking_obj.end_hosting(assets_obj, ui_obj) if event.type == pygame.KEYUP: if event.key == pygame.K_UP: assets_obj.player.speed += assets_obj.player.control_speed if event.key == pygame.K_DOWN: assets_obj.player.speed -= assets_obj.player.control_speed
def main(): args = parse_args() config_logger(args.verbose) logging.info("arguments called with: {}".format(sys.argv)) logging.info("parsed arguments: {}".format(args)) sync = Sync() networking = Networking(args.check_blocks_in_flight_interval, args.private_ip, sync) executor = Executor(networking) strategy = Strategy(args.lead_stubborn, args.equal_fork_stubborn, args.trail_stubborn) if args.start_hash: chain = Chain(executor, strategy, core.lx(args.start_hash)) else: chain = Chain(executor, strategy) networking.chain = chain t = threading.Thread(target=cliserver.start, args=(chain, sync,)) t.daemon = True t.start() networking.start()
def client(assets_obj: assets.Assets, networking_obj: networking.Networking, ui_obj: assets.UserInterface): """Client mode input handler""" assets_obj.opponent.previous_speed = assets_obj.opponent.speed for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_w: assets_obj.opponent.speed -= assets_obj.opponent.control_speed if event.key == pygame.K_s: assets_obj.opponent.speed += assets_obj.opponent.control_speed if event.type == pygame.KEYUP: if event.key == pygame.K_w: assets_obj.opponent.speed += assets_obj.opponent.control_speed if event.key == pygame.K_s: assets_obj.opponent.speed -= assets_obj.opponent.control_speed if event.key == pygame.K_ESCAPE: networking_obj.network_disconnect(assets_obj, ui_obj) print("end tcp client") if assets_obj.opponent.speed != assets_obj.opponent.previous_speed: networking_obj.send_controls(assets_obj, ui_obj)
def test_networking(): n = Networking("127.0.0.1", 0) _thread.start_new_thread(_handle_server, (n, )) n.wait_for_connection() # Full message msg = n.recv_message() assert isinstance(msg, SessionStartMessage) # Split message msg = n.recv_message() assert isinstance(msg, SessionStartMessage)
class NetworkingTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(NetworkingTest, self).__init__(*args, **kwargs) self.networking = None self.client = None self.private_connection = None self.public_connections = None self.public_connection1 = None self.public_connection2 = None self.chain = None def setUp(self): self.networking = Networking(5, '127.0.0.1', MagicMock()) self.client = MagicMock() self.networking.client = self.client self.private_connection = MagicMock() self.private_connection.host = ('127.0.0.1', '4444') self.public_connection1 = MagicMock() self.public_connection1.host = ('public_conn1', '1') self.public_connection2 = MagicMock() self.public_connection2.host = ('public_conn2', '2') self.client.connections = { '127.0.0.1': self.private_connection, 'public_conn1': self.public_connection1, 'public_conn2': self.public_connection2, } self.chain = self.networking.chain = MagicMock() def test_check_blocks_in_flight_no_flights(self): self.networking.blocks_in_flight = {} self.networking.check_blocks_in_flight() self.assertEqual(len(self.networking.blocks_in_flight), 0) @patch('time.time', lambda: 3) def test_check_blocks_in_flight_timeout(self): hash_ = CBlock().GetHash() self.networking.check_blocks_in_flight_interval = 2 self.networking.blocks_in_flight = {hash_: BlockInFlight(hash_, 0)} self.networking.check_blocks_in_flight() self.assertEqual(len(self.networking.blocks_in_flight), 0) @patch('time.time', lambda: 1) def test_check_blocks_in_flight_does_not_timeout(self): hash_ = CBlock().GetHash() self.networking.check_blocks_in_flight_interval = 2 self.networking.blocks_in_flight = {hash_: BlockInFlight(hash_, 0)} self.networking.check_blocks_in_flight() self.assertEqual(len(self.networking.blocks_in_flight), 1) @patch('chainutil.request_get_headers') def test_inv_message_msg_block_private(self, mock): mock.return_value = ['hash20', 'hash19'] self.networking.request_blocks = MagicMock() inv = net.CInv() inv.hash = 'hash1' inv.type = networking.inv_typemap['Block'] msg = messages.msg_inv msg.inv = [inv] self.networking.inv_message(self.private_connection, msg) self.assertEqual(self.private_connection.send.call_count, 1) self.assertTrue(mock.called) self.assertEqual(self.private_connection.send.call_args_list[0][0][0], 'getheaders') @patch('chainutil.request_get_headers') def test_inv_message_msg_request_block(self, mock): mock.return_value = ['hash20', 'hash19'] self.networking.request_blocks = MagicMock() inv = net.CInv() inv.hash = 'hash1' inv.type = networking.inv_typemap['Block'] msg = messages.msg_inv msg.inv = [inv] self.networking.inv_message(self.private_connection, msg) self.assertTrue(self.networking.request_blocks.called) self.assertEqual(self.networking.request_blocks.call_args[0][0], self.private_connection) self.assertEqual(self.networking.request_blocks.call_args[0][1], ['hash1']) def test_inv_message_msg_filtered_block(self): inv = net.CInv() inv.type = networking.inv_typemap['FilteredBlock'] msg = messages.msg_inv msg.inv = [inv] self.networking.inv_message(self.private_connection, msg) self.assertFalse(self.private_connection.send.called) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.public_connection2.send.called) def test_inv_message_msg_error(self): inv = net.CInv() inv.type = networking.inv_typemap['Error'] msg = messages.msg_inv msg.inv = [inv] self.networking.inv_message(self.private_connection, msg) self.assertFalse(self.private_connection.send.called) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.public_connection2.send.called) def test_inv_message_msg_tx_known(self): inv = net.CInv() inv.type = networking.inv_typemap['TX'] inv.hash = 'hash1' msg = messages.msg_inv() msg.inv = [inv] self.networking.txs = {inv.hash: 'saved_transaction'} self.networking.inv_message(self.private_connection, msg) self.assertFalse(self.private_connection.send.called) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.public_connection2.send.called) def test_inv_message_msg_unknown(self): inv = net.CInv() inv.type = "Unknown" msg = messages.msg_inv msg.inv = [inv] self.networking.inv_message(self.private_connection, msg) self.assertFalse(self.private_connection.send.called) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.public_connection2.send.called) def test_send_inv_private_blocks(self): block1 = Block(CBlock(), BlockOrigin.private) block1.cached_hash = 'hash1' block2 = Block(CBlock(), BlockOrigin.private) block2.cached_hash = 'hash2' self.networking.send_inv([block1, block2]) self.assertTrue(self.public_connection1.send.called) self.assertTrue(self.public_connection2.send.called) self.assertEqual(len(self.public_connection2.send.call_args[0][1].inv), 2) self.assertFalse(self.private_connection.send.called) def test_send_inv_public_blocks(self): block1 = Block(CBlock(), BlockOrigin.public) block1.cached_hash = 'hash1' block2 = Block(CBlock(), BlockOrigin.public) block2.cached_hash = 'hash2' self.networking.send_inv([block1, block2]) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.public_connection2.send.called) self.assertTrue(self.private_connection.send.called) inv = self.private_connection.send.call_args[0][1].inv self.assertEqual(len(inv), 2) def test_send_inv_blocks(self): block1 = Block(CBlock(), BlockOrigin.public) block1.cached_hash = 'hash1' block2 = Block(CBlock(), BlockOrigin.public) block2.cached_hash = 'hash2' block3 = Block(CBlock(), BlockOrigin.public) block3.cached_hash = 'hash3' block4 = Block(CBlock(), BlockOrigin.private) block4.cached_hash = 'hash4' block5 = Block(CBlock(), BlockOrigin.private) block5.cached_hash = 'hash5' self.networking.send_inv([block1, block2, block3, block4, block5]) self.assertTrue(self.private_connection.send.called) inv = self.private_connection.send.call_args[0][1].inv self.assertEqual(len(inv), 3) self.assertTrue(self.public_connection1.send.called) self.assertTrue(self.public_connection2.send.called) self.assertEqual(len(self.public_connection2.send.call_args[0][1].inv), 2) def test_ignore_message(self): networking.ignore_message(self.private_connection, None) self.assertFalse(self.private_connection.send.called) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.public_connection2.send.called) def test_headers_message_known_blocks(self): cblock1 = CBlock(nNonce=1) block1 = Block(cblock1, None) cblock2 = CBlock(nNonce=2) block2 = Block(cblock2, None) self.chain.blocks = {block1.hash(): block1, block2.hash(): block2} self.networking.request_blocks = MagicMock() message = messages.msg_headers() message.headers = [cblock1.get_header(), cblock2.get_header()] self.networking.headers_message(self.public_connection1, message) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.chain.process_header.called) self.assertFalse(self.private_connection.send.called) self.assertTrue(self.networking.request_blocks.called) self.assertEqual(len(self.networking.request_blocks.call_args[0][1]), 0) def test_headers_message_two_unknown_blocks(self): header1 = CBlockHeader(nNonce=1) header2 = CBlockHeader(nNonce=2) message = messages.msg_headers() message.headers = [header1, header2] self.networking.blocks_in_flight = {} self.networking.request_blocks = MagicMock() self.networking.headers_message(self.private_connection, message) self.assertEqual(self.chain.process_header.call_count, 2) self.assertEqual(self.chain.process_header.call_args[0][1], BlockOrigin.private) self.assertTrue(self.networking.request_blocks.called) self.assertEqual(len(self.networking.request_blocks.call_args[0][1]), 2) self.assertIn(header1.GetHash(), self.networking.request_blocks.call_args[0][1]) self.assertIn(header2.GetHash(), self.networking.request_blocks.call_args[0][1]) def test_headers_message_one_block_not_in_flight(self): header1 = CBlockHeader(nNonce=1) header2 = CBlockHeader(nNonce=2) message = messages.msg_headers() message.headers = [header1, header2] self.networking.blocks_in_flight = {header1.GetHash(): 'in_flight'} self.networking.headers_message(self.private_connection, message) self.assertEqual(self.private_connection.send.call_args[0][0], 'getdata') self.assertEqual(len(self.private_connection.send.call_args[0][1].inv), 1) def test_request_blocks(self): self.networking.request_blocks(self.public_connection1, ['hash1', 'hash2']) self.assertEqual(self.public_connection1.send.call_count, 1) self.assertEqual(self.public_connection1.send.call_args[0][0], 'getdata') self.assertEqual( self.public_connection1.send.call_args[0][1].inv[0].type, networking.inv_typemap['Block']) self.assertEqual( self.public_connection1.send.call_args[0][1].inv[0].hash, 'hash1') def test_request_blocks_no_hashes(self): self.networking.request_blocks(self.public_connection1, []) self.assertFalse(self.public_connection1.send.called, 1) @patch('chainutil.respond_get_headers') def test_getheaders_message_no_blocks_to_return(self, mock): message = messages.msg_getheaders() message.locator.vHave = ['hash1'] self.chain.tips = {'some_hash': 'some_block'} mock.return_value = [] self.networking.getheaders_message(self.private_connection, message) self.assertTrue(mock.called) self.assertEqual(mock.call_args[0][0], self.chain.tips) self.assertEqual(mock.call_args[0][1], BlockOrigin.private) self.assertEqual(mock.call_args[0][2], message.locator.vHave) self.assertTrue(self.private_connection.send.called) self.assertEqual(self.private_connection.send.call_args[0][0], 'headers') self.assertEqual(self.private_connection.send.call_args[0][1].headers, []) @patch('chainutil.respond_get_headers') def test_getheaders_message_no_block_found(self, mock): message = messages.msg_getheaders() block1 = Block('cblock_header1', BlockOrigin.private) block1.cblock = CBlock(nNonce=1) block2 = Block('cblock_header2', BlockOrigin.private) block2.cblock = CBlock(nNonce=2) mock.return_value = [block1, block2] self.networking.getheaders_message(self.private_connection, message) self.assertTrue(self.private_connection.send.called) self.assertEqual( len(self.private_connection.send.call_args[0][1].headers), 2) self.assertEqual( self.private_connection.send.call_args[0][1].headers[0], block1.cblock) self.assertEqual( self.private_connection.send.call_args[0][1].headers[1], block2.cblock) def test_block_message(self): message = messages.msg_block() cblock = CBlock() message.block = cblock block = Block(None, BlockOrigin.private) block.cached_hash = message.block.GetHash() self.chain.blocks = {block.hash(): block} self.networking.block_message(self.private_connection, message) self.assertEqual(self.chain.blocks[block.hash()].cblock, cblock) def test_block_message_remove_from_blocks_in_flight(self): message = messages.msg_block() cblock = CBlock() message.block = cblock block = Block(None, BlockOrigin.private) block.cached_hash = message.block.GetHash() self.chain.blocks = {block.hash(): block} self.networking.blocks_in_flight = {block.hash(): 'in_flight'} self.networking.block_message(self.private_connection, message) self.assertEqual(len(self.networking.blocks_in_flight), 0) def test_block_message_deferred_requests(self): message = messages.msg_block() cblock = CBlock() hash_ = cblock.GetHash() message.block = cblock block = Block(None, BlockOrigin.private) block.cached_hash = hash_ self.networking.deferred_block_requests = \ {hash_: [self.private_connection.host[0], self.public_connection2.host[0]]} self.networking.send_block = MagicMock() self.networking.block_message(self.public_connection1, message) self.assertEqual(len(self.networking.deferred_block_requests), 0) self.assertEqual(self.networking.send_block.call_count, 2) self.assertEqual(self.networking.send_block.call_args[0][1], cblock) def test_block_message_two_times(self): message = messages.msg_block() cblock1 = CBlock(nNonce=1) cblock2 = CBlock(nNonce=2) message.block = cblock1 block = Block(None, BlockOrigin.private) block.cached_hash = message.block.GetHash() self.chain.blocks = {block.hash(): block} self.networking.block_message(self.private_connection, message) message.block = cblock2 self.networking.block_message(self.private_connection, message) def test_getdata_message_with_block(self): cblock = CBlock() block = Block(cblock, BlockOrigin.private) block.cblock = cblock message = messages.msg_getdata() cInv = CInv() cInv.type = networking.inv_typemap['Block'] cInv.hash = cblock.GetHash() message.inv = [cInv] self.chain.blocks = {cblock.GetHash(): block} self.networking.getdata_message(self.public_connection1, message) self.assertTrue(self.public_connection1.send.called) self.assertEqual(self.public_connection1.send.call_args[0][0], 'block') self.assertEqual(self.public_connection1.send.call_args[0][1].block, cblock) def test_getdata_message_cblock_not_available(self): cblock = CBlock() hash_ = cblock.GetHash() block = Block(cblock, BlockOrigin.private) message = messages.msg_getdata() cInv = CInv() cInv.type = networking.inv_typemap['Block'] cInv.hash = hash_ message.inv = [cInv] self.chain.blocks = {hash_: block} self.networking.deferred_block_requests = {} self.networking.getdata_message(self.public_connection1, message) self.assertFalse(self.public_connection1.called) self.assertIn(hash_, self.networking.deferred_block_requests) self.assertIn(self.public_connection1.host[0], self.networking.deferred_block_requests[hash_]) def test_getdata_message_with_unknown_hashes(self): message = messages.msg_getdata() cInv1 = CInv() cInv1.type = networking.inv_typemap['Block'] cInv1.hash = 'hash1' cInv2 = CInv() cInv2.type = networking.inv_typemap['Block'] cInv2.hash = 'hash2' message.inv = [cInv1, cInv2] self.chain.blocks = {} self.networking.getdata_message(self.public_connection1, message) self.assertFalse(self.public_connection1.send.called) def test_getdata_message_with_two_blocks(self): cblock1 = CBlock() block1 = Block(cblock1, BlockOrigin.private) block1.cblock = cblock1 cInv1 = CInv() cInv1.type = networking.inv_typemap['Block'] cInv1.hash = cblock1.GetHash() cblock2 = CBlock() block2 = Block(cblock2, BlockOrigin.private) block2.cblock = cblock2 cInv2 = CInv() cInv2.type = networking.inv_typemap['Block'] cInv2.hash = cblock2.GetHash() message = messages.msg_getdata() message.inv = [cInv1, cInv2] self.chain.blocks = { cblock1.GetHash(): block1, cblock2.GetHash(): block2 } self.networking.getdata_message(self.public_connection1, message) self.assertTrue(self.public_connection1.send.called) self.assertEqual(self.public_connection1.send.call_count, 2) def test_getdata_message_without_tx(self): message = messages.msg_getdata() inv = CInv() inv.type = networking.inv_typemap['TX'] inv.hash = 'hash1' message.inv = [inv] self.networking.get_tx = MagicMock() self.networking.get_tx.return_value = None self.networking.getdata_message(self.public_connection1, message) self.assertFalse(self.private_connection.send.called) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.public_connection2.send.called) def test_get_private_connection(self): connection = self.networking.get_private_connection() self.assertEqual(connection, self.private_connection) def test_get_private_connection_no_pirvate_connection(self): del self.client.connections['127.0.0.1'] connection = self.networking.get_private_connection() self.assertEqual(connection, None) def test_get_current_public_connection(self): connections = list(self.networking.get_current_public_connection()) self.assertEqual(len(connections), 2)
from networking import Networking from light_sensor import LightSensor from controller import Controller from protocol_machine import ProtocolMachine from scheduler import Scheduler print("Starting Controller...") controller = Controller() print("Controller started") print("Starting Lightmodule...") lightsensor = LightSensor() print("Lightmodule started") print("Creating ProtocolMachine...") protocol_machine = ProtocolMachine(controller, lightsensor) print("ProtocolMachine created") print("Starting Server...") networking = Networking(protocol_machine) print("Networking started") print("Starting Scheduler...") scheduler = Scheduler(controller, lightsensor) print("Scheduler started")
def register(): network = Networking() if network.register_by_ip(request.remote_addr): return jsonify({'success': True}) else: return jsonify({'success': False})
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.Config = {} self.pid = os.getpid() ## @var config_manager # ConfigManager (Class) self.config_manager = ConfigManager(self) self.config_manager.check_path() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.timer = None self.status = None self.statusbar = None self.user_stats = {} self.user_exists = {} self.ip_requested = [] self.username = None self.images = {} for i in "away", "online", "offline", "noexist", "logo", "close", "green", "yellow", "red", "icon", "away_trusted", "away_banned", "away_buddied", "away_ignored", "online_trusted", "online_banned", "online_ignored", "online_buddied", "offline_trusted", "offline_banned", "offline_ignored", "offline_buddied", "hilite", "empty": #loader = gtk.gdk.PixbufLoader("png") data = getattr(imagedata, i) loader = QPixmap() if loader.loadFromData(data): self.images[i] = QIcon(loader) else: print i, "failed to load" #loader.write(data, len(data)) #loader.close() #self.images[i] = loader.get_pixbuf() del loader, data #gc.collect() #self.MurmurWindow.set_icon(self.images["icon"]) #self.ui.ChatRooms = QtGui.QTabWidget(self.ui.ChatRoomsLabel) #self.ui.ChatRooms.setObjectName("ChatRooms") self.ChatRooms = ChatRooms(self) self.ui.ChatRoomsLayout.addWidget(self.ChatRooms) self.PrivateChats = PrivateChats(self) self.ui.PrivateChatsLayout.addWidget(self.PrivateChats) self.Networking = Networking(self) self.Downloads = Downloads(self) self.Uploads = Uploads(self) self.Settings = Settings(self) # Networking signals self.connect(self.Networking, SIGNAL("JoinRoom(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.JoinRoom) self.connect(self.Networking, SIGNAL("LeaveRoom(PyQt_PyObject)"), self.ChatRooms.LeaveRoom) self.connect(self.Networking, SIGNAL("UserStatus(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.GetUserStatus) self.connect( self.Networking, SIGNAL("SayChatRoom(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.SayChatRoom) #self.connect(self.Networking, SIGNAL("SayChatRoom(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"), self.PrivateChat.SayPrivate) self.connect(self.Networking, SIGNAL("Log(PyQt_PyObject)"), self.AppendToLogWindow) self.connect( self.Networking, SIGNAL("ShowMessage(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.PrivateChats.ShowMessage) self.connect(self.Networking, SIGNAL("UserJoinedRoom(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.UserJoinedRoom) self.connect(self.Networking, SIGNAL("UserLeftRoom(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.UserLeftRoom) self.connect(self.Networking, SIGNAL("ConnClose()"), self.ChatRooms.ConnClose) # Main Menu actions self.connect(self.ui.actionToggle_Away, SIGNAL("activated()"), self.away_toggle) self.connect(self.ui.actionAbout_Qt, SIGNAL("activated()"), self.OnAbout) self.connect(self.ui.actionConnect_to_daemon, SIGNAL("activated()"), self.OnConnect) self.connect(self.ui.actionDisconnect_from_daemon, SIGNAL("activated()"), self.OnDisconnect) self.connect(self.ui.actionConfigure, SIGNAL("activated()"), self.OnConfigure) self.Networking.start()
# sys.stdout = Logger() # Ten Minutes OFF_COUNTER = 60 not_home_counter = 0 home_counter = 0 startup = True update_playlist = True print "Downloading Playlists" player = Mopidy() network = Networking() # Once above is done lets make it check every like... 5 seconds? # We will need a better way to scan the network. # Something quick that looks for the mac address of the phone print '-wwwwwwwuuuuuttttt' print network.check_macs() while True: print 'Scanning...' found = False mac = network.check_macs() if mac and not startup: print 'MAC: %s' % mac
def action_prompt(master_data, input_name_or_id=None, english_name=''): """Asks the user which function they want to use.""" # Make the list of potential actions. ACT_EXIT = 'exit' ACT_HELP = 'help' ACT_INTROSPECT = 'introspect' ACT_UNIT_TEST = 'unit test' ACT_FIND_CHAR = 'find' ACT_SEE_ABILITIES = 'see abilities' ACT_GET_CHAR_TEMPLATE = 'char template' ACT_DL_CHAR_IMAGES = 'dl char images' ACT_DL_EQUIP_IMAGES = 'dl equip images' ACT_WRITE_SKILL_LIST = 'skill list' ACT_WRITE_ABILITY_LIST = 'ability list' ACT_WRITE_CHAR_NAME_LIST = 'char list' ACT_WRITE_EQUIP_LIST = 'equip list' ACT_WRITE_SKIN_LIST = 'skin list' ACT_WRITE_MASTER_CHAR_LIST = 'master char list' ACT_FRAME_ICONS = 'frame' action_list = { ACT_EXIT: 'Exit and return the parsed master data.', ACT_HELP: 'List all actions.', ACT_UNIT_TEST: 'Unit test some things.', ACT_INTROSPECT: 'Activate the interactive prompt.', ACT_FIND_CHAR: 'Find a character.', ACT_SEE_ABILITIES: 'See the list of unique abilities.', ACT_GET_CHAR_TEMPLATE: 'Output a Character template.', ACT_DL_CHAR_IMAGES: 'Download all images for a character.', ACT_DL_EQUIP_IMAGES: 'Download all equipment images.', ACT_WRITE_SKILL_LIST: 'Write the Skill list (Skill ID:Skill Info).', ACT_WRITE_ABILITY_LIST: 'Write the Ability list (Ability ID:Ability Info).', ACT_WRITE_CHAR_NAME_LIST: 'Write the Character list (FKG ID:JP Name).', ACT_WRITE_EQUIP_LIST: 'Write the Equipment list (Equip ID:Equip Info).', ACT_WRITE_MASTER_CHAR_LIST: 'Write the Master Character List (FKG ID:All Data).', ACT_WRITE_SKIN_LIST: 'Write the Skin list page (Skin ID:All Data)', ACT_FRAME_ICONS: 'Puts frames on all character icons in the "dl" folder.', } def list_actions(): for key, action in action_list.items(): print('{0}: {1}'.format(key, action)) from imaging import Imaging imaging = Imaging() from networking import Networking networking = Networking() # Begin the prompt loop for which action to take. list_actions() user_input = '' while user_input != ACT_EXIT: try: user_input = input('>>> Input the action you want to do: ') except ValueError: continue output_text = '' if user_input == ACT_INTROSPECT: introspect(master_data, imaging) elif user_input == ACT_HELP: list_actions() elif user_input == ACT_UNIT_TEST: UnitTest().run_tests() elif user_input == ACT_WRITE_CHAR_NAME_LIST: output_text = master_data.outputter.get_char_list_page() elif user_input == ACT_GET_CHAR_TEMPLATE: output_text = get_char_template(master_data) elif user_input == ACT_DL_CHAR_IMAGES: output_text = download_character_images(master_data, networking) elif user_input == ACT_DL_EQUIP_IMAGES: networking.dl_equip_pics(master_data.equipment) elif user_input == ACT_WRITE_SKILL_LIST: output_text = master_data.get_skill_list_page() elif user_input == ACT_WRITE_ABILITY_LIST: output_text = master_data.get_bundled_ability_list_page() elif user_input == ACT_WRITE_SKIN_LIST: output_text = master_data.get_skin_info_page() elif user_input == ACT_WRITE_MASTER_CHAR_LIST: output_text = master_data.get_master_char_data_page() elif user_input == ACT_WRITE_EQUIP_LIST: output_text = master_data.get_equipment_list_page() elif user_input == ACT_FIND_CHAR: char_name_or_id = input( "Input the character's Japanese name or ID: ") print('\n\n'.join([ entry.getlua() for entry in master_data.get_char_entries(char_name_or_id) ])) elif user_input == ACT_SEE_ABILITIES: # Note: You may optionally do something with the return value. # TODO: Remove this command when I feel like it is no longer needed. ability_list = master_data.find_referenced_abilities() elif user_input == ACT_FRAME_ICONS: apply_frames(master_data, imaging) if output_text: with open(DEFAULT_OUTFILENAME, 'w', encoding="utf-8") as outfile: outfile.write(output_text) print('Completed the processing.')
def register(): network = Networking() if network.register_by_ip(request.remote_addr): return jsonify({'success':True}) else: return jsonify({'success':False})
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.Config = {} self.pid = os.getpid() ## @var config_manager # ConfigManager (Class) self.config_manager = ConfigManager(self) self.config_manager.check_path() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.timer = None self.status = None self.statusbar = None self.user_stats = {} self.user_exists = {} self.ip_requested = [] self.username = None self.images = {} for i in "away", "online", "offline", "noexist", "logo", "close", "green", "yellow", "red", "icon", "away_trusted", "away_banned", "away_buddied", "away_ignored", "online_trusted", "online_banned", "online_ignored", "online_buddied", "offline_trusted", "offline_banned", "offline_ignored", "offline_buddied", "hilite", "empty": #loader = gtk.gdk.PixbufLoader("png") data = getattr(imagedata, i) loader = QPixmap() if loader.loadFromData(data): self.images[i] = QIcon(loader) else: print i, "failed to load" #loader.write(data, len(data)) #loader.close() #self.images[i] = loader.get_pixbuf() del loader, data #gc.collect() #self.MurmurWindow.set_icon(self.images["icon"]) #self.ui.ChatRooms = QtGui.QTabWidget(self.ui.ChatRoomsLabel) #self.ui.ChatRooms.setObjectName("ChatRooms") self.ChatRooms = ChatRooms(self) self.ui.ChatRoomsLayout.addWidget(self.ChatRooms) self.PrivateChats = PrivateChats(self) self.ui.PrivateChatsLayout.addWidget(self.PrivateChats) self.Networking = Networking(self) self.Downloads = Downloads(self) self.Uploads = Uploads(self) self.Settings = Settings(self) # Networking signals self.connect(self.Networking, SIGNAL("JoinRoom(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.JoinRoom) self.connect(self.Networking, SIGNAL("LeaveRoom(PyQt_PyObject)"), self.ChatRooms.LeaveRoom) self.connect(self.Networking, SIGNAL("UserStatus(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.GetUserStatus) self.connect(self.Networking, SIGNAL("SayChatRoom(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.SayChatRoom) #self.connect(self.Networking, SIGNAL("SayChatRoom(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"), self.PrivateChat.SayPrivate) self.connect(self.Networking, SIGNAL("Log(PyQt_PyObject)"), self.AppendToLogWindow) self.connect(self.Networking, SIGNAL("ShowMessage(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.PrivateChats.ShowMessage) self.connect(self.Networking, SIGNAL("UserJoinedRoom(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.UserJoinedRoom) self.connect(self.Networking, SIGNAL("UserLeftRoom(PyQt_PyObject, PyQt_PyObject)"), self.ChatRooms.UserLeftRoom) self.connect(self.Networking, SIGNAL("ConnClose()"), self.ChatRooms.ConnClose) # Main Menu actions self.connect(self.ui.actionToggle_Away, SIGNAL("activated()"), self.away_toggle) self.connect(self.ui.actionAbout_Qt, SIGNAL("activated()"), self.OnAbout) self.connect(self.ui.actionConnect_to_daemon, SIGNAL("activated()"), self.OnConnect) self.connect(self.ui.actionDisconnect_from_daemon, SIGNAL("activated()"), self.OnDisconnect) self.connect(self.ui.actionConfigure, SIGNAL("activated()"), self.OnConfigure) self.Networking.start()