Skip to content

Commit 81292d5

Browse files
committed
Add pathtraits info
1 parent 29095f5 commit 81292d5

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

pathtraits/cli.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import os
77
import click
8-
from pathtraits import scan, access, create as _create
8+
from pathtraits import scan, access, db, create as _create
99

1010
logger = logging.getLogger(__name__)
1111

@@ -111,5 +111,18 @@ def create(path, needed_until, overwrite, verbose):
111111
_create.generate_metadata(path, needed_until, overwrite, verbose)
112112

113113

114+
@main.command()
115+
@click.option(
116+
"--db-path",
117+
default=DB_PATH,
118+
type=click.Path(file_okay=True, dir_okay=False),
119+
)
120+
def info(db_path):
121+
"""
122+
Displays info about the database
123+
"""
124+
db.TraitsDB(db_path).info()
125+
126+
114127
if __name__ == "__main__":
115128
main()

pathtraits/db.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class TraitsDB:
1818
Database of pathtrait in 3NF with view of all joined trait tables
1919
"""
2020

21+
db_path = None
2122
cursor = None
2223
traits = []
2324

@@ -96,8 +97,8 @@ def flatten_dict(dictionary: dict, root_key: str = "", separator: str = "/"):
9697
return dict(items)
9798

9899
def __init__(self, db_path):
99-
db_path = os.path.join(db_path)
100-
self.cursor = sqlite3.connect(db_path, autocommit=True).cursor()
100+
self.db_path = os.path.join(db_path)
101+
self.cursor = sqlite3.connect(self.db_path, autocommit=True).cursor()
101102
self.cursor.row_factory = TraitsDB.row_factory
102103

103104
init_path_table_query = """
@@ -257,6 +258,20 @@ def get_paths(self, query_str):
257258
res = [x["path"] for x in res]
258259
return res
259260

261+
def info(self):
262+
"""
263+
Prints info about this database
264+
265+
:param self: this database
266+
"""
267+
res = {}
268+
res["db_path"] = self.db_path
269+
res["traits"] = self.traits
270+
res["paths"] = len(self.get_paths("TRUE"))
271+
272+
if len(res) > 0:
273+
print(yaml.safe_dump(res))
274+
260275
def put_path_id(self, path):
261276
"""
262277
Docstring for put_path_id

0 commit comments

Comments
 (0)