Skip to content

Commit

Permalink
SqEntryList: remove persist= arg, do not cleanup internally
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 7, 2024
1 parent b03b619 commit 193b09a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
2 changes: 0 additions & 2 deletions pyglossary/glossary_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def _newInMemorySqEntryList(self) -> SqEntryList:
entryFromRaw=self._entryFromRaw,
filename="file::memory:", # or "file::memory:?cache=shared"
create=True,
persist=True,
)

def __init__(
Expand Down Expand Up @@ -978,7 +977,6 @@ def _switchToSQLite(
entryFromRaw=self._entryFromRaw,
filename=sq_fpath,
create=True,
persist=True,
)
self._cleanupPathList.add(sq_fpath)

Expand Down
13 changes: 1 addition & 12 deletions pyglossary/sq_entry_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
from __future__ import annotations

import logging
import os
from os.path import isfile
from typing import TYPE_CHECKING

from .glossary_utils import Error
Expand All @@ -45,20 +43,16 @@ def __init__( # noqa: PLR0913
entryFromRaw: Callable[[RawEntryType], EntryType],
filename: str,
create: bool = True,
persist: bool = False,
) -> None:
"""
sqliteSortKey[i] == (name, type, valueFunc).
persist: do not delete the file when variable is deleted
"""
import sqlite3

self._entryToRaw = entryToRaw
self._entryFromRaw = entryFromRaw
self._filename = filename

self._persist = persist
self._con: sqlite3.Connection | None = sqlite3.connect(filename)
self._cur: sqlite3.Cursor | None = self._con.cursor()

Expand Down Expand Up @@ -204,9 +198,4 @@ def close(self) -> None:
self._cur = None

def __del__(self) -> None:
try:
self.close()
if not self._persist and isfile(self._filename):
os.remove(self._filename)
except AttributeError as e:
log.error(str(e))
self.close()

0 comments on commit 193b09a

Please sign in to comment.