MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / importPatterns

Method importPatterns

eos/saveddata/damagePattern.py:275–328  ·  view source on GitHub ↗
(cls, text)

Source from the content-addressed store, hash-verified

273
274 @classmethod
275 def importPatterns(cls, text):
276 lines = re.split('[\n\r]+', text)
277 patterns = []
278 numPatterns = 0
279
280 # When we import damage profiles, we create new ones and update old ones. To do this, get a list of current
281 # patterns to allow lookup
282 lookup = {}
283 current = eos.db.getDamagePatternList()
284 for pattern in current:
285 lookup[pattern.rawName] = pattern
286
287 for line in lines:
288 try:
289 if line.strip()[0] == "#": # comments
290 continue
291 line = line.split('#', 1)[0] # allows for comments
292 type, data = line.rsplit('=', 1)
293 type, data = type.strip(), data.split(',')
294 except (KeyboardInterrupt, SystemExit):
295 raise
296 except:
297 # Data isn't in correct format, continue to next line
298 continue
299
300 if type != "DamageProfile":
301 continue
302
303 numPatterns += 1
304 name, data = data[0], data[1:5]
305 fields = {}
306
307 for index, val in enumerate(data):
308 try:
309 fields["%sAmount" % cls.DAMAGE_TYPES[index]] = int(val)
310 except (KeyboardInterrupt, SystemExit):
311 raise
312 except:
313 continue
314
315 if len(fields) == 4: # Avoid possible blank lines
316 if name.strip() in lookup:
317 pattern = lookup[name.strip()]
318 pattern.update(**fields)
319 eos.db.save(pattern)
320 else:
321 pattern = DamagePattern(**fields)
322 pattern.rawName = name.strip()
323 eos.db.save(pattern)
324 patterns.append(pattern)
325
326 eos.db.commit()
327
328 return patterns, numPatterns
329
330 EXPORT_FORMAT = "DamageProfile = %s,%d,%d,%d,%d\n"
331

Callers

nothing calls this directly

Calls 4

updateMethod · 0.95
saveMethod · 0.80
DamagePatternClass · 0.70
appendMethod · 0.45

Tested by

no test coverage detected