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 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)
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 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 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 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), })
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()
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.')
# 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