def __stop(self): if not self.start_button.IsEnabled(): self.log.debug("Stop discovery service") self._discovery_service.stop() self.log.debug("Stop Proxy server") self._proxy_server.stop() self.log.debug("Stop Websocket Proxy server") self._websocket_server.stop() self.log.debug("Stop netlog parser") self._netlog_parser.stop() self.log.debug("Stop image acquisition service") self._edpicture.stop() self.log.debug("Stopping EDSM database background updater") edsmdb.get_instance().close() self.log.debug("Stop all proxy clients and 3rd party plugins") self.client_listview.DeleteAllItems() self.plugin_listview.DeleteAllItems() for client in self._client_list: client.close() del self._client_list[:] del self._plugin_operational_list[:] self._client_list = list() self._plugin_operational_list = list() self.log.debug("All services stopped")
def __init__(self, version, line_time, system_name, num_bodies=0, system_position=None, position=(0.0, 0.0, 0.0), ship_status=NETLOG_SHIP_STATUS.UNKNOWN): edevent.BaseEvent.__init__(self, NETLOG_LINE_TYPE.SYSTEM, line_time) self._version = version self._name = system_name self._num_bodies = num_bodies self._position = position self._ship_status = ship_status # Now that FD is supplying the system coordinates # we should look at pulling systems by cube/sphere # rather than by system name. edsm_db = edsmdb.get_instance() # self._distances = edsm_db.get_distances(self._name, 120.0) self._distances = set() if system_position: self._system_coordinates = system_position else: system = edsm_db.get_system(self._name) if system: self._system_coordinates = system.position else: self._system_coordinates = None
def __on_wipe_database(self, event): msg = wx.MessageDialog(parent = self, message = "Really wipe the EDSM database? Recreating will download more than 1GB.", caption = "Warning", style = wx.CANCEL | wx.OK | wx.ICON_INFORMATION | wx.CENTRE) if msg.ShowModal() == wx.ID_OK: # You asked for it. self._edconfig.set_local_system_db(self._local_system_db.IsChecked()) self.Parent.on_stop(event) edsmdb.get_instance().erase() self.Parent.on_start(event) event.Skip()
def __on_net_recv(self, event): # self.log.debug("New net event: [%s]", str(event)) if event.get_line_type() == 'SendKeys': edsendkeys.sendkeys(event.get_keys()) elif event.get_line_type() == 'GetDistances': # self.log.debug("New distance event: [%s]", str(event)) dist_response = ednet.StarMapDistanceResponseEvent() edsm = edsmdb.get_instance() for dist in event.get_distances(): distance = edsm.get_distance(dist['sys1'], dist['sys2']) if distance and distance.distance != 0.0: dist_response.add(dist['sys1'], dist['sys2'], distance.distance) self.log.debug("Get Dist Response: [%s]" % str(dist_response)) event.get_proxy_client().send(dist_response)
def on_start(self, event): # wxGlade: EDProxyFrame.<event_handler> netlog_path = self._edconfig.get_netlog_path() journal_path = self._edconfig.get_journal_path() appconfig_path = os.path.join(self._edconfig.get_appconfig_path(), "AppConfig.xml") # appconfig_path = os.path.join(self._edconfig.get_appconfig_path(), "AppConfigLocal.xml") if not netlog_path or not os.path.exists(netlog_path): msg = wx.MessageDialog(parent = self, message = "Error: Invalid log path specified!", caption = "Error starting proxy server", style = wx.OK | wx.ICON_ERROR) msg.ShowModal() msg.Destroy() elif not appconfig_path or not os.path.exists(appconfig_path): msg = wx.MessageDialog(parent = self, message = "Error: Cannot find E:D configuration file! Please configure EDProxy.", caption = "Error starting proxy server", style = wx.OK | wx.ICON_ERROR) msg.ShowModal() msg.Destroy() else: self.start_button.Disable() if self._edconfig.get_local_system_db(): edsm_db = edsmdb.get_instance() edsm_db.connect() if edsm_db.is_install_required(): msg = wx.MessageDialog(parent = self, message = "A local copy of the EDSM starsystem database will require downloading more than 1GB of data and may not be necessary. Would you like to proceed?", caption = "EDSM Database Download", style = wx.CANCEL | wx.OK | wx.ICON_QUESTION | wx.CENTRE) if msg.ShowModal() == wx.ID_OK: self._edsm_progress_dialog = wx.ProgressDialog("Synchronizing EDSM Database", "Synchronizing EDSM Database...", parent = self, style = wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME) self._edsm_progress_dialog.SetSize((480, 103)) self._edsm_progress_dialog.Center() edsm_db.install_edsmdb(onprogress=self.__edsm_on_progress) self._edsm_progress_dialog.Destroy() wx.SafeYield() edsm_db.start_background_update(onupdate = self.__edsm_on_update) try: self._netlog_parser.set_netlog_prefix(edutils.get_logfile_prefix(appconfig_path)) self._journal_parser.set_journal_prefix('Journal') if os.path.exists(self._edconfig.get_image_path()): self._edpicture.set_image_path(self._edconfig.get_image_path()) self._edpicture.set_convert_format(self._edconfig.get_image_format()) self._edpicture.set_delete_after_convert(self._edconfig.get_image_delete_after_convert()) self._edpicture.set_convert_space(self._edconfig.get_image_convert_space()) self._edpicture.set_name_replacement(self._edconfig.get_image_name_replacement()) self._edpicture.start() self._netlog_parser.start(netlog_path) self._journal_parser.start(journal_path) self.log.debug("Starting up plugins.") for value in self._plugin_list: self.log.debug("Plugin %s:%s", value.get_name(), str(value.is_operational())) if value.is_operational(): _thread = threading.Thread(target = self.__plugin_thread, args = (value,)) _thread.daemon = True _thread.start() self.log.debug("Done plugins") self._proxy_server.start() self._websocket_server.start() self._discovery_service.start() # Announce to the world that EDProxy is up and running. self._discovery_service.send(ednet.EDDiscoveryMessageAnnounce('edproxy', edutils.get_ipaddr(), 45550)) # self._import_menu.Enable(True) self.stop_button.Enable() except Exception as ex: self.log.error("There was an error starting the proxy.", exc_info = sys.exc_info()) self.stop_button.Disable() self._discovery_service.stop() self._proxy_server.stop() self._websocket_server.stop() self._edpicture.stop() self._netlog_parser.stop() self.start_button.Enable() edsm_db.close() msg = wx.MessageDialog(parent = self, message = "Error starting up proxy server: " + ex.message, caption = "Error starting proxy server", style = wx.OK | wx.ICON_ERROR) msg.ShowModal() msg.Destroy() event.Skip()
def __on_exit_menu(self, event): self.__stop() edsmdb.get_instance().close() self.Destroy()
monitor = EDNetlogMonitor() monitor.start("/Users/wes/src/pydev/edproxy/test") try: while True: time.sleep(1) except: monitor.stop() if __name__ == "__main__": user_dir = os.path.join(edutils.get_user_dir(), ".edproxy") if not os.path.exists(user_dir): os.makedirs(user_dir) user_dir = os.path.join(user_dir, "edproxy.log") logging.basicConfig( format= "%(asctime)s-%(levelname)s-%(filename)s-%(lineno)d %(message)s", filename=user_dir) root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) edsmdb.get_instance().connect() # _test_past_logs() _test_parse_logs() # while True: # print os.stat("D:\\Dropbox\\Weston Desktop\\Documents\\Elite Dangerous\\Logs\\netLog.160605111209.01.log") # time.sleep(1)
print "what shutdown!?" self.handle.close() except Exception, e: print e print "Exception in server layer." try: sock.shutdown(socket.SHUT_RDWR) sock.close() except: pass try: edsm_db = edsmdb.get_instance() sol = edsm_db.get_system('Sol') sol_distances = edsm_db.get_distances('Sol') json_dict = dict() json_dict['Type'] = 'System' json_dict['System'] = 'Sol' json_dict['Bodies'] = 0 json_dict['Position'] = (0, 0, 0) json_dict['Status'] = 'Supercruise' json_dict['SystemCoord'] = sol.position dict_list = list() for distance in sol_distances: item = dict()