def importDna(string): sMkt = service.Market.getInstance() info = string.split(":") f = Fit() try: f.ship = Ship(sMkt.getItem(int(info[0]))) f.name = "{0} - DNA Imported".format(f.ship.item.name) except UnicodeEncodeError as e: def logtransform(s): if len(s) > 10: return s[:10] + "..." return s logger.exception("Couldn't import ship data %r", [logtransform(s) for s in info]) return None moduleList = [] for itemInfo in info[1:]: if itemInfo: itemID, amount = itemInfo.split(";") item = sMkt.getItem(int(itemID), eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = int(amount) f.drones.append(d) elif item.category.name == "Charge": c = Cargo(item) c.amount = int(amount) f.cargo.append(c) else: for i in xrange(int(amount)): try: m = Module(item) except: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(f): f.modules.append(m) else: m.owner = f if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): module.owner = f if module.isValidState(State.ACTIVE): module.state = State.ACTIVE f.modules.append(module) return f
def importDna(string): sMkt = service.Market.getInstance() info = string.split(":") f = Fit() f.ship = Ship(sMkt.getItem(int(info[0]))) f.name = "{0} - DNA Imported".format(f.ship.item.name) for itemInfo in info[1:]: if itemInfo: itemID, amount = itemInfo.split(";") item = sMkt.getItem(int(itemID), eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = int(amount) f.drones.append(d) elif item.category.name == "Charge": c = Cargo(item) c.amount = int(amount) f.cargo.append(c) else: for i in xrange(int(amount)): try: m = Module(item) f.modules.append(m) except: pass if m.isValidState(State.ACTIVE): m.state = State.ACTIVE return f
def importXml(cls, text): doc = xml.dom.minidom.parseString(text.encode("utf-8")) fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fits = [] from eos import db for fitting in fittings: f = Fit() f.name = fitting.getAttribute("name") shipType = fitting.getElementsByTagName("shipType").item(0).getAttribute("value") f.ship = Ship(db.getItem(shipType)) hardwares = fitting.getElementsByTagName("hardware") for hardware in hardwares: try: moduleName = hardware.getAttribute("type") item = db.getItem(moduleName, eager="group.category") if item: if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) else: m = Module(item) if m.isValidState(State.ACTIVE): m.state = State.ACTIVE f.modules.append(m) except Exception: continue fits.append(f) return fits
def importCrest(str): fit = json.loads(str) sMkt = service.Market.getInstance() f = Fit() f.name = fit['name'] try: try: f.ship = Ship(sMkt.getItem(fit['ship']['id'])) except ValueError: f.ship = Citadel(sMkt.getItem(fit['ship']['id'])) except: return None items = fit['items'] items.sort(key=lambda k: k['flag']) moduleList = [] for module in items: try: item = sMkt.getItem(module['type']['id'], eager="group.category") if module['flag'] == INV_FLAG_DRONEBAY: d = Drone(item) d.amount = module['quantity'] f.drones.append(d) elif module['flag'] == INV_FLAG_CARGOBAY: c = Cargo(item) c.amount = module['quantity'] f.cargo.append(c) elif module['flag'] == INV_FLAG_FIGHTER: fighter = Fighter(item) f.fighters.append(fighter) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(f): f.modules.append(m) else: if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) except: continue # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): f.modules.append(module) return f
def importDna(cls, string): from eos import db info = string.split(":") f = Fit() f.ship = Ship(db.getItem(int(info[0]))) f.name = "{0} - DNA Imported".format(f.ship.item.name) for itemInfo in info[1:]: if itemInfo: itemID, amount = itemInfo.split(";") item = db.getItem(int(itemID), eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = int(amount) f.drones.append(d) elif item.category.name == "Charge": for i in xrange(int(amount)): for mod in f.modules: if (mod.isValidCharge(item) and mod.charge == None): mod.charge = item break; else: for i in xrange(int(amount)): try: m = Module(item) f.modules.append(m) except: pass if m.isValidState(State.ACTIVE): m.state = State.ACTIVE return f
def importCrest(str): fit = json.loads(str) sMkt = service.Market.getInstance() f = Fit() f.name = fit['name'] try: try: f.ship = Ship(sMkt.getItem(fit['ship']['id'])) except ValueError: f.ship = Citadel(sMkt.getItem(fit['ship']['id'])) except: return None items = fit['items'] items.sort(key=lambda k: k['flag']) moduleList = [] for module in items: try: item = sMkt.getItem(module['type']['id'], eager="group.category") if module['flag'] == INV_FLAG_DRONEBAY: d = Drone(item) d.amount = module['quantity'] f.drones.append(d) elif module['flag'] == INV_FLAG_CARGOBAY: c = Cargo(item) c.amount = module['quantity'] f.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(f): f.modules.append(m) else: if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) except: continue # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): f.modules.append(module) return f
def importDna(string): sMkt = service.Market.getInstance() info = string.split(":") f = Fit() try: f.ship = Ship(sMkt.getItem(int(info[0]))) f.name = "{0} - DNA Imported".format(f.ship.item.name) except UnicodeEncodeError as e: def logtransform(s): if len(s) > 10: return s[:10] + "..." return s logger.exception("Couldn't import ship data %r", [ logtransform(s) for s in info ]) return None moduleList = [] for itemInfo in info[1:]: if itemInfo: itemID, amount = itemInfo.split(";") item = sMkt.getItem(int(itemID), eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = int(amount) f.drones.append(d) elif item.category.name == "Charge": c = Cargo(item) c.amount = int(amount) f.cargo.append(c) else: for i in xrange(int(amount)): try: m = Module(item) except: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(f): f.modules.append(m) else: m.owner = f if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): module.owner = f if module.isValidState(State.ACTIVE): module.state = State.ACTIVE f.modules.append(module) return f
def importCrest(info): sMkt = service.Market.getInstance() network = service.Network.getInstance() try: response = network.request( "https://public-crest.eveonline.com/killmails/%s/%s/" % info, network.EVE) except: return kill = (json.loads(response.read()))['victim'] fit = Fit() fit.ship = Ship(sMkt.getItem(kill['shipType']['name'])) fit.name = "CREST: %s's %s" % (kill['character']['name'], kill['shipType']['name']) # sort based on flag to get proper rack position items = sorted(kill['items'], key=lambda k: k['flag']) # We create a relation between module flag and module position on fit at time of append: # this allows us to know which module to apply charges to if need be (see below) flagMap = {} # Charges may show up before or after the module. We process modules first, # storing any charges that are fitted in a dict and noting their flag (module). charges = {} for mod in items: if mod['flag'] == 5: # throw out cargo continue item = sMkt.getItem(mod['itemType']['name'], eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = mod[ 'quantityDropped'] if 'quantityDropped' in mod else mod[ 'quantityDestroyed'] fit.drones.append(d) elif item.category.name == "Charge": charges[mod['flag']] = item else: m = Module(item) if m.isValidState(State.ACTIVE): m.state = State.ACTIVE fit.modules.append(m) flagMap[mod['flag']] = fit.modules.index(m) for flag, item in charges.items(): # we do not need to verify valid charge as it comes directly from CCP fit.modules[flagMap[flag]].charge = item return fit
def importXml(text, callback=None, encoding="utf-8"): sMkt = service.Market.getInstance() doc = xml.dom.minidom.parseString(text.encode(encoding)) fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fits = [] for i, fitting in enumerate(fittings): f = Fit() f.name = fitting.getAttribute("name") # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item( 0).getAttribute("value") try: f.ship = Ship(sMkt.getItem(shipType)) except: continue hardwares = fitting.getElementsByTagName("hardware") for hardware in hardwares: try: moduleName = hardware.getAttribute("type") try: item = sMkt.getItem(moduleName, eager="group.category") except: continue if item: if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) elif hardware.getAttribute("slot").lower() == "cargo": # although the eve client only support charges in cargo, third-party programs # may support items or "refits" in cargo. Support these by blindly adding all # cargo, not just charges c = Cargo(item) c.amount = int(hardware.getAttribute("qty")) f.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue if m.isValidState(State.ACTIVE): m.state = State.ACTIVE f.modules.append(m) except KeyboardInterrupt: continue fits.append(f) if callback: wx.CallAfter(callback, None) return fits
def importXml(text, callback=None, encoding="utf-8"): sMkt = service.Market.getInstance() doc = xml.dom.minidom.parseString(text.encode(encoding)) fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fits = [] for i, fitting in enumerate(fittings): f = Fit() f.name = fitting.getAttribute("name") # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item(0).getAttribute("value") try: f.ship = Ship(sMkt.getItem(shipType)) except: continue hardwares = fitting.getElementsByTagName("hardware") for hardware in hardwares: try: moduleName = hardware.getAttribute("type") try: item = sMkt.getItem(moduleName, eager="group.category") except: continue if item: if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) elif hardware.getAttribute("slot").lower() == "cargo": # although the eve client only support charges in cargo, third-party programs # may support items or "refits" in cargo. Support these by blindly adding all # cargo, not just charges c = Cargo(item) c.amount = int(hardware.getAttribute("qty")) f.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue if m.isValidState(State.ACTIVE): m.state = State.ACTIVE f.modules.append(m) except KeyboardInterrupt: continue fits.append(f) if callback: wx.CallAfter(callback, None) return fits
def importCrest(cls, info): from eos import db import urllib2 import json try: response = urllib2.urlopen("https://public-crest.eveonline.com/killmails/%s/%s/" % info) except: return kill = (json.loads(response.read()))['victim'] fit = Fit() fit.ship = Ship(db.getItem(kill['shipType']['name'])) fit.name = "CREST: %s's %s" % (kill['character']['name'], kill['shipType']['name']) # sort based on flag to get proper rack position items = sorted(kill['items'], key=lambda k: k['flag']) # We create a relation between module flag and module position on fit at time of append: # this allows us to know which module to apply charges to if need be (see below) flagMap = {} # Charges may show up before or after the module. We process modules first, # storing any charges that are fitted in a dict and noting their flag (module). charges = {} for mod in items: if mod['flag'] == 5: # throw out cargo continue item = db.getItem(mod['itemType']['name'], eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = mod['quantityDropped'] if 'quantityDropped' in mod else mod['quantityDestroyed'] fit.drones.append(d) elif item.category.name == "Charge": charges[mod['flag']] = item else: m = Module(item) if m.isValidState(State.ACTIVE): m.state = State.ACTIVE fit.modules.append(m) flagMap[mod['flag']] = fit.modules.index(m) for flag, item in charges.items(): # we do not need to verify valid charge as it comes directly from CCP fit.modules[flagMap[flag]].charge = item return fit
def importXml(cls, text): doc = xml.dom.minidom.parseString(text.encode("utf-8")) fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fits = [] from eos import db for fitting in fittings: f = Fit() f.name = fitting.getAttribute("name") # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item(0).getAttribute("value") try: f.ship = Ship(db.getItem(shipType)) except: continue hardwares = fitting.getElementsByTagName("hardware") for hardware in hardwares: try: moduleName = hardware.getAttribute("type") try: item = db.getItem(moduleName, eager="group.category") except: continue if item: if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue if m.isValidState(State.ACTIVE): m.state = State.ACTIVE f.modules.append(m) except KeyboardInterrupt: continue fits.append(f) return fits
def importXml(cls, text): doc = xml.dom.minidom.parseString(text.encode("utf-8")) fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fits = [] from eos import db for fitting in fittings: f = Fit() f.name = fitting.getAttribute("name") # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item( 0).getAttribute("value") try: f.ship = Ship(db.getItem(shipType)) except: continue hardwares = fitting.getElementsByTagName("hardware") for hardware in hardwares: try: moduleName = hardware.getAttribute("type") try: item = db.getItem(moduleName, eager="group.category") except: continue if item: if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue if m.isValidState(State.ACTIVE): m.state = State.ACTIVE f.modules.append(m) except KeyboardInterrupt: continue fits.append(f) return fits
def importDna(string): sMkt = service.Market.getInstance() info = string.split(":") f = Fit() try: f.ship = Ship(sMkt.getItem(int(info[0]))) f.name = "{0} - DNA Imported".format(f.ship.item.name) except UnicodeEncodeError as e: def logtransform(s): if len(s) > 10: return s[:10] + "..." return s logger.exception("Couldn't import ship data %r", [logtransform(s) for s in info]) return None for itemInfo in info[1:]: if itemInfo: itemID, amount = itemInfo.split(";") item = sMkt.getItem(int(itemID), eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = int(amount) f.drones.append(d) elif item.category.name == "Charge": c = Cargo(item) c.amount = int(amount) f.cargo.append(c) else: for i in xrange(int(amount)): try: m = Module(item) f.modules.append(m) except: pass if m.isValidState(State.ACTIVE): m.state = State.ACTIVE return f
def importDna(string): sMkt = service.Market.getInstance() info = string.split(":") f = Fit() try: f.ship = Ship(sMkt.getItem(int(info[0]))) f.name = "{0} - DNA Imported".format(f.ship.item.name) except UnicodeEncodeError as e: def logtransform(s): if len(s) > 10: return s[:10] + "..." return s logger.exception("Couldn't import ship data %r", [ logtransform(s) for s in info ]) return None for itemInfo in info[1:]: if itemInfo: itemID, amount = itemInfo.split(";") item = sMkt.getItem(int(itemID), eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = int(amount) f.drones.append(d) elif item.category.name == "Charge": c = Cargo(item) c.amount = int(amount) f.cargo.append(c) else: for i in xrange(int(amount)): try: m = Module(item) f.modules.append(m) except: pass if m.isValidState(State.ACTIVE): m.state = State.ACTIVE return f
def importCrest(str): fit = json.loads(str) sMkt = service.Market.getInstance() f = Fit() f.name = fit['name'] try: f.ship = Ship(sMkt.getItem(fit['ship']['id'])) except: return None items = fit['items'] items.sort(key=lambda k: k['flag']) for module in items: try: item = sMkt.getItem(module['type']['id'], eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = module['quantity'] f.drones.append(d) elif item.category.name == "Charge": c = Cargo(item) c.amount = module['quantity'] f.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue if m.isValidState(State.ACTIVE): m.state = State.ACTIVE f.modules.append(m) except: continue return f
def importXml(text, callback=None, encoding="utf-8"): sMkt = service.Market.getInstance() doc = xml.dom.minidom.parseString(text.encode(encoding)) fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fits = [] for i, fitting in enumerate(fittings): f = Fit() f.name = fitting.getAttribute("name") # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item(0).getAttribute("value") try: try: f.ship = Ship(sMkt.getItem(shipType)) except ValueError: f.ship = Citadel(sMkt.getItem(shipType)) except: continue hardwares = fitting.getElementsByTagName("hardware") moduleList = [] for hardware in hardwares: try: moduleName = hardware.getAttribute("type") try: item = sMkt.getItem(moduleName, eager="group.category") except: continue if item: if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) elif item.category.name == "Fighter": ft = Fighter(item) ft.amount = int(hardware.getAttribute("qty")) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize f.fighters.append(ft) elif hardware.getAttribute("slot").lower() == "cargo": # although the eve client only support charges in cargo, third-party programs # may support items or "refits" in cargo. Support these by blindly adding all # cargo, not just charges c = Cargo(item) c.amount = int(hardware.getAttribute("qty")) f.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(f): m.owner = f f.modules.append(m) else: if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) except KeyboardInterrupt: continue # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): module.owner = f f.modules.append(module) fits.append(f) if callback: wx.CallAfter(callback, None) return fits
def importEftCfg(cls, shipname, contents): """Handle import from EFT config store file""" # Check if we have such ship in database, bail if we don't from eos import db try: db.getItem(shipname) except: return # If client didn't take care of encoding file contents into Unicode, # do it using fallback encoding ourselves if isinstance(contents, str): contents = unicode(contents, "cp1252") # List for fits fits = [] # List for starting line numbers for each fit fitIndices = [] # Separate string into lines lines = re.split('[\n\r]+', contents) for line in lines: # Detect fit header if line[:1] == "[" and line[-1:] == "]": # Line index where current fit starts startPos = lines.index(line) fitIndices.append(startPos) for i, startPos in enumerate(fitIndices): # End position is last file line if we're trying to get it for last fit, # or start position of next fit minus 1 endPos = len(lines) if i == len(fitIndices) - 1 else fitIndices[i + 1] # Finally, get lines for current fitting fitLines = lines[startPos:endPos] try: # Create fit object f = Fit() # Strip square brackets and pull out a fit name f.name = fitLines[0][1:-1] # Assign ship to fitting f.ship = Ship(db.getItem(shipname)) for i in range(1, len(fitLines)): line = fitLines[i] # Parse line into some data we will need misc = re.match("(Drones|Implant|Booster)_(Active|Inactive)=(.+)",line) if misc: entityType = misc.group(1) entityState = misc.group(2) entityData = misc.group(3) if entityType == "Drones": droneData = re.match("(.+),([0-9]+)", entityData) # Get drone name and attempt to detect drone number droneName = droneData.group(1) if droneData else entityData droneAmount = int(droneData.group(2)) if droneData else 1 # Bail if we can't get item or it's not from drone category try: droneItem = db.getItem(droneName, eager="group.category") except: continue if droneItem.category.name != "Drone": continue # Add drone to the fitting d = Drone(droneItem) d.amount = droneAmount if entityState == "Active": d.amountActive = droneAmount elif entityState == "Inactive": d.amountActive = 0 f.drones.append(d) elif entityType == "Implant": # Bail if we can't get item or it's not from implant category try: implantItem = db.getItem(entityData, eager="group.category") except: continue if implantItem.category.name != "Implant": continue # Add implant to the fitting imp = Implant(implantItem) if entityState == "Active": imp.active = True elif entityState == "Inactive": imp.active = False f.implants.append(imp) elif entityType == "Booster": # Bail if we can't get item or it's not from implant category try: boosterItem = db.getItem(entityData, eager="group.category") except: continue # All boosters have implant category if boosterItem.category.name != "Implant": continue # Add booster to the fitting b = Booster(boosterItem) if entityState == "Active": b.active = True elif entityState == "Inactive": b.active = False f.boosters.append(b) # If we don't have any prefixes, then it's a module else: withCharge = re.match("(.+),(.+)", line) modName = withCharge.group(1) if withCharge else line chargeName = withCharge.group(2) if withCharge else None # If we can't get module item, skip it try: modItem = db.getItem(modName) except: continue # Create module and activate it if it's activable m = Module(modItem) if m.isValidState(State.ACTIVE): m.state = State.ACTIVE # Add charge to mod if applicable, on any errors just don't add anything if chargeName: try: chargeItem = db.getItem(chargeName, eager="group.category") if chargeItem.category.name == "Charge": m.charge = chargeItem except: pass # Append module to fit f.modules.append(m) # Append fit to list of fits fits.append(f) # Skip fit silently if we get an exception except Exception: pass return fits
def importEft(cls, eftString): from eos import db offineSuffix = " /OFFLINE" fit = cls() eftString = eftString.strip() lines = re.split('[\n\r]+', eftString) info = lines[0][1:-1].split(",", 1) if len(info) == 2: shipType = info[0].strip() fitName = info[1].strip() else: shipType = info[0].strip() fitName = "Imported %s" % shipType try: fit.ship = Ship(db.getItem(shipType)) fit.name = fitName except: return droneMap = {} for i in range(1, len(lines)): line = lines[i] setOffline = line.endswith(offineSuffix) if setOffline == True: line = line[:len(line) - len(offineSuffix)] modAmmo = line.split(",") modDrone = modAmmo[0].split(" x") if len(modAmmo) == 2: ammoName = modAmmo[1].strip() else: ammoName = None modName = modDrone[0].strip() if len(modDrone) == 2: droneAmount = modDrone[1].strip() else: droneAmount = None try: item = db.getItem(modName, eager="group.category") except: try: item = db.getItem(modAmmo[0], eager="group.category") except: continue if item.category.name == "Drone": droneAmount = int(droneAmount) if droneAmount is not None else 1 if not modName in droneMap: droneMap[modName] = 0 droneMap[modName] += droneAmount elif item.category.name == "Implant": fit.implants.append(Implant(item)) else: m = Module(item) if ammoName: try: m.charge = db.getItem(ammoName) except: pass if setOffline == True and m.isValidState(State.OFFLINE): m.state = State.OFFLINE elif m.isValidState(State.ACTIVE): m.state = State.ACTIVE fit.modules.append(m) for droneName in droneMap: d = Drone(db.getItem(droneName)) d.amount = droneMap[droneName] fit.drones.append(d) return fit
def importFittingWindow(string, activeFit): sMkt = service.Market.getInstance() sFit = service.Fit.getInstance() activeFit = sFit.getFit(activeFit) # if the current fit has mods, do not mess with it. Instead, make new fit if activeFit.modCount > 0: fit = Fit() fit.ship = Ship(sMkt.getItem(activeFit.ship.item.ID)) fit.name = "%s (copy)" % activeFit.name else: fit = activeFit lines = re.split('[\n\r]+', string) droneMap = {} cargoMap = {} modules = [] for i in range(1, len(lines)): line = lines[i].strip() if not line: continue try: amount, modName = line.split("x ") amount = int(amount) item = sMkt.getItem(modName, eager="group.category") except: # if no data can be found (old names) continue if item.category.name == "Drone": if not modName in droneMap: droneMap[modName] = 0 droneMap[modName] += amount elif item.category.name == "Charge": if not modName in cargoMap: cargoMap[modName] = 0 cargoMap[modName] += amount else: for _ in xrange(amount): try: m = Module(item) except ValueError: continue # If we are importing T3 ship, we must apply subsystems first, then # calcModAttr() to get the ship slots if m.slot == Slot.SUBSYSTEM and m.fits(fit): fit.modules.append(m) else: modules.append(m) fit.clear() fit.calculateModifiedAttributes() for m in modules: # we check to see if module fits as a basic sanity check # if it doesn't then the imported fit is most likely invalid # (ie: user tried to import Legion fit to a Rifter) if m.fits(fit): fit.modules.append(m) if m.isValidState(State.ACTIVE): m.state = State.ACTIVE m.owner = fit # not sure why this is required when it's not for other import methods, but whatever else: return for droneName in droneMap: d = Drone(sMkt.getItem(droneName)) d.amount = droneMap[droneName] fit.drones.append(d) for cargoName in cargoMap: c = Cargo(sMkt.getItem(cargoName)) c.amount = cargoMap[cargoName] fit.cargo.append(c) return fit
def importEft(eftString): sMkt = service.Market.getInstance() offineSuffix = " /OFFLINE" fit = Fit() eftString = eftString.strip() lines = re.split('[\n\r]+', eftString) info = lines[0][1:-1].split(",", 1) if len(info) == 2: shipType = info[0].strip() fitName = info[1].strip() else: shipType = info[0].strip() fitName = "Imported %s" % shipType try: ship = sMkt.getItem(shipType) fit.ship = Ship(ship) fit.name = fitName except: return # maintain map of drones and their quantities droneMap = {} cargoMap = {} for i in range(1, len(lines)): ammoName = None extraAmount = None line = lines[i].strip() if not line: continue setOffline = line.endswith(offineSuffix) if setOffline is True: # remove offline suffix from line line = line[:len(line) - len(offineSuffix)] modAmmo = line.split(",") # matches drone and cargo with x{qty} modExtra = modAmmo[0].split(" x") if len(modAmmo) == 2: # line with a module and ammo ammoName = modAmmo[1].strip() modName = modAmmo[0].strip() elif len(modExtra) == 2: # line with drone/cargo and qty extraAmount = modExtra[1].strip() modName = modExtra[0].strip() else: # line with just module modName = modExtra[0].strip() try: # get item information. If we are on a Drone/Cargo line, throw out cargo item = sMkt.getItem(modName, eager="group.category") except: # if no data can be found (old names) continue if item.category.name == "Drone": extraAmount = int( extraAmount) if extraAmount is not None else 1 if not modName in droneMap: droneMap[modName] = 0 droneMap[modName] += extraAmount if len(modExtra) == 2 and item.category.name != "Drone": extraAmount = int( extraAmount) if extraAmount is not None else 1 if not modName in cargoMap: cargoMap[modName] = 0 cargoMap[modName] += extraAmount elif item.category.name == "Implant": fit.implants.append(Implant(item)) else: try: m = Module(item) except ValueError: continue if ammoName: try: ammo = sMkt.getItem(ammoName) if m.isValidCharge(ammo) and m.charge is None: m.charge = ammo except: pass if setOffline is True and m.isValidState(State.OFFLINE): m.state = State.OFFLINE elif m.isValidState(State.ACTIVE): m.state = State.ACTIVE fit.modules.append(m) for droneName in droneMap: d = Drone(sMkt.getItem(droneName)) d.amount = droneMap[droneName] fit.drones.append(d) for cargoName in cargoMap: c = Cargo(sMkt.getItem(cargoName)) c.amount = cargoMap[cargoName] fit.cargo.append(c) return fit
def importXml(text, callback=None, encoding="utf-8"): sMkt = service.Market.getInstance() doc = xml.dom.minidom.parseString(text.encode(encoding)) fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fits = [] for i, fitting in enumerate(fittings): f = Fit() f.name = fitting.getAttribute("name") # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item( 0).getAttribute("value") try: try: f.ship = Ship(sMkt.getItem(shipType)) except ValueError: f.ship = Citadel(sMkt.getItem(shipType)) except: continue hardwares = fitting.getElementsByTagName("hardware") moduleList = [] for hardware in hardwares: try: moduleName = hardware.getAttribute("type") try: item = sMkt.getItem(moduleName, eager="group.category") except: continue if item: if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) elif item.category.name == "Fighter": ft = Fighter(item) ft.amount = int( hardware.getAttribute("qty") ) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize f.fighters.append(ft) elif hardware.getAttribute("slot").lower() == "cargo": # although the eve client only support charges in cargo, third-party programs # may support items or "refits" in cargo. Support these by blindly adding all # cargo, not just charges c = Cargo(item) c.amount = int(hardware.getAttribute("qty")) f.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(f): m.owner = f f.modules.append(m) else: if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) except KeyboardInterrupt: continue # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): module.owner = f f.modules.append(module) fits.append(f) if callback: wx.CallAfter(callback, None) return fits
def importEft(eftString): sMkt = service.Market.getInstance() offineSuffix = " /OFFLINE" fit = Fit() eftString = eftString.strip() lines = re.split('[\n\r]+', eftString) info = lines[0][1:-1].split(",", 1) if len(info) == 2: shipType = info[0].strip() fitName = info[1].strip() else: shipType = info[0].strip() fitName = "Imported %s" % shipType try: ship = sMkt.getItem(shipType) fit.ship = Ship(ship) fit.name = fitName except: return # maintain map of drones and their quantities droneMap = {} cargoMap = {} moduleList = [] for i in range(1, len(lines)): ammoName = None extraAmount = None line = lines[i].strip() if not line: continue setOffline = line.endswith(offineSuffix) if setOffline is True: # remove offline suffix from line line = line[:len(line) - len(offineSuffix)] modAmmo = line.split(",") # matches drone and cargo with x{qty} modExtra = modAmmo[0].split(" x") if len(modAmmo) == 2: # line with a module and ammo ammoName = modAmmo[1].strip() modName = modAmmo[0].strip() elif len(modExtra) == 2: # line with drone/cargo and qty extraAmount = modExtra[1].strip() modName = modExtra[0].strip() else: # line with just module modName = modExtra[0].strip() try: # get item information. If we are on a Drone/Cargo line, throw out cargo item = sMkt.getItem(modName, eager="group.category") except: # if no data can be found (old names) continue if item.category.name == "Drone": extraAmount = int(extraAmount) if extraAmount is not None else 1 if not modName in droneMap: droneMap[modName] = 0 droneMap[modName] += extraAmount if len(modExtra) == 2 and item.category.name != "Drone": extraAmount = int(extraAmount) if extraAmount is not None else 1 if not modName in cargoMap: cargoMap[modName] = 0 cargoMap[modName] += extraAmount elif item.category.name == "Implant": fit.implants.append(Implant(item)) # elif item.category.name == "Subsystem": # try: # subsystem = Module(item) # except ValueError: # continue # # if subsystem.fits(fit): # fit.modules.append(subsystem) else: try: m = Module(item) except ValueError: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(fit): fit.modules.append(m) else: if ammoName: try: ammo = sMkt.getItem(ammoName) if m.isValidCharge(ammo) and m.charge is None: m.charge = ammo except: pass if setOffline is True and m.isValidState(State.OFFLINE): m.state = State.OFFLINE elif m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(fit) for m in moduleList: if m.fits(fit): m.owner = fit if not m.isValidState(m.state): print "Error: Module", m, "cannot have state", m.state fit.modules.append(m) for droneName in droneMap: d = Drone(sMkt.getItem(droneName)) d.amount = droneMap[droneName] fit.drones.append(d) for cargoName in cargoMap: c = Cargo(sMkt.getItem(cargoName)) c.amount = cargoMap[cargoName] fit.cargo.append(c) return fit
def importEft(eftString): sMkt = service.Market.getInstance() offineSuffix = " /OFFLINE" fit = Fit() eftString = eftString.strip() lines = re.split('[\n\r]+', eftString) info = lines[0][1:-1].split(",", 1) if len(info) == 2: shipType = info[0].strip() fitName = info[1].strip() else: shipType = info[0].strip() fitName = "Imported %s" % shipType try: ship = sMkt.getItem(shipType) try: fit.ship = Ship(ship) except ValueError: fit.ship = Citadel(ship) fit.name = fitName except: return # maintain map of drones and their quantities droneMap = {} cargoMap = {} moduleList = [] for i in range(1, len(lines)): ammoName = None extraAmount = None line = lines[i].strip() if not line: continue setOffline = line.endswith(offineSuffix) if setOffline is True: # remove offline suffix from line line = line[:len(line) - len(offineSuffix)] modAmmo = line.split(",") # matches drone and cargo with x{qty} modExtra = modAmmo[0].split(" x") if len(modAmmo) == 2: # line with a module and ammo ammoName = modAmmo[1].strip() modName = modAmmo[0].strip() elif len(modExtra) == 2: # line with drone/cargo and qty extraAmount = modExtra[1].strip() modName = modExtra[0].strip() else: # line with just module modName = modExtra[0].strip() try: # get item information. If we are on a Drone/Cargo line, throw out cargo item = sMkt.getItem(modName, eager="group.category") except: # if no data can be found (old names) continue if item.category.name == "Drone": extraAmount = int( extraAmount) if extraAmount is not None else 1 if not modName in droneMap: droneMap[modName] = 0 droneMap[modName] += extraAmount elif item.category.name == "Fighter": extraAmount = int( extraAmount) if extraAmount is not None else 1 fighterItem = Fighter(item) if (extraAmount > fighterItem.fighterSquadronMaxSize ): #Amount bigger then max fightergroup size extraAmount = fighterItem.fighterSquadronMaxSize if fighterItem.fits(fit): fit.fighters.append(fighterItem) if len( modExtra ) == 2 and item.category.name != "Drone" and item.category.name != "Fighter": extraAmount = int( extraAmount) if extraAmount is not None else 1 if not modName in cargoMap: cargoMap[modName] = 0 cargoMap[modName] += extraAmount elif item.category.name == "Implant": fit.implants.append(Implant(item)) # elif item.category.name == "Subsystem": # try: # subsystem = Module(item) # except ValueError: # continue # # if subsystem.fits(fit): # fit.modules.append(subsystem) else: try: m = Module(item) except ValueError: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(fit): fit.modules.append(m) else: if ammoName: try: ammo = sMkt.getItem(ammoName) if m.isValidCharge(ammo) and m.charge is None: m.charge = ammo except: pass if setOffline is True and m.isValidState(State.OFFLINE): m.state = State.OFFLINE elif m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(fit) for m in moduleList: if m.fits(fit): m.owner = fit if not m.isValidState(m.state): print "Error: Module", m, "cannot have state", m.state fit.modules.append(m) for droneName in droneMap: d = Drone(sMkt.getItem(droneName)) d.amount = droneMap[droneName] fit.drones.append(d) for cargoName in cargoMap: c = Cargo(sMkt.getItem(cargoName)) c.amount = cargoMap[cargoName] fit.cargo.append(c) return fit
def importEftCfg(shipname, contents, callback=None): """Handle import from EFT config store file""" # Check if we have such ship in database, bail if we don't sMkt = service.Market.getInstance() try: sMkt.getItem(shipname) except: return [] # empty list is expected # If client didn't take care of encoding file contents into Unicode, # do it using fallback encoding ourselves if isinstance(contents, str): contents = unicode(contents, "cp1252") fits = [] # List for fits fitIndices = [] # List for starting line numbers for each fit lines = re.split('[\n\r]+', contents) # Separate string into lines for line in lines: # Detect fit header if line[:1] == "[" and line[-1:] == "]": # Line index where current fit starts startPos = lines.index(line) fitIndices.append(startPos) for i, startPos in enumerate(fitIndices): # End position is last file line if we're trying to get it for last fit, # or start position of next fit minus 1 endPos = len(lines) if i == len(fitIndices) - 1 else fitIndices[i + 1] # Finally, get lines for current fitting fitLines = lines[startPos:endPos] try: # Create fit object f = Fit() # Strip square brackets and pull out a fit name f.name = fitLines[0][1:-1] # Assign ship to fitting try: f.ship = Ship(sMkt.getItem(shipname)) except ValueError: f.ship = Citadel(sMkt.getItem(shipname)) moduleList = [] for x in range(1, len(fitLines)): line = fitLines[x] if not line: continue # Parse line into some data we will need misc = re.match( "(Drones|Implant|Booster)_(Active|Inactive)=(.+)", line) cargo = re.match("Cargohold=(.+)", line) if misc: entityType = misc.group(1) entityState = misc.group(2) entityData = misc.group(3) if entityType == "Drones": droneData = re.match("(.+),([0-9]+)", entityData) # Get drone name and attempt to detect drone number droneName = droneData.group( 1) if droneData else entityData droneAmount = int( droneData.group(2)) if droneData else 1 # Bail if we can't get item or it's not from drone category try: droneItem = sMkt.getItem( droneName, eager="group.category") except: continue if droneItem.category.name == "Drone": # Add drone to the fitting d = Drone(droneItem) d.amount = droneAmount if entityState == "Active": d.amountActive = droneAmount elif entityState == "Inactive": d.amountActive = 0 f.drones.append(d) elif droneItem.category.name == "Fighter": # EFT saves fighter as drones ft = Fighter(droneItem) ft.amount = int( droneAmount ) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize f.fighters.append(ft) else: continue elif entityType == "Implant": # Bail if we can't get item or it's not from implant category try: implantItem = sMkt.getItem( entityData, eager="group.category") except: continue if implantItem.category.name != "Implant": continue # Add implant to the fitting imp = Implant(implantItem) if entityState == "Active": imp.active = True elif entityState == "Inactive": imp.active = False f.implants.append(imp) elif entityType == "Booster": # Bail if we can't get item or it's not from implant category try: boosterItem = sMkt.getItem( entityData, eager="group.category") except: continue # All boosters have implant category if boosterItem.category.name != "Implant": continue # Add booster to the fitting b = Booster(boosterItem) if entityState == "Active": b.active = True elif entityState == "Inactive": b.active = False f.boosters.append(b) # If we don't have any prefixes, then it's a module elif cargo: cargoData = re.match("(.+),([0-9]+)", cargo.group(1)) cargoName = cargoData.group( 1) if cargoData else cargo.group(1) cargoAmount = int( cargoData.group(2)) if cargoData else 1 # Bail if we can't get item try: item = sMkt.getItem(cargoName) except: continue # Add Cargo to the fitting c = Cargo(item) c.amount = cargoAmount f.cargo.append(c) else: withCharge = re.match("(.+),(.+)", line) modName = withCharge.group(1) if withCharge else line chargeName = withCharge.group( 2) if withCharge else None # If we can't get module item, skip it try: modItem = sMkt.getItem(modName) except: continue # Create module m = Module(modItem) # Add subsystems before modules to make sure T3 cruisers have subsystems installed if modItem.category.name == "Subsystem": if m.fits(f): f.modules.append(m) else: m.owner = f # Activate mod if it is activable if m.isValidState(State.ACTIVE): m.state = State.ACTIVE # Add charge to mod if applicable, on any errors just don't add anything if chargeName: try: chargeItem = sMkt.getItem( chargeName, eager="group.category") if chargeItem.category.name == "Charge": m.charge = chargeItem except: pass # Append module to fit moduleList.append(m) # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): f.modules.append(module) # Append fit to list of fits fits.append(f) if callback: wx.CallAfter(callback, None) # Skip fit silently if we get an exception except Exception: pass return fits
def importEftCfg(shipname, contents, callback=None): """Handle import from EFT config store file""" # Check if we have such ship in database, bail if we don't sMkt = service.Market.getInstance() try: sMkt.getItem(shipname) except: return [] # empty list is expected # If client didn't take care of encoding file contents into Unicode, # do it using fallback encoding ourselves if isinstance(contents, str): contents = unicode(contents, "cp1252") fits = [] # List for fits fitIndices = [] # List for starting line numbers for each fit lines = re.split('[\n\r]+', contents) # Separate string into lines for line in lines: # Detect fit header if line[:1] == "[" and line[-1:] == "]": # Line index where current fit starts startPos = lines.index(line) fitIndices.append(startPos) for i, startPos in enumerate(fitIndices): # End position is last file line if we're trying to get it for last fit, # or start position of next fit minus 1 endPos = len(lines) if i == len(fitIndices) - 1 else fitIndices[i + 1] # Finally, get lines for current fitting fitLines = lines[startPos:endPos] try: # Create fit object f = Fit() # Strip square brackets and pull out a fit name f.name = fitLines[0][1:-1] # Assign ship to fitting f.ship = Ship(sMkt.getItem(shipname)) moduleList = [] for x in range(1, len(fitLines)): line = fitLines[x] if not line: continue # Parse line into some data we will need misc = re.match("(Drones|Implant|Booster)_(Active|Inactive)=(.+)", line) cargo = re.match("Cargohold=(.+)", line) if misc: entityType = misc.group(1) entityState = misc.group(2) entityData = misc.group(3) if entityType == "Drones": droneData = re.match("(.+),([0-9]+)", entityData) # Get drone name and attempt to detect drone number droneName = droneData.group(1) if droneData else entityData droneAmount = int(droneData.group(2)) if droneData else 1 # Bail if we can't get item or it's not from drone category try: droneItem = sMkt.getItem(droneName, eager="group.category") except: continue if droneItem.category.name != "Drone": continue # Add drone to the fitting d = Drone(droneItem) d.amount = droneAmount if entityState == "Active": d.amountActive = droneAmount elif entityState == "Inactive": d.amountActive = 0 f.drones.append(d) elif entityType == "Implant": # Bail if we can't get item or it's not from implant category try: implantItem = sMkt.getItem(entityData, eager="group.category") except: continue if implantItem.category.name != "Implant": continue # Add implant to the fitting imp = Implant(implantItem) if entityState == "Active": imp.active = True elif entityState == "Inactive": imp.active = False f.implants.append(imp) elif entityType == "Booster": # Bail if we can't get item or it's not from implant category try: boosterItem = sMkt.getItem(entityData, eager="group.category") except: continue # All boosters have implant category if boosterItem.category.name != "Implant": continue # Add booster to the fitting b = Booster(boosterItem) if entityState == "Active": b.active = True elif entityState == "Inactive": b.active = False f.boosters.append(b) # If we don't have any prefixes, then it's a module elif cargo: cargoData = re.match("(.+),([0-9]+)", cargo.group(1)) cargoName = cargoData.group(1) if cargoData else cargo.group(1) cargoAmount = int(cargoData.group(2)) if cargoData else 1 # Bail if we can't get item try: item = sMkt.getItem(cargoName) except: continue # Add Cargo to the fitting c = Cargo(item) c.amount = cargoAmount f.cargo.append(c) else: withCharge = re.match("(.+),(.+)", line) modName = withCharge.group(1) if withCharge else line chargeName = withCharge.group(2) if withCharge else None # If we can't get module item, skip it try: modItem = sMkt.getItem(modName) except: continue # Create module m = Module(modItem) # Add subsystems before modules to make sure T3 cruisers have subsystems installed if modItem.category.name == "Subsystem": if m.fits(f): f.modules.append(m) else: m.owner = f # Activate mod if it is activable if m.isValidState(State.ACTIVE): m.state = State.ACTIVE # Add charge to mod if applicable, on any errors just don't add anything if chargeName: try: chargeItem = sMkt.getItem(chargeName, eager="group.category") if chargeItem.category.name == "Charge": m.charge = chargeItem except: pass # Append module to fit moduleList.append(m) # Recalc to get slot numbers correct for T3 cruisers service.Fit.getInstance().recalc(f) for module in moduleList: if module.fits(f): f.modules.append(module) # Append fit to list of fits fits.append(f) if callback: wx.CallAfter(callback, None) # Skip fit silently if we get an exception except Exception: pass return fits
def importDna(string): sMkt = Market.getInstance() ids = map(int, re.findall(r'\d+', string)) for id_ in ids: try: try: try: Ship(sMkt.getItem(sMkt.getItem(id_))) except ValueError: Citadel(sMkt.getItem(sMkt.getItem(id_))) except ValueError: Citadel(sMkt.getItem(id_)) string = string[string.index(str(id_)):] break except: pass string = string[:string.index("::") + 2] info = string.split(":") f = Fit() try: try: f.ship = Ship(sMkt.getItem(int(info[0]))) except ValueError: f.ship = Citadel(sMkt.getItem(int(info[0]))) f.name = "{0} - DNA Imported".format(f.ship.item.name) except UnicodeEncodeError: def logtransform(s_): if len(s_) > 10: return s_[:10] + "..." return s_ logger.exception("Couldn't import ship data %r", [logtransform(s) for s in info]) return None moduleList = [] for itemInfo in info[1:]: if itemInfo: itemID, amount = itemInfo.split(";") item = sMkt.getItem(int(itemID), eager="group.category") if item.category.name == "Drone": d = Drone(item) d.amount = int(amount) f.drones.append(d) elif item.category.name == "Fighter": ft = Fighter(item) ft.amount = int(amount) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize if ft.fits(f): f.fighters.append(ft) elif item.category.name == "Charge": c = Cargo(item) c.amount = int(amount) f.cargo.append(c) else: for i in xrange(int(amount)): try: m = Module(item) except: continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(f): f.modules.append(m) else: m.owner = f if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) # Recalc to get slot numbers correct for T3 cruisers svcFit.getInstance().recalc(f) for module in moduleList: if module.fits(f): module.owner = f if module.isValidState(State.ACTIVE): module.state = State.ACTIVE f.modules.append(module) return f