Move fetch function to shared
This commit is contained in:
@@ -35,7 +35,7 @@ from eos.saveddata.fit import Fit
|
|||||||
from service.fit import Fit as svcFit
|
from service.fit import Fit as svcFit
|
||||||
from service.market import Market
|
from service.market import Market
|
||||||
from service.port.muta import exportMutant
|
from service.port.muta import exportMutant
|
||||||
from service.port.shared import IPortUser, processing_notify
|
from service.port.shared import IPortUser, fetchItem, processing_notify
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
@@ -536,7 +536,7 @@ def _importGetMutationData(lines):
|
|||||||
if attrInfo is None:
|
if attrInfo is None:
|
||||||
continue
|
continue
|
||||||
mutaAttrs[attrInfo.ID] = value
|
mutaAttrs[attrInfo.ID] = value
|
||||||
mutaItem = _fetchItem(mutaName)
|
mutaItem = fetchItem(mutaName)
|
||||||
if mutaItem is None:
|
if mutaItem is None:
|
||||||
continue
|
continue
|
||||||
data[ref] = (mutaItem, mutaAttrs)
|
data[ref] = (mutaItem, mutaAttrs)
|
||||||
@@ -577,7 +577,7 @@ def _importCreateFit(lines):
|
|||||||
shipType = m.group('shipType').strip()
|
shipType = m.group('shipType').strip()
|
||||||
fitName = m.group('fitName').strip()
|
fitName = m.group('fitName').strip()
|
||||||
try:
|
try:
|
||||||
ship = _fetchItem(shipType)
|
ship = fetchItem(shipType)
|
||||||
try:
|
try:
|
||||||
fit.ship = Ship(ship)
|
fit.ship = Ship(ship)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -589,20 +589,6 @@ def _importCreateFit(lines):
|
|||||||
return fit
|
return fit
|
||||||
|
|
||||||
|
|
||||||
def _fetchItem(typeName, eagerCat=False):
|
|
||||||
sMkt = Market.getInstance()
|
|
||||||
eager = 'group.category' if eagerCat else None
|
|
||||||
try:
|
|
||||||
item = sMkt.getItem(typeName, eager=eager)
|
|
||||||
except:
|
|
||||||
pyfalog.warning('service.port.eft: unable to fetch item "{}"'.format(typeName))
|
|
||||||
return None
|
|
||||||
if sMkt.getPublicityByItem(item):
|
|
||||||
return item
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _clearTail(lst):
|
def _clearTail(lst):
|
||||||
while lst and lst[-1] is None:
|
while lst and lst[-1] is None:
|
||||||
del lst[-1]
|
del lst[-1]
|
||||||
@@ -657,7 +643,7 @@ class Section:
|
|||||||
class BaseItemSpec:
|
class BaseItemSpec:
|
||||||
|
|
||||||
def __init__(self, typeName):
|
def __init__(self, typeName):
|
||||||
item = _fetchItem(typeName, eagerCat=True)
|
item = fetchItem(typeName, eagerCat=True)
|
||||||
if item is None:
|
if item is None:
|
||||||
raise EftImportError
|
raise EftImportError
|
||||||
self.typeName = typeName
|
self.typeName = typeName
|
||||||
@@ -694,7 +680,7 @@ class RegularItemSpec(BaseItemSpec):
|
|||||||
|
|
||||||
def __fetchCharge(self, chargeName):
|
def __fetchCharge(self, chargeName):
|
||||||
if chargeName:
|
if chargeName:
|
||||||
charge = _fetchItem(chargeName, eagerCat=True)
|
charge = fetchItem(chargeName, eagerCat=True)
|
||||||
if not charge or charge.category.name != 'Charge':
|
if not charge or charge.category.name != 'Charge':
|
||||||
charge = None
|
charge = None
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
from eos.db.gamedata.queries import getAttributeInfo
|
from eos.db.gamedata.queries import getAttributeInfo
|
||||||
from gui.utils.numberFormatter import roundToPrec
|
from gui.utils.numberFormatter import roundToPrec
|
||||||
|
from service.port.shared import fetchItem
|
||||||
|
|
||||||
|
|
||||||
def exportMutant(mutant, firstPrefix='', prefix=''):
|
def exportMutant(mutant, firstPrefix='', prefix=''):
|
||||||
@@ -36,3 +37,17 @@ def exportMutant(mutant, firstPrefix='', prefix=''):
|
|||||||
for a in sorted(mutatedAttrs))
|
for a in sorted(mutatedAttrs))
|
||||||
exportLines.append('{}{}'.format(prefix, customAttrsLine))
|
exportLines.append('{}{}'.format(prefix, customAttrsLine))
|
||||||
return '\n'.join(exportLines)
|
return '\n'.join(exportLines)
|
||||||
|
|
||||||
|
|
||||||
|
def importMutant(lines):
|
||||||
|
try:
|
||||||
|
baseName = lines[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
baseName = baseName.strip()
|
||||||
|
mutant = fetchItem(baseName)
|
||||||
|
# try:
|
||||||
|
# mutaName = lines[1]
|
||||||
|
# except IndexError:
|
||||||
|
# return mutant
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,13 @@
|
|||||||
|
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
|
from logbook import Logger
|
||||||
|
|
||||||
|
from service.market import Market
|
||||||
|
|
||||||
|
|
||||||
|
pyfalog = Logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class UserCancelException(Exception):
|
class UserCancelException(Exception):
|
||||||
"""when user cancel on port processing."""
|
"""when user cancel on port processing."""
|
||||||
@@ -68,3 +75,17 @@ class IPortUser(metaclass=ABCMeta):
|
|||||||
def processing_notify(iportuser, flag, data):
|
def processing_notify(iportuser, flag, data):
|
||||||
if not iportuser.on_port_processing(flag, data):
|
if not iportuser.on_port_processing(flag, data):
|
||||||
raise UserCancelException
|
raise UserCancelException
|
||||||
|
|
||||||
|
|
||||||
|
def fetchItem(typeName, eagerCat=False):
|
||||||
|
sMkt = Market.getInstance()
|
||||||
|
eager = 'group.category' if eagerCat else None
|
||||||
|
try:
|
||||||
|
item = sMkt.getItem(typeName, eager=eager)
|
||||||
|
except:
|
||||||
|
pyfalog.warning('service.port.shared: unable to fetch item "{}"'.format(typeName))
|
||||||
|
return None
|
||||||
|
if sMkt.getPublicityByItem(item):
|
||||||
|
return item
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user