77from . import _utils as ut
88
99
10- def register (path : str , names : Union [str , List [str ]], url : str , retry : int = 3 , wait : int = 1 ):
10+ def register (path : str , names : Union [str , List [str ]], url : str , retry : int = 3 , wait : int = 1 , block : bool = True ):
1111 """
12- Register a directory into the SewerRat search index. It is assumed that
13- that the directory is world-readable and that the caller has write access.
14- If a metadata file cannot be indexed (e.g., due to incorrect formatting,
15- insufficient permissions), a warning will be printed but the function will
16- not throw an error.
12+ Register a directory into the SewerRat search index.
1713
1814 Args:
1915 path:
2016 Path to the directory to be registered.
17+ The directory should be readable by the SewerRat API and the caller should have write access.
2118
2219 names:
23- List of strings containing the base names of metadata files inside
24- ``path`` to be indexed. Alternatively, a single string containing
25- the base name for a single metadata file.
20+ List of strings containing the base names of metadata files inside ``path`` to be indexed.
21+ Alternatively, a single string containing the base name for a single metadata file.
2622
2723 url:
2824 URL to the SewerRat REST API.
@@ -32,6 +28,16 @@ def register(path: str, names: Union[str, List[str]], url: str, retry: int = 3,
3228
3329 wait:
3430 Deprecated, ignored.
31+
32+ block:
33+ Whether to block on successful registration.
34+
35+ Returns:
36+ On success, the directory is registered.
37+ If a metadata file cannot be indexed (e.g., due to incorrect formatting, insufficient permissions), a warning will be printed but the function will not throw an error.
38+
39+ If ``block = False``, the function returns before confirmation of successful registration from the SewerRat API.
40+ This can be useful for asynchronous processing of directories with many files.
3541 """
3642 if isinstance (names , str ):
3743 names = [names ]
@@ -50,13 +56,14 @@ def register(path: str, names: Union[str, List[str]], url: str, retry: int = 3,
5056 handle .write ("" )
5157
5258 try :
53- res = requests .post (url + "/register/finish" , json = { "path" : path , "base" : names }, allow_redirects = True )
59+ res = requests .post (url + "/register/finish" , json = { "path" : path , "base" : names , "block" : block }, allow_redirects = True )
5460 if res .status_code >= 300 :
5561 raise ut .format_error (res )
5662 body = res .json ()
5763 finally :
5864 os .unlink (target )
5965
60- for comment in body ["comments" ]:
61- warnings .warn (comment )
66+ if block :
67+ for comment in body ["comments" ]:
68+ warnings .warn (comment )
6269 return
0 commit comments