mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-12 15:27:14 +03:00
Also refactors data.py to edmc_data.py as I'm having weird issues with PyCharm debugger not starting, and this seems to be to do with module name clashes.
16 lines
707 B
Python
16 lines
707 B
Python
"""Utility functions relating to ships."""
|
|
from edmc_data import ship_name_map
|
|
|
|
def ship_file_name(ship_name: str, ship_type: str) -> str:
|
|
"""Return a ship name suitable for a filename."""
|
|
name = str(ship_name or ship_name_map.get(ship_type.lower(), ship_type)).strip()
|
|
if name.endswith('.'):
|
|
name = name[:-2]
|
|
|
|
if name.lower() in ('con', 'prn', 'aux', 'nul',
|
|
'com0', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9',
|
|
'lpt0', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'):
|
|
name = name + '_'
|
|
|
|
return name.translate({ord(x): u'_' for x in ('\0', '<', '>', ':', '"', '/', '\\', '|', '?', '*')})
|