EDDNSender: convert_legacy_file() belongs with "open the database"

This commit is contained in:
Athanasius authored and Athanasius committed 2022-11-22 14:02:10 +00:00
1 parent 0e20f4bc00
commit 2b957d140c
1 file changed
+20 -19
+20 -19
View File
@@ -136,6 +136,7 @@ class EDDNSender:
- Ensure the sqlite3 database for EDDN replays exists and has schema.
- Convert any legacy file into the database.
- (Future) Handle any database migrations.
:param eddn_endpoint: Where messages should be sent.
"""
@@ -205,6 +206,25 @@ class EDDNSender:
return db_conn
def convert_legacy_file(self):
"""Convert a legacy file's contents into the sqlite3 db."""
filename = config.app_dir_path / 'replay.jsonl'
try:
with open(filename, 'r+', buffering=1) as replay_file:
for line in replay_file:
cmdr, msg = json.loads(line)
self.add_message(cmdr, msg)
except FileNotFoundError:
pass
finally:
# Best effort at removing the file/contents
# NB: The legacy code assumed it could write to the file.
replay_file = open(filename, 'w') # Will truncate
replay_file.close()
os.unlink(filename)
def close(self) -> None:
"""Clean up any resources."""
if self.db:
@@ -280,25 +300,6 @@ class EDDNSender:
)
self.db_conn.commit()
def convert_legacy_file(self):
"""Convert a legacy file's contents into the sqlite3 db."""
filename = config.app_dir_path / 'replay.jsonl'
try:
with open(filename, 'r+', buffering=1) as replay_file:
for line in replay_file:
cmdr, msg = json.loads(line)
self.add_message(cmdr, msg)
except FileNotFoundError:
pass
finally:
# Best effort at removing the file/contents
# NB: The legacy code assumed it could write to the file.
replay_file = open(filename, 'w') # Will truncate
replay_file.close()
os.unlink(filename)
# TODO: a good few of these methods are static or could be classmethods. they should be created as such.
class EDDN: