@@ -70,40 +70,6 @@ def get_dict(db, path):
7070 return res
7171
7272
73- def get_paths (db , query_str ):
74- """
75- Docstring for get_paths
76-
77- :param db: Description
78- :param query_str: Description
79- """
80- query_str = f"SELECT DISTINCT path FROM data where { query_str } ;"
81- res = db .execute (query_str , ignore_error = False ).fetchall ()
82- res = [x ["path" ] for x in res ]
83- return res
84-
85-
86- def get_paths_values (db , query_str ):
87- """
88- Docstring for get_paths_values
89-
90- :param db: Description
91- :param query_str: Description
92- """
93- query_str = f"SELECT * FROM data where { query_str } ;"
94- response = db .execute (query_str , ignore_error = False ).fetchall ()
95- res = {}
96- for r in response :
97- path = r ["path" ]
98- # ensure distinct paths
99- # pylint: disable=C0201
100- if path not in res .keys ():
101- r = nest_dict (r )
102- r .pop ("path" )
103- res [path ] = r
104- return res
105-
106-
10773def get (path , db_path , verbose ):
10874 """
10975 Docstring for get
@@ -124,33 +90,16 @@ def get(path, db_path, verbose):
12490 sys .exit (1 )
12591
12692
127- def query (query_str , db_path , show_values ):
93+ def query (query_str , db_path ):
12894 """
12995 Docstring for query
13096
13197 :param query_str: Description
13298 :param db_path: Description
13399 """
134100 db = TraitsDB (db_path )
135- if show_values :
136- res = get_paths_values (db , query_str )
137- if len (res ) > 0 :
138- print (yaml .safe_dump (res ))
139- else :
140- logger .error (
141- "No paths found for traits matching %s in database %s" ,
142- query_str ,
143- db_path ,
144- )
145- sys .exit (1 )
146- else :
147- res = get_paths (db , query_str )
148- if len (res ) > 0 :
149- for r in res :
150- print (r )
151- else :
152- logger .error (
153- "No paths found for traits matching %s in database %s" ,
154- query_str ,
155- db_path ,
156- )
101+ paths = db .get_paths (query_str )
102+ if paths == []:
103+ sys .exit (f"No paths matching query '{ query_str } '" )
104+ for path in paths :
105+ print (path )
0 commit comments