Import DNA-formatted fits from chat messages
This commit is contained in:
@@ -38,7 +38,7 @@ from service.market import Market
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
def importDna(string):
|
||||
def importDna(string, fitName=None):
|
||||
sMkt = Market.getInstance()
|
||||
|
||||
ids = list(map(int, re.findall(r'\d+', string)))
|
||||
@@ -65,7 +65,10 @@ def importDna(string):
|
||||
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)
|
||||
if fitName is None:
|
||||
f.name = "{0} - DNA Imported".format(f.ship.item.name)
|
||||
else:
|
||||
f.name = fitName
|
||||
except UnicodeEncodeError:
|
||||
def logtransform(s_):
|
||||
if len(s_) > 10:
|
||||
|
||||
@@ -236,8 +236,14 @@ class Port(object):
|
||||
return "EFT", (cls.importEft(lines),)
|
||||
|
||||
# Check if string is in DNA format
|
||||
if re.match("\d+(:\d+(;\d+))*::", firstLine):
|
||||
dnaPattern = "\d+(:\d+(;\d+))*::"
|
||||
if re.match(dnaPattern, firstLine):
|
||||
return "DNA", (cls.importDna(string),)
|
||||
dnaChatPattern = "<url=fitting:(?P<dna>{})>(?P<fitName>[^<>]+)</url>".format(dnaPattern)
|
||||
m = re.match(dnaChatPattern, firstLine)
|
||||
if m:
|
||||
return "DNA", (cls.importDna(m.group("dna"), fitName=m.group("fitName")),)
|
||||
|
||||
|
||||
# Assume that we import stand-alone abyssal module if all else fails
|
||||
if activeFit is not None:
|
||||
@@ -262,8 +268,8 @@ class Port(object):
|
||||
|
||||
# DNA-related methods
|
||||
@staticmethod
|
||||
def importDna(string):
|
||||
return importDna(string)
|
||||
def importDna(string, fitName=None):
|
||||
return importDna(string, fitName=fitName)
|
||||
|
||||
@staticmethod
|
||||
def exportDna(fit, callback=None):
|
||||
|
||||
Reference in New Issue
Block a user