Handle import from EFT config store file
(shipname, lines, progress)
| 373 | |
| 374 | |
| 375 | def importEftCfg(shipname, lines, progress): |
| 376 | """Handle import from EFT config store file""" |
| 377 | |
| 378 | # Check if we have such ship in database, bail if we don't |
| 379 | sMkt = Market.getInstance() |
| 380 | try: |
| 381 | sMkt.getItem(shipname) |
| 382 | except (KeyboardInterrupt, SystemExit): |
| 383 | raise |
| 384 | except: |
| 385 | return [] # empty list is expected |
| 386 | |
| 387 | fits = [] # List for fits |
| 388 | fitIndices = [] # List for starting line numbers for each fit |
| 389 | |
| 390 | for line in lines: |
| 391 | # Detect fit header |
| 392 | if line[:1] == "[" and line[-1:] == "]": |
| 393 | # Line index where current fit starts |
| 394 | startPos = lines.index(line) |
| 395 | fitIndices.append(startPos) |
| 396 | |
| 397 | for i, startPos in enumerate(fitIndices): |
| 398 | if progress and progress.userCancelled: |
| 399 | return [] |
| 400 | # End position is last file line if we're trying to get it for last fit, |
| 401 | # or start position of next fit minus 1 |
| 402 | endPos = len(lines) if i == len(fitIndices) - 1 else fitIndices[i + 1] |
| 403 | |
| 404 | # Finally, get lines for current fitting |
| 405 | fitLines = lines[startPos:endPos] |
| 406 | |
| 407 | try: |
| 408 | # Create fit object |
| 409 | fitobj = Fit() |
| 410 | # Strip square brackets and pull out a fit name |
| 411 | fitobj.name = fitLines[0][1:-1] |
| 412 | # Assign ship to fitting |
| 413 | try: |
| 414 | fitobj.ship = Ship(sMkt.getItem(shipname)) |
| 415 | except ValueError: |
| 416 | fitobj.ship = Citadel(sMkt.getItem(shipname)) |
| 417 | |
| 418 | moduleList = [] |
| 419 | for x in range(1, len(fitLines)): |
| 420 | line = fitLines[x] |
| 421 | if not line: |
| 422 | continue |
| 423 | |
| 424 | # Parse line into some data we will need |
| 425 | misc = re.match(r"(Drones|Implant|Booster)_(Active|Inactive)=(.+)", line) |
| 426 | cargo = re.match(r"Cargohold=(.+)", line) |
| 427 | # 2017/03/27 NOTE: store description from EFT |
| 428 | description = re.match(r"Description=(.+)", line) |
| 429 | |
| 430 | if misc: |
| 431 | entityType = misc.group(1) |
| 432 | entityState = misc.group(2) |
no test coverage detected