diff --git a/src/shortcircuit/model/evedb.py b/src/shortcircuit/model/evedb.py index 4f41b64..a6efec9 100644 --- a/src/shortcircuit/model/evedb.py +++ b/src/shortcircuit/model/evedb.py @@ -1,20 +1,33 @@ # evedb.py import csv +import io import os +from PySide2 import QtCore from .utility.singleton import Singleton -def dict_from_csvqfile(file_path: str): - path = file_path.split('/') - path.insert(0, 'resources') - path.insert(0, '..') - path = os.sep.join(path) - f = open(path, 'r') - reader = csv.reader(f, delimiter=';') +class FileReader: + def __init__(self, file_path: str): + self.reader = None + self.qfile = QtCore.QFile(file_path) + self.status = self.qfile.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text) - return reader + def __iter__(self): + return self + + def __next__(self): + if self.qfile.atEnd(): + raise StopIteration + ret = self.qfile.decodeName(self.qfile.readLine()) # I'm kinda sorry, but not at all + if not ret: + raise StopIteration + return ret + + @staticmethod + def get_dict_from_csv_qfile(file_path: str): + return csv.reader(FileReader(file_path), delimiter=';') class EveDb(metaclass=Singleton): @@ -42,12 +55,12 @@ class EveDb(metaclass=Singleton): ) def __init__(self): - self.gates = [[int(rows[0]), int(rows[1])] for rows in dict_from_csvqfile("database/system_jumps.csv")] + self.gates = [[int(rows[0]), int(rows[1])] for rows in FileReader.get_dict_from_csv_qfile(':database/system_jumps.csv')] self.system_desc = { int(rows[0]): [rows[1], rows[2], float(rows[3])] - for rows in dict_from_csvqfile("database/system_description.csv") + for rows in FileReader.get_dict_from_csv_qfile(':database/system_description.csv') } - self.wh_codes = {rows[0]: int(rows[1]) for rows in dict_from_csvqfile("database/statics.csv")} + self.wh_codes = {rows[0]: int(rows[1]) for rows in FileReader.get_dict_from_csv_qfile(':database/statics.csv')} # TODO properly type this def get_whsize_by_code(self, code):