tradedangerous 11.5.3__py3-none-any.whl → 12.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tradedangerous might be problematic. Click here for more details.
- tradedangerous/cache.py +567 -395
- tradedangerous/cli.py +2 -2
- tradedangerous/commands/TEMPLATE.py +25 -26
- tradedangerous/commands/__init__.py +8 -16
- tradedangerous/commands/buildcache_cmd.py +40 -10
- tradedangerous/commands/buy_cmd.py +57 -46
- tradedangerous/commands/commandenv.py +0 -2
- tradedangerous/commands/export_cmd.py +78 -50
- tradedangerous/commands/import_cmd.py +67 -31
- tradedangerous/commands/market_cmd.py +52 -19
- tradedangerous/commands/olddata_cmd.py +120 -107
- tradedangerous/commands/rares_cmd.py +122 -110
- tradedangerous/commands/run_cmd.py +118 -66
- tradedangerous/commands/sell_cmd.py +52 -45
- tradedangerous/commands/shipvendor_cmd.py +49 -234
- tradedangerous/commands/station_cmd.py +55 -485
- tradedangerous/commands/update_cmd.py +56 -420
- tradedangerous/csvexport.py +173 -162
- tradedangerous/gui.py +2 -2
- tradedangerous/plugins/eddblink_plug.py +387 -251
- tradedangerous/plugins/spansh_plug.py +2488 -821
- tradedangerous/prices.py +124 -142
- tradedangerous/templates/TradeDangerous.sql +6 -6
- tradedangerous/tradecalc.py +1227 -1109
- tradedangerous/tradedb.py +533 -384
- tradedangerous/tradeenv.py +12 -1
- tradedangerous/version.py +1 -1
- {tradedangerous-11.5.3.dist-info → tradedangerous-12.0.0.dist-info}/METADATA +6 -4
- {tradedangerous-11.5.3.dist-info → tradedangerous-12.0.0.dist-info}/RECORD +33 -38
- {tradedangerous-11.5.3.dist-info → tradedangerous-12.0.0.dist-info}/WHEEL +1 -1
- tradedangerous/commands/update_gui.py +0 -721
- tradedangerous/jsonprices.py +0 -254
- tradedangerous/plugins/edapi_plug.py +0 -1071
- tradedangerous/plugins/journal_plug.py +0 -537
- tradedangerous/plugins/netlog_plug.py +0 -316
- {tradedangerous-11.5.3.dist-info → tradedangerous-12.0.0.dist-info}/entry_points.txt +0 -0
- {tradedangerous-11.5.3.dist-info → tradedangerous-12.0.0.dist-info/licenses}/LICENSE +0 -0
- {tradedangerous-11.5.3.dist-info → tradedangerous-12.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import os
|
|
3
|
-
import re
|
|
4
|
-
import pathlib
|
|
5
|
-
import time as _time
|
|
6
|
-
from datetime import datetime, timedelta, timezone
|
|
7
|
-
|
|
8
|
-
from .. import csvexport
|
|
9
|
-
from . import PluginException, ImportPluginBase
|
|
10
|
-
|
|
11
|
-
def snapToGrid32(val):
|
|
12
|
-
try:
|
|
13
|
-
val = float(val)
|
|
14
|
-
corr = -0.5 if val < 0 else +0.5
|
|
15
|
-
pos = int(val*32+corr)/32
|
|
16
|
-
except:
|
|
17
|
-
pos = None
|
|
18
|
-
pass
|
|
19
|
-
return pos
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class ImportPlugin(ImportPluginBase):
|
|
23
|
-
"""
|
|
24
|
-
Plugin that parses the netLog file and add or update the system.
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
logGlob = "netLog.*.log"
|
|
28
|
-
ADDED_NAME = 'netLog'
|
|
29
|
-
LOGDIR_NAME = "FDEVLOGDIR"
|
|
30
|
-
DATE_FORMATS = {
|
|
31
|
-
2: ("%y", "YY", "%y"),
|
|
32
|
-
4: ("%Y", "YYYY", "%y"),
|
|
33
|
-
5: ("%y-%m", "YY-MM", "%y%m"),
|
|
34
|
-
7: ("%Y-%m", "YYYY-MM", "%y%m"),
|
|
35
|
-
8: ("%y-%m-%d", "YY-MM-DD", "%y%m%d"),
|
|
36
|
-
10: ("%Y-%m-%d", "YYYY-MM-DD", "%y%m%d"),
|
|
37
|
-
}
|
|
38
|
-
ignoreSysNames = [
|
|
39
|
-
'TRAINING',
|
|
40
|
-
'DESTINATION',
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
pluginOptions = {
|
|
44
|
-
'show': "Only show the system name and position. Don't update the DB.",
|
|
45
|
-
'last': "Only parse the last (newest) netLog file.",
|
|
46
|
-
'date': "Only parse netLog files from date, format=[YY]YY[-MM[-DD]].",
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
def __init__(self, tdb, tdenv):
|
|
50
|
-
super().__init__(tdb, tdenv)
|
|
51
|
-
|
|
52
|
-
logDirName = os.getenv(self.LOGDIR_NAME, None)
|
|
53
|
-
if not logDirName:
|
|
54
|
-
raise PluginException(
|
|
55
|
-
"Environment variable '{}' not set "
|
|
56
|
-
"(see 'README.md' for help)."
|
|
57
|
-
.format(self.LOGDIR_NAME)
|
|
58
|
-
)
|
|
59
|
-
tdenv.NOTE("{}={}", self.LOGDIR_NAME, logDirName)
|
|
60
|
-
|
|
61
|
-
self.logPath = pathlib.Path(logDirName)
|
|
62
|
-
if not self.logPath.is_dir():
|
|
63
|
-
raise PluginException(
|
|
64
|
-
"{}: is not a directory.".format(
|
|
65
|
-
str(self.logPath)
|
|
66
|
-
)
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
def parseLogDirList(self):
|
|
70
|
-
"""
|
|
71
|
-
parse netLog files
|
|
72
|
-
"""
|
|
73
|
-
# HEADER: 16-07-02-00:18 Mitteleurop�ische Sommerzeit (22:18 GMT) - part 1
|
|
74
|
-
# SYSTEM: {00:20:24} System:"Caelinus" StarPos:(0.188,-18.625,52.063)ly NormalFlight
|
|
75
|
-
# or (since 2.3)
|
|
76
|
-
# HEADER: ============================================
|
|
77
|
-
# HEADER: Logs/netLog.170430120645.01.log (part 1)
|
|
78
|
-
# HEADER: 2017-04-30 12:06 Mitteleurop�ische Sommerzeit
|
|
79
|
-
# HEADER: ============================================
|
|
80
|
-
# SYSTEM: {10:13:33GMT 407.863s} System:"Huokang" StarPos:(-12.188,35.469,-25.281)ly NormalFlight
|
|
81
|
-
tdb, tdenv = self.tdb, self.tdenv
|
|
82
|
-
optShow = self.getOption("show")
|
|
83
|
-
|
|
84
|
-
oldHeadRegEx = re.compile(r"^(?P<headDateTime>\d\d-\d\d-\d\d-\d\d:\d\d)\s+(?P<headTZName>.*[^\s])\s+(?P<headTimeGMT>\(.*GMT\))")
|
|
85
|
-
newHeadRegEx = re.compile(r"^(?P<headDateTime>\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)\s+(?P<headTZName>.*[^\s])")
|
|
86
|
-
|
|
87
|
-
sysRegEx = re.compile(r'^\{[^\}]+\}\s+System:"(?P<sysName>[^"]+)".*StarPos:\((?P<sysPos>[^)]+)\)ly')
|
|
88
|
-
dateRegEx = re.compile(r'^\{(?P<logTime>\d\d:\d\d:\d\d)')
|
|
89
|
-
|
|
90
|
-
def calcSeconds(h=0, m=0, s=0):
|
|
91
|
-
return 3600*h + 60*m + s
|
|
92
|
-
|
|
93
|
-
sysCount = 0
|
|
94
|
-
logSysList = {}
|
|
95
|
-
for filePath in self.filePathList:
|
|
96
|
-
tdenv.NOTE("parsing '{}'", filePath.name)
|
|
97
|
-
oldCount = sysCount
|
|
98
|
-
with filePath.open() as logFile:
|
|
99
|
-
headDate, headMatch = None, None
|
|
100
|
-
lineCount = 0
|
|
101
|
-
statHeader = True
|
|
102
|
-
for line in logFile:
|
|
103
|
-
lineCount += 1
|
|
104
|
-
line = line.strip('\r\n')
|
|
105
|
-
if statHeader:
|
|
106
|
-
# parse header line to get the date and timezone
|
|
107
|
-
tdenv.DEBUG0(" HEADER: {}", line.replace("{", "{{").replace("}", "}}"))
|
|
108
|
-
if lineCount == 1:
|
|
109
|
-
# old format
|
|
110
|
-
headMatch = oldHeadRegEx.match(line)
|
|
111
|
-
timeFormat = '%y-%m-%d-%H:%M'
|
|
112
|
-
if lineCount == 3:
|
|
113
|
-
# new format since 2.3
|
|
114
|
-
headMatch = newHeadRegEx.match(line)
|
|
115
|
-
timeFormat = '%Y-%m-%d %H:%M'
|
|
116
|
-
if headMatch:
|
|
117
|
-
headDate = headMatch.group('headDateTime')
|
|
118
|
-
headTZName = headMatch.group('headTZName')
|
|
119
|
-
if headTZName == _time.tzname[1]:
|
|
120
|
-
# daylight saving time
|
|
121
|
-
headTZInfo = timedelta(seconds = -_time.altzone)
|
|
122
|
-
else:
|
|
123
|
-
# normal time
|
|
124
|
-
headTZInfo = timedelta(seconds = -_time.timezone)
|
|
125
|
-
tdenv.DEBUG0(" HEADER: Date {}".format(headDate))
|
|
126
|
-
tdenv.DEBUG0(" HEADER: TZInfo {}".format(headTZInfo))
|
|
127
|
-
try:
|
|
128
|
-
# convert it into something useable
|
|
129
|
-
headDate = datetime.fromtimestamp(
|
|
130
|
-
_time.mktime(
|
|
131
|
-
_time.strptime(headDate, timeFormat)
|
|
132
|
-
),
|
|
133
|
-
timezone(headTZInfo)
|
|
134
|
-
)
|
|
135
|
-
except:
|
|
136
|
-
headDate = None
|
|
137
|
-
pass
|
|
138
|
-
if not headDate:
|
|
139
|
-
if lineCount > 3:
|
|
140
|
-
raise PluginException("Doesn't seem do be a FDEV netLog file")
|
|
141
|
-
else:
|
|
142
|
-
statHeader = False
|
|
143
|
-
if lineCount == 3:
|
|
144
|
-
# new format since 2.3, switch to UTC
|
|
145
|
-
headDate = headDate.astimezone()
|
|
146
|
-
tdenv.DEBUG0(" DATE: {}", headDate)
|
|
147
|
-
headSecs = calcSeconds(headDate.hour, headDate.minute, headDate.second)
|
|
148
|
-
lastDate = logDate = headDate
|
|
149
|
-
lastSecs = logSecs = headSecs
|
|
150
|
-
else:
|
|
151
|
-
tdenv.DEBUG1("LOGLINE: {}", line.replace("{", "{{").replace("}", "}}"))
|
|
152
|
-
# check every line for new time to enhance the lastDate
|
|
153
|
-
# use time difference because of different timezone usage
|
|
154
|
-
logTimeMatch = dateRegEx.match(line)
|
|
155
|
-
if logTimeMatch:
|
|
156
|
-
h, m, s = logTimeMatch.group('logTime').split(":")
|
|
157
|
-
logSecs = calcSeconds(int(h), int(m), int(s))
|
|
158
|
-
logDiff = logSecs - lastSecs
|
|
159
|
-
if logDiff < 0:
|
|
160
|
-
# it's a new day
|
|
161
|
-
logDiff += 86400
|
|
162
|
-
logDate = lastDate + timedelta(seconds=logDiff)
|
|
163
|
-
tdenv.DEBUG1("LOGDATE: {}", logDate)
|
|
164
|
-
|
|
165
|
-
sysMatch = sysRegEx.match(line)
|
|
166
|
-
if sysMatch:
|
|
167
|
-
# we found a system, yeah
|
|
168
|
-
sysDate = logDate
|
|
169
|
-
sysName = sysMatch.group('sysName')
|
|
170
|
-
sysPos = sysMatch.group('sysPos')
|
|
171
|
-
sysPosX, sysPosY, sysPosZ = sysPos.split(',')
|
|
172
|
-
sysPosX = snapToGrid32(sysPosX)
|
|
173
|
-
sysPosY = snapToGrid32(sysPosY)
|
|
174
|
-
sysPosZ = snapToGrid32(sysPosZ)
|
|
175
|
-
tdenv.DEBUG0(" SYSTEM: {} {} {} {} {}", sysDate, sysName, sysPosX, sysPosY, sysPosZ)
|
|
176
|
-
logSysList[sysName] = (sysPosX, sysPosY, sysPosZ, sysDate)
|
|
177
|
-
|
|
178
|
-
lastDate = logDate
|
|
179
|
-
lastSecs = logSecs
|
|
180
|
-
sysCount = len(logSysList)
|
|
181
|
-
tdenv.NOTE("Found {} System(s).", sysCount-oldCount)
|
|
182
|
-
|
|
183
|
-
if not optShow:
|
|
184
|
-
try:
|
|
185
|
-
idNetLog = tdb.lookupAdded(self.ADDED_NAME)
|
|
186
|
-
tdenv.DEBUG1("idNetLog = {}", idNetLog)
|
|
187
|
-
except KeyError:
|
|
188
|
-
tdenv.WARN("Entry '{}' not found in 'Added' table.", self.ADDED_NAME)
|
|
189
|
-
tdenv.WARN("Trying to add it myself.")
|
|
190
|
-
db = tdb.getDB()
|
|
191
|
-
cur = db.cursor()
|
|
192
|
-
cur.execute(
|
|
193
|
-
"""
|
|
194
|
-
INSERT INTO Added(name) VALUES(?)
|
|
195
|
-
""",
|
|
196
|
-
[self.ADDED_NAME]
|
|
197
|
-
)
|
|
198
|
-
db.commit()
|
|
199
|
-
tdenv.NOTE("Export Table 'Added'")
|
|
200
|
-
_, path = csvexport.exportTableToFile(tdb, tdenv, "Added")
|
|
201
|
-
pass
|
|
202
|
-
|
|
203
|
-
addCount = 0
|
|
204
|
-
oldCount = 0
|
|
205
|
-
newCount = 0
|
|
206
|
-
for sysName in logSysList:
|
|
207
|
-
sysPosX, sysPosY, sysPosZ, sysDate = logSysList[sysName]
|
|
208
|
-
utcDate = sysDate.astimezone(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
|
|
209
|
-
tdenv.DEBUG0("log system '{}' ({}, {}, {}, '{}')",
|
|
210
|
-
sysName, sysPosX, sysPosY, sysPosZ, utcDate
|
|
211
|
-
)
|
|
212
|
-
if sysName.upper() in self.ignoreSysNames:
|
|
213
|
-
tdenv.NOTE("Ignoring system: '{}'", sysName)
|
|
214
|
-
continue
|
|
215
|
-
systemTD = tdb.systemByName.get(sysName.upper(), None)
|
|
216
|
-
if systemTD:
|
|
217
|
-
# we allready know the system, check coords
|
|
218
|
-
tdenv.DEBUG0("Old system '{}' ({}, {}, {})",
|
|
219
|
-
systemTD.dbname, systemTD.posX, systemTD.posY, systemTD.posZ
|
|
220
|
-
)
|
|
221
|
-
oldCount += 1
|
|
222
|
-
if not (systemTD.posX == sysPosX and
|
|
223
|
-
systemTD.posY == sysPosY and
|
|
224
|
-
systemTD.posZ == sysPosZ):
|
|
225
|
-
tdenv.WARN("System '{}' has different coordinates:", sysName)
|
|
226
|
-
tdenv.WARN(" database: {}, {}, {}", systemTD.posX, systemTD.posY, systemTD.posZ)
|
|
227
|
-
tdenv.WARN(" netlog: {}, {}, {}", sysPosX, sysPosY, sysPosZ)
|
|
228
|
-
else:
|
|
229
|
-
# new system
|
|
230
|
-
tdenv.NOTE("New system '{}' ({}, {}, {}, '{}')",
|
|
231
|
-
sysName, sysPosX, sysPosY, sysPosZ, utcDate
|
|
232
|
-
)
|
|
233
|
-
newCount += 1
|
|
234
|
-
if not optShow:
|
|
235
|
-
tdb.addLocalSystem(
|
|
236
|
-
sysName.upper(),
|
|
237
|
-
sysPosX, sysPosY, sysPosZ,
|
|
238
|
-
added=self.ADDED_NAME,
|
|
239
|
-
modified=utcDate,
|
|
240
|
-
commit=False
|
|
241
|
-
)
|
|
242
|
-
addCount += 1
|
|
243
|
-
|
|
244
|
-
tdenv.NOTE("Found {:>3} System(s) altogether.", sysCount)
|
|
245
|
-
if oldCount:
|
|
246
|
-
tdenv.NOTE(" {:>3} old", oldCount)
|
|
247
|
-
if newCount:
|
|
248
|
-
tdenv.NOTE(" {:>3} new", newCount)
|
|
249
|
-
if addCount:
|
|
250
|
-
tdenv.NOTE(" {:>3} added", addCount)
|
|
251
|
-
tdb.getDB().commit()
|
|
252
|
-
tdenv.NOTE("Export Table 'System'")
|
|
253
|
-
_, path = csvexport.exportTableToFile(tdb, tdenv, "System")
|
|
254
|
-
|
|
255
|
-
def getLogDirList(self):
|
|
256
|
-
"""
|
|
257
|
-
get all netLog files
|
|
258
|
-
"""
|
|
259
|
-
tdenv = self.tdenv
|
|
260
|
-
logDate = self.getOption("date")
|
|
261
|
-
logLast = self.getOption("last")
|
|
262
|
-
|
|
263
|
-
self.logDate = None
|
|
264
|
-
if isinstance(logDate, str):
|
|
265
|
-
self.fmtDate = len(logDate)
|
|
266
|
-
fmt = self.DATE_FORMATS.get(self.fmtDate, (None, None, None))
|
|
267
|
-
if fmt[0]:
|
|
268
|
-
tdenv.DEBUG0("date format: {}", fmt[0])
|
|
269
|
-
try:
|
|
270
|
-
self.logDate = datetime.strptime(logDate, fmt[0])
|
|
271
|
-
except ValueError:
|
|
272
|
-
pass
|
|
273
|
-
if self.logDate:
|
|
274
|
-
globDat = self.logDate.strftime(fmt[2])
|
|
275
|
-
self.logGlob = "netLog." + globDat + "*.log"
|
|
276
|
-
else:
|
|
277
|
-
raise PluginException(
|
|
278
|
-
"Wrong date '{}' format. Must be in the form of '{}'".format(
|
|
279
|
-
logDate,
|
|
280
|
-
"','".join([d[1] for d in self.DATE_FORMATS.values()]))
|
|
281
|
-
)
|
|
282
|
-
tdenv.NOTE("using date: {}", self.logDate.strftime(fmt[0]))
|
|
283
|
-
tdenv.NOTE("using pattern: {}", self.logGlob)
|
|
284
|
-
|
|
285
|
-
self.filePathList = []
|
|
286
|
-
for filePath in sorted(self.logPath.glob(self.logGlob)):
|
|
287
|
-
tdenv.DEBUG0("logfile: {}", str(filePath))
|
|
288
|
-
self.filePathList.append(filePath)
|
|
289
|
-
|
|
290
|
-
if logLast and len(self.filePathList) > 1:
|
|
291
|
-
del self.filePathList[:-1]
|
|
292
|
-
|
|
293
|
-
listLen = len(self.filePathList)
|
|
294
|
-
if listLen == 0:
|
|
295
|
-
raise PluginException("No logfile found.")
|
|
296
|
-
elif listLen == 1:
|
|
297
|
-
tdenv.NOTE("Found one logfile.")
|
|
298
|
-
else:
|
|
299
|
-
tdenv.NOTE("Found {} logfiles.", listLen)
|
|
300
|
-
|
|
301
|
-
def run(self):
|
|
302
|
-
tdb, tdenv = self.tdb, self.tdenv
|
|
303
|
-
|
|
304
|
-
tdenv.DEBUG0("show: {}", self.getOption("show"))
|
|
305
|
-
tdenv.DEBUG0("last: {}", self.getOption("last"))
|
|
306
|
-
tdenv.DEBUG0("date: {}", self.getOption("date"))
|
|
307
|
-
|
|
308
|
-
# Ensure the cache is built and reloaded.
|
|
309
|
-
tdb.reloadCache()
|
|
310
|
-
tdb.load(maxSystemLinkLy=tdenv.maxSystemLinkLy)
|
|
311
|
-
|
|
312
|
-
self.getLogDirList()
|
|
313
|
-
self.parseLogDirList()
|
|
314
|
-
|
|
315
|
-
# We did all the work
|
|
316
|
-
return False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|