forked from jimkeir/EDProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedproxy.py
More file actions
executable file
·674 lines (527 loc) · 27.7 KB
/
edproxy.py
File metadata and controls
executable file
·674 lines (527 loc) · 27.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.6.8 on Wed Jun 10 12:56:29 2015
#
import wx
# begin wxGlade: dependencies
import gettext
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
import os, sys
import threading
import logging.handlers
import edutils
import ednet
import edparser
import edconfig
import edsettings
import edpicture
import netlogline
import edimport
import edupdate
import webbrowser
from edicon import edicon
from edsm import EDSM
from __builtin__ import range
import edsendkeys
import edsmdb
from edconfig import EDConfig
# import datetime
class EDProxyFrame(wx.Frame):
def __init__(self, *args, **kwds):
self.log = logging.getLogger("com.fussyware.edproxy");
self.log.setLevel(logging.DEBUG)
# begin wxGlade: EDProxyFrame.__init__
kwds["style"] = wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.CLIP_CHILDREN
wx.Frame.__init__(self, *args, **kwds)
menu_bar = wx.MenuBar()
settings_menu = wx.Menu()
self._import_menu = settings_menu.Append(wx.ID_ANY, "&Import\tCTRL+I")
pref_menu = settings_menu.Append(wx.ID_PREFERENCES, "&Preferences\tCTRL+,", "Configure Edproxy Settings.")
about_menu = settings_menu.Append(wx.ID_ABOUT, "&About", "About Edproxy")
exit_menu = settings_menu.Append(wx.ID_EXIT, "&Exit", "Exit Edproxy.")
menu_bar.Append(settings_menu, "&File")
self.SetMenuBar(menu_bar)
self._import_menu.Enable(False)
self.start_button = wx.Button(self, wx.ID_ANY, _("Start"))
self.stop_button = wx.Button(self, wx.ID_ANY, _("Stop"))
self.client_listview = wx.ListView(self, style = wx.LC_REPORT | wx.BORDER_SUNKEN)
self.plugin_listview = wx.ListView(self, style = wx.LC_REPORT | wx.BORDER_SUNKEN)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_MENU, self.__on_import_menu, self._import_menu)
self.Bind(wx.EVT_MENU, self.__on_pref_menu, pref_menu)
self.Bind(wx.EVT_MENU, self.__on_exit_menu, exit_menu)
self.Bind(wx.EVT_MENU, self.__on_about_menu, about_menu)
self.Bind(wx.EVT_BUTTON, self.on_start, self.start_button)
self.Bind(wx.EVT_BUTTON, self.on_stop, self.stop_button)
# end wxGlade
self.Bind(wx.EVT_CLOSE, self.on_win_close)
self._edconfig = edconfig.get_instance()
wx.CallLater(10, self.__finish_init_thread)
# if self._edconfig.get_start_minimized():
# print "hide"
def __set_properties(self):
# begin wxGlade: EDProxyFrame.__set_properties
self.SetTitle(_("Elite: Dangerous Proxy - v" + EDConfig.get_version()))
self.SetIcon(edicon.GetIcon())
# self.SetIcon(wx.Icon('edicon.ico', wx.BITMAP_TYPE_ICO))
self.SetMinClientSize(wx.Size(400, -1))
self.SetMinSize(wx.Size(400, -1))
self.stop_button.Enable(False)
self.client_listview.InsertColumn(0, "Connected IP Address", width = wx.LIST_AUTOSIZE_USEHEADER)
self.client_listview.InsertColumn(1, "Port", width = wx.LIST_AUTOSIZE)
self.plugin_listview.InsertColumn(0, "Third-Party Plugin")
self.plugin_listview.InsertColumn(1, "Status")
self.plugin_listview.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
self.plugin_listview.SetColumnWidth(1, 200)
# end wxGlade
self._lock = threading.Lock()
self._ui_conditional = threading.Condition(self._lock)
self._client_list = list()
self._netlog_parser = edparser.EDNetlogMonitor()
self._netlog_parser.add_listener(self.__on_async_parser_event)
self._journal_parser = edparser.EDJournalMonitor()
self._journal_parser.add_listener(self.__on_async_parser_event)
self._edpicture = edpicture.EDPictureMonitor()
self._edpicture.add_listener(self.__on_new_image)
self._discovery_service = ednet.EDDiscoveryService("239.45.99.98", 45551)
self._discovery_service.add_listener(self.__on_new_message)
self._proxy_server = ednet.EDProxyServer(45550)
self._proxy_server.add_listener(self.__on_new_client)
self._websocket_server = ednet.EDProxyWebServer(8097)
self._websocket_server.add_listener(self.__on_new_client)
self._plugin_operational_list = list()
self._plugin_list = list()
self._plugin_list.append(EDSM())
def __do_layout(self):
# begin wxGlade: EDProxyFrame.__do_layout
sizer_3 = wx.BoxSizer(wx.VERTICAL)
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
sizer_5.Add(self.start_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
sizer_5.Add(self.stop_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
sizer_3.Add(self.client_listview, 0, wx.ALL | wx.EXPAND, 0)
sizer_3.AddSpacer(1)
sizer_3.Add(self.plugin_listview, 0, wx.ALL | wx.EXPAND, 0)
sizer_3.AddSpacer(5)
sizer_3.Add(sizer_5, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 2)
sizer_3.AddSpacer(2)
self.SetSizer(sizer_3)
# sizer_3.Fit(self)
self.Layout()
self.SetSize(self.GetEffectiveMinSize())
self.Centre()
# end wxGlade
def __ui_thread_caller(self, func, *args, **kwargs):
func(*args, **kwargs)
with self._lock:
self._ui_conditional.notify()
def __run_on_ui_thread(self, func, *args, **kwargs):
wx.CallAfter(self.__ui_thread_caller, func, *args, **kwargs)
with self._lock:
self._ui_conditional.wait()
def __finish_init_thread(self):
if self._edconfig.was_created():
message = "Welcome to Edproxy!\n\n"
message = message + "Edproxy allows you to send notifications out to other applications.\n\n"
message = message + "From within Settings you may set your E:D log, and AppConfig.xml, paths. Defaults will be chosen for you for normal installations.\n\n"
message = message + "You may also configure how you wish Edproxy to start-up and where to look for new E:D images."
msg = wx.MessageDialog(parent = self,
message = message,
caption = "Welcome!",
style = wx.OK | wx.ICON_INFORMATION)
msg.ShowModal()
msg.Destroy()
settings = edsettings.EDSettings(self, wx.ID_ANY, "Settings Configuration")
settings.ShowModal()
settings.Destroy()
elif self._edconfig.was_upgraded():
message = "Edproxy has been successfully upgraded to version " + EDConfig.get_version() + "\n\n"
message = message + "New to this release is:\n"
message = message + "- Support for sending journal entries\n"
message = message + "- Local copy of EDSM database is optional\n"
msg = wx.MessageDialog(parent = self,
message = message,
caption = "Upgrade to Version " + EDConfig.get_version(),
style = wx.OK | wx.ICON_INFORMATION)
msg.ShowModal()
msg.Destroy()
paths_are_good = False
while not paths_are_good:
netlog_path = self._edconfig.get_netlog_path()
journal_path = self._edconfig.get_journal_path()
appconfig_path = self._edconfig.get_appconfig_path()
if not netlog_path or not appconfig_path or not os.path.exists(netlog_path) or not os.path.exists(os.path.join(appconfig_path, "AppConfig.xml")):
message = "Could not locate E:D logging directory, or configuration directory. "
message = message + "Please update the settings providing the appropriate directories.\n\n"
message = message + "Some common log directories are:\n"
for p in edutils.get_potential_log_dirs():
message = message + p + "\n"
message = message + "\nSome common AppConfig directories are:\n"
for p in edutils.get_potential_appconfig_dirs():
message = message + p + "\n"
msg = wx.MessageDialog(parent = self,
message = message,
caption = "Verbose Logging Setup Error",
style = wx.OK | wx.CANCEL | wx.ICON_EXCLAMATION)
if wx.ID_CANCEL == msg.ShowModal():
break
msg.Destroy()
settings = edsettings.EDSettings(self, wx.ID_ANY, "Settings Configuration")
settings.ShowModal()
settings.Destroy()
else:
paths_are_good = True
if self._edconfig.get_edproxy_startup():
wx.PostEvent(self.GetEventHandler(), wx.PyCommandEvent(wx.EVT_BUTTON.typeId, self.start_button.GetId()))
if sys.platform == "win32":
self._updater = edupdate.EDWin32Updater(self, EDConfig.get_version(), self._edconfig.get_update_baseURL())
elif sys.platform == "darwin":
self._updater = edupdate.EDMacOSXUpdater(self, EDConfig.get_version(), self._edconfig.get_update_baseURL())
self.Bind(edupdate.EVT_UPGRADE_EVENT, self.__on_upgrade)
def __edsm_on_progress(self, msg, fatal = False):
if not fatal:
(keep_going, skip) = self._edsm_progress_dialog.Pulse(newmsg = msg)
return keep_going
else:
msg = wx.MessageDialog(parent = self._edsm_progress_dialog,
message = msg,
caption = "Error",
style = wx.OK | wx.ICON_ERROR)
msg.ShowModal()
msg.Destroy()
return False
def __edsm_on_update(self):
try:
event = edsmdb.StarMapDbUpdatedEvent()
self.log.debug("Sending new edsm event: [%s]", event)
self._lock.acquire()
for client in self._client_list:
client.send(event)
finally:
self._lock.release()
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 __on_upgrade(self, event):
msg = wx.MessageDialog(parent = self,
message = "An update for Edproxy is available. Proceed with update?",
caption = "Edproxy Update Available",
style = wx.CANCEL | wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
if msg.ShowModal() == wx.ID_OK:
self.__stop()
# We will NEVER return from HERE!
event.get_updater().perform_update()
event.Skip()
def __on_import_menu(self, event):
dbimport = edimport.EDImportDialog(self, wx.ID_ANY, "Import Exploration Database")
if dbimport.ShowModal() == wx.ID_OK:
print "OK"
dbimport.Destroy()
def __on_pref_menu(self, event):
settings = edsettings.EDSettings(self, wx.ID_ANY, "Settings Configuration")
if settings.ShowModal() == wx.ID_OK:
if self.stop_button.IsEnabled():
self.log.info("The preferences have changed. Stop the proxy and then attempt to restart it.")
self.stop_button.Disable()
self.__stop()
self.start_button.Enable()
wx.PostEvent(self.GetEventHandler(), wx.PyCommandEvent(wx.EVT_BUTTON.typeId, self.start_button.GetId()))
settings.Destroy()
def __on_exit_menu(self, event):
self.__stop()
edsmdb.get_instance().close()
self.Destroy()
def __on_about_menu(self, event):
webbrowser.open('https://github.com/jimkeir/EDProxy', new=2)
def __new_client_thread(self, client, addr):
while not client.is_initialized() and client.is_running():
try:
client.wait_for_initialized(0.5)
except ednet.TimeoutException:
self.log.debug("Timeout waiting for initialized. Try again.")
try:
self._lock.acquire()
self.client_listview.Append([ addr[0], addr[1] ])
self._client_list.append(client)
client.set_ondisconnect_listener(self.__on_client_disconnect)
client.set_onrecv_listener(self.__on_net_recv)
finally:
self._lock.release()
if client.get_start_time() is not None:
edparser.parse_past_logs(self._edconfig.get_netlog_path(),
self._netlog_parser.get_netlog_prefix(),
self.__on_sync_parser_event,
args = (client,),
start_time = client.get_start_time())
# The initial request for for "Now". Send the entirety of the most recent journal, because it's
# an accumulative dataset.
edparser.parse_past_journals(self._edconfig.get_journal_path(),
self._journal_parser.get_journal_prefix(),
self.__on_sync_parser_event,
args = (client,),
start_time = client.get_start_time())
event = edsmdb.StarMapDbUpdatedEvent()
client.send(event)
def __on_async_parser_event(self, event):
if event.get_line_type() == netlogline.NETLOG_LINE_TYPE.SYSTEM:
self._edpicture.set_name_replacement(event.get_name())
self._edconfig.set_image_name_replacement(event.get_name())
try:
self.log.debug("Sending new event: [%s]", event)
self._lock.acquire()
for client in self._client_list:
client.send(event)
for plugin in self._plugin_operational_list:
index = self.plugin_listview.FindItem(0, plugin.get_name())
if index != -1:
self.plugin_listview.SetStringItem(index, 1, "Transmitting...")
plugin.post(event)
if index != -1:
self.plugin_listview.SetStringItem(index, 1, "Waiting for data...")
finally:
self._lock.release()
def __on_sync_parser_event(self, event, client):
if event.get_line_type() == netlogline.NETLOG_LINE_TYPE.SYSTEM:
self._edpicture.set_name_replacement(event.get_name())
self._edconfig.set_image_name_replacement(event.get_name())
client.send(event)
def __on_new_client(self, client, addr):
self.log.info("New remote client at [%s] connected", addr)
# try:
# self._lock.acquire()
# # for _client in self._client_list:
# # if _client.get_peername()[0] == client.get_peername()[0]:
# # self.log.debug("remote client in list close: [%s]", _client.get_peername())
# # _client.close()
# # self.log.debug("Done with close")
# finally:
# self.log.debug("Good to go with the new client.")
# self._lock.release()
_thread = threading.Thread(target = self.__new_client_thread, args = (client, addr))
_thread.daemon = True
_thread.start()
def __on_client_disconnect(self, client):
try:
peername = client.get_peername()
self.log.info("Disconnecting [%s]", peername)
self.log.debug("1")
self._lock.acquire()
self.log.debug("2")
self._client_list.remove(client)
self.log.debug("3")
index = self.client_listview.FindItem(0, peername[0])
self.log.debug("4")
if index != -1:
self.log.debug("5 [%d]" % index)
self.client_listview.DeleteItem(index)
wx.SafeYield()
self.log.debug("6")
finally:
self.log.debug("Disconnect done.")
self._lock.release()
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_new_message(self, message):
if message.get_type() == ednet.DISCOVERY_SERVICE_TYPE.QUERY:
self.log.debug("Received new discovery query message [%s]", message)
if not message.get_name() or message.get_name() == 'edproxy':
self._discovery_service.send(ednet.EDDiscoveryMessageAnnounce('edproxy',
edutils.get_ipaddr(),
45550))
def __on_new_image(self, event):
self.log.debug("Received new image: [%s]", event)
try:
self._lock.acquire()
for client in self._client_list:
self.log.debug("Send image to: [%s]", client.get_peername())
client.send(event)
finally:
self._lock.release()
def __plugin_sync_parser_event(self, event, plugin):
plugin.post(event)
def __plugin_thread(self, plugin):
self.log.debug("New Plugin (EDSM) has been added.")
index = self.plugin_listview.Append([ plugin.get_name(), "Transmitting..." ])
self.log.debug("Parse old logs.")
# We need to parse old logs twice because it takes so long we may have missed
# a couple of systems at the end since the user is not going to wait for it.
#
# The first time is to pick up all systems. This may take a VERY long time
# initial log upload. (30+ minutes)
# The second time is to pick up any systems that were jumped to while
# transmitting the initial set. If This is NOT an initial upload then
# this will be very close to, or exactly, a no-op due to start time.
# The third time should absolutely be a no-op, but is there to
# just make sure we got everything.
for _ in range(3):
edparser.parse_past_logs(self._edconfig.get_netlog_path(),
self._netlog_parser.get_netlog_prefix(),
self.__plugin_sync_parser_event,
args = (plugin,),
start_time = plugin.get_last_interaction_time())
self.log.debug("Done parse old logs.")
self.plugin_listview.SetStringItem(index, 1, "Waiting for data...")
try:
self._lock.acquire()
self._plugin_operational_list.append(plugin)
finally:
self._lock.release()
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_stop(self, event): # wxGlade: EDProxyFrame.<event_handler>
self._import_menu.Enable(False)
self.stop_button.Disable()
self.__stop()
self.start_button.Enable()
event.Skip()
def on_win_close(self, event):
self.__stop()
event.Skip()
# end of class EDProxyFrame
class EDProxyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
ed_frame = EDProxyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(ed_frame)
ed_frame.Show()
return 1
# end of class EDProxyApp
class LoggerWriter(object):
def __init__(self, logger, log_level = logging.INFO):
self._logger = logger
self._log_level = log_level
def write(self, buf):
if buf and buf.rstrip():
self._logger.log(self._log_level, buf.rstrip())
if __name__ == "__main__":
gettext.install("edproxy") # replace with the appropriate catalog name
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_log_handler = logging.handlers.RotatingFileHandler(user_dir, maxBytes=(2 * 1024 * 1024), backupCount=5)
root_log_handler.setFormatter(logging.Formatter("%(asctime)s-%(levelname)s-%(filename)s-%(lineno)d %(message)s"))
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(root_log_handler)
sys.stdout = LoggerWriter(root_logger, logging.INFO)
sys.stderr = LoggerWriter(root_logger, logging.ERROR)
edproxy = EDProxyApp(0)
edproxy.MainLoop()