Get ESI fitting import working completely. Use a file cache for EsiApp to prevent long startup times (possibly cache for about a week or so, and start in background if it needs to be gotten again?)
This commit is contained in:
@@ -50,15 +50,6 @@ from utils.timer import Timer
|
||||
|
||||
|
||||
|
||||
class EsiInitThread(threading.Thread):
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
self.name = "EsiInitThread"
|
||||
|
||||
def run(self):
|
||||
Crest.initEsiApp()
|
||||
|
||||
|
||||
class Crest(object):
|
||||
clientIDs = {
|
||||
Servers.TQ : 'f9be379951c046339dc13a00e6be7704',
|
||||
@@ -73,15 +64,14 @@ class Crest(object):
|
||||
|
||||
@classmethod
|
||||
def initEsiApp(cls):
|
||||
with Timer() as t:
|
||||
cls.esiapp = EsiApp(cache=None)
|
||||
|
||||
with Timer() as t:
|
||||
with Timer("Main EsiApp") as t:
|
||||
cls.esiapp = EsiApp(cache=file_cache)
|
||||
with Timer('ESI v1') as t:
|
||||
cls.esi_v1 = cls.esiapp.get_v1_swagger
|
||||
with Timer() as t:
|
||||
with Timer('ESI v4') as t:
|
||||
cls.esi_v4 = cls.esiapp.get_v4_swagger
|
||||
|
||||
esiRdy.set()
|
||||
# esiRdy.set()
|
||||
|
||||
@classmethod
|
||||
def genEsiClient(cls, security=None):
|
||||
@@ -118,10 +108,12 @@ class Crest(object):
|
||||
mode. The mode is sent as an argument, as well as the umber of
|
||||
characters still in the cache (if USER mode)
|
||||
"""
|
||||
Crest.initEsiApp()
|
||||
|
||||
prefetch = EsiInitThread()
|
||||
prefetch.daemon = True
|
||||
prefetch.start()
|
||||
|
||||
# prefetch = EsiInitThread()
|
||||
# prefetch.daemon = True
|
||||
# prefetch.start()
|
||||
|
||||
self.settings = CRESTSettings.getInstance()
|
||||
self.scopes = ['characterFittingsRead', 'characterFittingsWrite']
|
||||
@@ -188,7 +180,7 @@ class Crest(object):
|
||||
character_id=charID
|
||||
)
|
||||
resp = char.esi_client.request(op)
|
||||
return resp
|
||||
return resp.data
|
||||
|
||||
def postFitting(self, charID, json):
|
||||
# @todo: new fitting ID can be recovered from Location header,
|
||||
|
||||
@@ -491,7 +491,7 @@ class Port(object):
|
||||
|
||||
# If JSON-style start, parse as CREST/JSON
|
||||
if firstLine[0] == '{':
|
||||
return "JSON", (cls.importCrest(string),)
|
||||
return "JSON", (cls.importESI(string),)
|
||||
|
||||
# If we've got source file name which is used to describe ship name
|
||||
# and first line contains something like [setup name], detect as eft config file
|
||||
@@ -509,7 +509,7 @@ class Port(object):
|
||||
return "DNA", (cls.importDna(string),)
|
||||
|
||||
@staticmethod
|
||||
def importCrest(str_):
|
||||
def importESI(str_):
|
||||
|
||||
sMkt = Market.getInstance()
|
||||
fitobj = Fit()
|
||||
@@ -521,11 +521,11 @@ class Port(object):
|
||||
fitobj.notes = refobj['description']
|
||||
|
||||
try:
|
||||
refobj = refobj['ship']['id']
|
||||
ship = refobj['ship_type_id']
|
||||
try:
|
||||
fitobj.ship = Ship(sMkt.getItem(refobj))
|
||||
fitobj.ship = Ship(sMkt.getItem(ship))
|
||||
except ValueError:
|
||||
fitobj.ship = Citadel(sMkt.getItem(refobj))
|
||||
fitobj.ship = Citadel(sMkt.getItem(ship))
|
||||
except:
|
||||
pyfalog.warning("Caught exception in importCrest")
|
||||
return None
|
||||
@@ -535,7 +535,7 @@ class Port(object):
|
||||
moduleList = []
|
||||
for module in items:
|
||||
try:
|
||||
item = sMkt.getItem(module['type']['id'], eager="group.category")
|
||||
item = sMkt.getItem(module['type_id'], eager="group.category")
|
||||
if module['flag'] == INV_FLAG_DRONEBAY:
|
||||
d = Drone(item)
|
||||
d.amount = module['quantity']
|
||||
|
||||
Reference in New Issue
Block a user