-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathload.py
134 lines (103 loc) · 3.97 KB
/
load.py
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
from gui import *
import sys
import logging
import os
from config import config
# Plugin name
PLUGIN_NAME = 'Autopath'
DEBUG = False
ROLL_LOGS = False
# For holding module globals
globals = sys.modules[__name__]
globals.gui = None
def gui_update():
if globals.gui is not None:
globals.logger.debug("Updating GUI")
globals.gui.update()
def setup_logger():
# Logging
globals.dir_path = os.path.dirname(os.path.realpath(__file__))
globals.logger = logging.getLogger("edmc-autopath")
globals.logger.setLevel(logging.DEBUG)
globals.log_file = os.path.join(globals.dir_path, 'edmc-autopath.log')
# Roll log files
if os.path.exists(globals.log_file) and ROLL_LOGS:
i = 1
while os.path.exists(os.path.join(globals.dir_path, os.path.basename(globals.log_file) + "." + str(i) + ".log")):
i = i + 1
os.rename(globals.log_file, os.path.join(globals.dir_path, os.path.basename(globals.log_file) + "." + str(i) + ".log"))
fh = logging.FileHandler(globals.log_file, "a")
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s: %(message)s", "%d.%m.%Y %H:%M:%S")
fh.setFormatter(formatter)
globals.logger.addHandler(fh)
# Enable
globals.logger.disabled = not DEBUG
def plugin_start(plugin_dir):
"""
Load this plugin into EDMC
"""
# Logging
setup_logger()
globals.current_system = ""
globals.last_system = ""
# Checking existence of configuration values
first_run_done = config.getint("autopath_first_run_done")
if first_run_done == 0:
globals.logger.info("First run of application detected")
config.set("autopath_neutron", 1)
config.set("autopath_riches", 1)
config.set("autopath_first_run_done", 1)
print('{}: PLUGIN STARTED'.format(PLUGIN_NAME))
globals.logger.info('{}: PLUGIN STARTED'.format(PLUGIN_NAME))
def plugin_start3(plugin_dir):
# Python 3 mode
return plugin_start(plugin_dir)
def plugin_stop():
"""
EDMC is closing
"""
globals.logger.info('{}: PLUGIN DISABLED'.format(PLUGIN_NAME))
globals.logger.info('*************************************************************')
print('{}: PLUGIN DISABLED'.format(PLUGIN_NAME))
def plugin_app(parent):
"""
Creates plugin's GUI frame and returns it
:param parent: EDMC parent frame
:return: created frame
"""
globals.logger.debug("Creating GUI...")
globals.gui = MainGUI(parent, globals)
return globals.gui
def plugin_prefs(parent, cmdr, is_beta):
"""
Return a TK Frame for adding to the EDMC settings dialog.
"""
globals.logger.debug("Creating settings GUI...")
return PrefGUI.create_gui(parent, gui_update, globals)
def dashboard_entry(cmdr, is_beta, entry):
globals.logger.debug("Dashboard entry received")
pass
def cmdr_data(data, is_beta):
globals.logger.debug("CMDR DATA received")
# Update current system
if "lastSystem" in data.keys():
dct = data["lastSystem"]
if "name" in dct.keys():
new = dct["name"]
if len(globals.current_system) < 1:
globals.current_system = new
else:
globals.last_system = globals.current_system
globals.current_system = new
globals.neutron.update_clipboard(globals.current_system)
def journal_entry(cmdr, is_beta, system, station, entry, state):
globals.logger.debug("Journal entry received")
# Update current system
if entry is not None and entry["event"].lower() in ("fsdjump","startup"):
if len(globals.current_system) < 1:
globals.current_system = entry["StarSystem"]
else:
globals.last_system = globals.current_system
globals.current_system = entry["StarSystem"]
globals.neutron.update_clipboard(globals.current_system)