Skip to content

Commit dadeff9

Browse files
committed
Fix NFS database to usethe new super class
1 parent a3bc425 commit dadeff9

2 files changed

Lines changed: 5 additions & 28 deletions

File tree

nxc/protocols/nfs/database.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1-
from pathlib import Path
2-
from sqlalchemy.orm import sessionmaker, scoped_session
3-
from sqlalchemy import MetaData, Table
1+
from sqlalchemy import Table
42
from sqlalchemy.exc import (
5-
IllegalStateChangeError,
63
NoInspectionAvailable,
74
NoSuchTableError,
85
)
9-
from nxc.logger import nxc_logger
6+
from nxc.database import BaseDB
107
import sys
118

129

13-
class database:
10+
class database(BaseDB):
1411
def __init__(self, db_engine):
1512
self.CredentialsTable = None
1613
self.HostsTable = None
1714
self.LoggedinRelationsTable = None
1815
self.SharesTable = None
1916

20-
self.db_engine = db_engine
21-
self.db_path = self.db_engine.url.database
22-
self.protocol = Path(self.db_path).stem.upper()
23-
self.metadata = MetaData()
24-
self.reflect_tables()
25-
26-
session_factory = sessionmaker(bind=self.db_engine, expire_on_commit=True)
27-
Session = scoped_session(session_factory)
28-
self.sess = Session()
17+
super().__init__(db_engine)
2918

3019
@staticmethod
3120
def db_schema(db_conn):
@@ -79,16 +68,3 @@ def reflect_tables(self):
7968
[-] Then remove the {self.protocol} DB (`rm -f {self.db_path}`) and run nxc to initialize the new DB"""
8069
)
8170
sys.exit()
82-
83-
def shutdown_db(self):
84-
try:
85-
self.sess.close()
86-
# due to the async nature of nxc, sometimes session state is a bit messy and this will throw:
87-
# Method 'close()' can't be called here; method '_connection_for_bind()' is already in progress and
88-
# this would cause an unexpected state change to <SessionTransactionState.CLOSED: 5>
89-
except IllegalStateChangeError as e:
90-
nxc_logger.debug(f"Error while closing session db object: {e}")
91-
92-
def clear_database(self):
93-
for table in self.metadata.sorted_tables:
94-
self.sess.execute(table.delete())

nxc/protocols/ssh/database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, db_engine):
2626
self.LoggedinRelationsTable = None
2727
self.AdminRelationsTable = None
2828
self.KeysTable = None
29+
2930
super().__init__(db_engine)
3031

3132
@staticmethod

0 commit comments

Comments
 (0)