Implement exporting in CREST format

This commit is contained in:
blitzmann
2015-10-18 01:33:39 -04:00
parent c4246c0d50
commit 9269c54434
5 changed files with 90 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import os
import sys
import pycrest
# TODO: move all logging back to pyfa.py main loop
# We moved it here just to avoid rebuilding windows skeleton for now (any change to pyfa.py needs it)
@@ -28,6 +29,16 @@ evemonMinVersion = "4081"
clientID = '554727742a354f62ad9dfb34a188abc2'
clientSecret = 'fyCksblVC4AHafeYI9XOcV44xi0AOnMLV8tEU45M'
clientCallback = 'http://localhost:6461'
clientTest = True
# There are times we will need to access the base object outside of CREST calls
# (for example when exporting we need the correct href of the server)
# This will probably move elsewhere eventually
pycrest_eve = pycrest.EVE(
client_id=clientID,
api_key=clientSecret,
redirect_uri=clientCallback,
testing=clientTest)
pyfaPath = None
savePath = None

View File

@@ -25,16 +25,18 @@ class CopySelectDialog(wx.Dialog):
copyFormatEftImps = 1
copyFormatXml = 2
copyFormatDna = 3
copyFormatCrest = 4
def __init__(self, parent):
wx.Dialog.__init__(self, parent, id = wx.ID_ANY, title = u"Select a format", size = (-1,-1), style = wx.DEFAULT_DIALOG_STYLE)
mainSizer = wx.BoxSizer(wx.VERTICAL)
copyFormats = [u"EFT", u"EFT (Implants)", u"XML", u"DNA"]
copyFormats = [u"EFT", u"EFT (Implants)", u"XML", u"DNA", u"CREST"]
copyFormatTooltips = {CopySelectDialog.copyFormatEft: u"EFT text format",
CopySelectDialog.copyFormatEftImps: u"EFT text format",
CopySelectDialog.copyFormatXml: u"EVE native XML format",
CopySelectDialog.copyFormatDna: u"A one-line text format"}
CopySelectDialog.copyFormatDna: u"A one-line text format",
CopySelectDialog.copyFormatCrest: u"A JSON format used for EVE CREST"}
selector = wx.RadioBox(self, wx.ID_ANY, label = u"Copy to the clipboard using:", choices = copyFormats, style = wx.RA_SPECIFY_ROWS)
selector.Bind(wx.EVT_RADIOBOX, self.Selected)
for format, tooltip in copyFormatTooltips.iteritems():

View File

@@ -548,6 +548,10 @@ class MainFrame(wx.Frame):
sFit = service.Fit.getInstance()
toClipboard(sFit.exportDna(self.getActiveFit()))
def clipboardCrest(self):
sFit = service.Fit.getInstance()
toClipboard(sFit.exportCrest(self.getActiveFit()))
def clipboardXml(self):
sFit = service.Fit.getInstance()
toClipboard(sFit.exportXml(None, self.getActiveFit()))
@@ -565,14 +569,15 @@ class MainFrame(wx.Frame):
CopySelectDict = {CopySelectDialog.copyFormatEft: self.clipboardEft,
CopySelectDialog.copyFormatEftImps: self.clipboardEftImps,
CopySelectDialog.copyFormatXml: self.clipboardXml,
CopySelectDialog.copyFormatDna: self.clipboardDna}
CopySelectDialog.copyFormatDna: self.clipboardDna,
CopySelectDialog.copyFormatCrest: self.clipboardCrest}
dlg = CopySelectDialog(self)
dlg.ShowModal()
selected = dlg.GetSelected()
try:
CopySelectDict[selected]()
except:
pass
CopySelectDict[selected]()
dlg.Destroy()
def exportSkillsNeeded(self, event):

View File

@@ -820,6 +820,10 @@ class Fit(object):
fit = eos.db.getFit(fitID)
return Port.exportDna(fit)
def exportCrest(self, fitID, callback=None):
fit = eos.db.getFit(fitID)
return Port.exportCrest(fit, callback)
def exportXml(self, callback=None, *fitIDs):
fits = map(lambda fitID: eos.db.getFit(fitID), fitIDs)
return Port.exportXml(callback, *fits)

View File

@@ -25,6 +25,9 @@ from eos.types import State, Slot, Module, Cargo, Fit, Ship, Drone, Implant, Boo
import service
import wx
import logging
import config
import collections
import json
logger = logging.getLogger("pyfa.service.port")
@@ -34,9 +37,62 @@ except ImportError:
from utils.compat import OrderedDict
EFT_SLOT_ORDER = [Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM]
INV_FLAGS = {
Slot.LOW: 11,
Slot.MED: 19,
Slot.HIGH: 27,
Slot.RIG: 92,
Slot.SUBSYSTEM: 125}
class Port(object):
"""Service which houses all import/export format functions"""
@classmethod
def exportCrest(cls, ofit, callback=None):
print "export"
nested_dict = lambda: collections.defaultdict(nested_dict)
fit = nested_dict()
eve = config.pycrest_eve
fit['name'] = ofit.name
fit['ship']['href'] = "%stypes/%d/"%(eve._endpoint, ofit.ship.item.ID)
fit['ship']['id'] = ofit.ship.item.ID
fit['ship']['name'] = ofit.ship.item.name
fit['description'] = "<pyfa:%d />"%ofit.ID
fit['items'] = []
slotNum = {}
for module in ofit.modules:
if module.isEmpty:
continue
item = nested_dict()
slot = module.slot
if slot == Slot.SUBSYSTEM:
# Order of subsystem matters based on this attr. See GH issue #130
slot = int(module.getModifiedItemAttr("subSystemSlot"))
item['flag'] = slot
item['quantity'] = 1
item['type']['href'] = "%stypes/%d/"%(eve._endpoint, module.item.ID)
item['type']['id'] = module.item.ID
item['type']['name'] = module.item.name
else:
if not slot in slotNum:
slotNum[slot] = INV_FLAGS[slot]
item['flag'] = slotNum[slot]
item['quantity'] = 1
item['type']['href'] = "%stypes/%d/"%(eve._endpoint, module.item.ID)
item['type']['id'] = module.item.ID
item['type']['name'] = module.item.name
slotNum[slot] += 1
fit['items'].append(item)
print json.dumps(fit)
pass
@classmethod
def importAuto(cls, string, path=None, activeFit=None, callback=None, encoding=None):
@@ -63,6 +119,11 @@ class Port(object):
# Use DNA format for all other cases
return "DNA", (cls.importDna(string),)
@staticmethod
def importCrest(json):
pass
@staticmethod
def importDna(string):
sMkt = service.Market.getInstance()