Import / export implants sets
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
import eos.db
|
||||
import eos.types
|
||||
import copy
|
||||
import service.market
|
||||
|
||||
class ImportError(Exception):
|
||||
pass
|
||||
@@ -73,3 +74,51 @@ class ImplantSets():
|
||||
|
||||
def saveChanges(self, s):
|
||||
eos.db.save(s)
|
||||
|
||||
def importSets(self, text):
|
||||
sMkt = service.Market.getInstance()
|
||||
lines = text.splitlines()
|
||||
newSets = []
|
||||
errors = 0
|
||||
current = None
|
||||
lookup = {}
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
line = line.strip()
|
||||
try:
|
||||
if line == '' or line[0] == "#": # comments / empty string
|
||||
continue
|
||||
if line[:1] == "[" and line[-1:] == "]":
|
||||
current = eos.types.ImplantSet(line[1:-1])
|
||||
newSets.append(current)
|
||||
else:
|
||||
item = sMkt.getItem(line)
|
||||
current.implants.append(eos.types.Implant(item))
|
||||
except:
|
||||
errors += 1
|
||||
continue
|
||||
|
||||
for set in self.getImplantSetList():
|
||||
lookup[set.name] = set
|
||||
|
||||
for set in newSets:
|
||||
if set.name in lookup:
|
||||
match = lookup[set.name]
|
||||
for implant in set.implants:
|
||||
match.implants.append(eos.types.Implant(implant.item))
|
||||
else:
|
||||
eos.db.save(set)
|
||||
|
||||
eos.db.commit()
|
||||
|
||||
lenImports = len(newSets)
|
||||
if lenImports == 0:
|
||||
raise ImportError("No patterns found for import")
|
||||
if errors > 0:
|
||||
raise ImportError("%d sets imported from clipboard; %d errors"%(lenImports, errors))
|
||||
|
||||
def exportSets(self):
|
||||
patterns = self.getImplantSetList()
|
||||
patterns.sort(key=lambda p: p.name)
|
||||
return eos.types.ImplantSet.exportSets(*patterns)
|
||||
|
||||
|
||||
@@ -29,12 +29,15 @@ import eos.types
|
||||
from service.settings import SettingsProvider, NetworkSettings
|
||||
import service
|
||||
import service.conversions as conversions
|
||||
import logging
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from utils.compat import OrderedDict
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Event which tells threads dependent on Market that it's initialized
|
||||
mktRdy = threading.Event()
|
||||
|
||||
@@ -349,20 +352,25 @@ class Market():
|
||||
|
||||
def getItem(self, identity, *args, **kwargs):
|
||||
"""Get item by its ID or name"""
|
||||
if isinstance(identity, eos.types.Item):
|
||||
item = identity
|
||||
elif isinstance(identity, int):
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, basestring):
|
||||
# We normally lookup with string when we are using import/export
|
||||
# features. Check against overrides
|
||||
identity = conversions.all.get(identity, identity)
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, float):
|
||||
id = int(identity)
|
||||
item = eos.db.getItem(id, *args, **kwargs)
|
||||
else:
|
||||
raise TypeError("Need Item object, integer, float or string as argument")
|
||||
try:
|
||||
if isinstance(identity, eos.types.Item):
|
||||
item = identity
|
||||
elif isinstance(identity, int):
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, basestring):
|
||||
# We normally lookup with string when we are using import/export
|
||||
# features. Check against overrides
|
||||
identity = conversions.all.get(identity, identity)
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, float):
|
||||
id = int(identity)
|
||||
item = eos.db.getItem(id, *args, **kwargs)
|
||||
else:
|
||||
raise TypeError("Need Item object, integer, float or string as argument")
|
||||
except:
|
||||
logger.error("Could not get item: %s", identity)
|
||||
raise
|
||||
|
||||
return item
|
||||
|
||||
def getGroup(self, identity, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user