@@ -95,11 +95,7 @@ def add(
9595 raise NoFpathError (f"Resource at '{ fpath } ' does not exist." )
9696
9797 rid = generate_id ()
98- rpath = (
99- f"{ self .cache } /{ rid } " + (f".{ fpath .suffix } " if ext else "" )
100- if action != "asis"
101- else str (fpath )
102- )
98+ rpath = f"{ self .cache } /{ rid } " + (f".{ fpath .suffix } " if ext else "" ) if action != "asis" else str (fpath )
10399
104100 # create new record in the database
105101 res = Resource (
@@ -151,11 +147,7 @@ def query(self, query: str, field: str = "rname") -> List[Resource]:
151147 List of matching resources from cache.
152148 """
153149 with self .sessionLocal () as session :
154- return (
155- session .query (Resource )
156- .filter (Resource [field ].ilike ("%{}%" .format (query )))
157- .all ()
158- )
150+ return session .query (Resource ).filter (Resource [field ].ilike ("%{}%" .format (query ))).all ()
159151
160152 def _get (self , session : Session , rname : str ) -> Optional [Resource ]:
161153 """Get a resource with `rname` from given `Session`.
@@ -170,9 +162,7 @@ def _get(self, session: Session, rname: str) -> Optional[Resource]:
170162 Returns:
171163 The `Resource` for the `rname` if available.
172164 """
173- resource : Optional [Resource ] = (
174- session .query (Resource ).filter (Resource .rname == rname ).first ()
175- )
165+ resource : Optional [Resource ] = session .query (Resource ).filter (Resource .rname == rname ).first ()
176166
177167 if resource is not None :
178168 # `Resource` may exist but `rpath` could still be being
@@ -182,8 +172,7 @@ def _get(self, session: Session, rname: str) -> Optional[Resource]:
182172 while not Path (str (resource .rpath )).exists ():
183173 if time () - start >= timeout :
184174 raise RpathTimeoutError (
185- f"For resource: '{ rname } ' the rpath does not exist "
186- f"after { timeout } seconds."
175+ f"For resource: '{ rname } ' the rpath does not exist " f"after { timeout } seconds."
187176 )
188177 sleep (0.1 )
189178
@@ -274,3 +263,12 @@ def update(
274263 # but lets just add it to the cache.
275264 res = self .add (rname = rname , fpath = fpath , action = action )
276265 return res
266+
267+ def list_all (self ) -> List [Resource ]:
268+ """List all resources currently in the cache.
269+
270+ Returns:
271+ List of all Resource objects in the cache.
272+ """
273+ with self .sessionLocal () as session :
274+ return session .query (Resource ).all ()
0 commit comments