diff --git a/config.py b/config.py index f298e5775..e0b4ba0c0 100644 --- a/config.py +++ b/config.py @@ -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 diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 0faf850cb..14ee68703 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -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(): diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 2ce0413c1..d2747626a 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -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): diff --git a/service/fit.py b/service/fit.py index b93d3b0b2..efbf95b8b 100644 --- a/service/fit.py +++ b/service/fit.py @@ -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) diff --git a/service/port.py b/service/port.py index 23721945f..8a12ecc4f 100644 --- a/service/port.py +++ b/service/port.py @@ -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'] = ""%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()