@@ -20,20 +20,20 @@ def __init__(self, ingest_service: IngestService) -> None:
20
20
21
21
self ._files_under_root_folder : list [Path ] = list ()
22
22
23
- def _find_all_files_in_folder (self , root_path : Path ) -> None :
23
+ def _find_all_files_in_folder (self , root_path : Path , ignored : list [ str ] ) -> None :
24
24
"""Search all files under the root folder recursively.
25
25
Count them at the same time
26
26
"""
27
27
for file_path in root_path .iterdir ():
28
- if file_path .is_file ():
28
+ if file_path .is_file () and file_path . name not in ignored :
29
29
self .total_documents += 1
30
30
self ._files_under_root_folder .append (file_path )
31
- elif file_path .is_dir ():
32
- self ._find_all_files_in_folder (file_path )
31
+ elif file_path .is_dir () and file_path . name not in ignored :
32
+ self ._find_all_files_in_folder (file_path , ignored )
33
33
34
- def ingest_folder (self , folder_path : Path ) -> None :
34
+ def ingest_folder (self , folder_path : Path , ignored : list [ str ] ) -> None :
35
35
# Count total documents before ingestion
36
- self ._find_all_files_in_folder (folder_path )
36
+ self ._find_all_files_in_folder (folder_path , ignored )
37
37
self ._ingest_all (self ._files_under_root_folder )
38
38
39
39
def _ingest_all (self , files_to_ingest : list [Path ]) -> None :
@@ -64,12 +64,19 @@ def _do_ingest_one(self, changed_path: Path) -> None:
64
64
action = argparse .BooleanOptionalAction ,
65
65
default = False ,
66
66
)
67
+ parser .add_argument (
68
+ "--ignored" ,
69
+ nargs = "*" ,
70
+ help = "List of files/directories to ignore" ,
71
+ default = [],
72
+ )
67
73
parser .add_argument (
68
74
"--log-file" ,
69
75
help = "Optional path to a log file. If provided, logs will be written to this file." ,
70
76
type = str ,
71
77
default = None ,
72
78
)
79
+
73
80
args = parser .parse_args ()
74
81
75
82
# Set up logging to a file if a path is provided
@@ -91,9 +98,17 @@ def _do_ingest_one(self, changed_path: Path) -> None:
91
98
92
99
ingest_service = global_injector .get (IngestService )
93
100
worker = LocalIngestWorker (ingest_service )
94
- worker .ingest_folder (root_path )
101
+ worker .ingest_folder (root_path , args .ignored )
102
+
103
+ if args .ignored :
104
+ logger .info (f"Skipping following files and directories: { args .ignored } " )
95
105
96
106
if args .watch :
97
107
logger .info (f"Watching { args .folder } for changes, press Ctrl+C to stop..." )
108
+ directories_to_watch = [
109
+ dir
110
+ for dir in root_path .iterdir ()
111
+ if dir .is_dir () and dir .name not in args .ignored
112
+ ]
98
113
watcher = IngestWatcher (args .folder , worker .ingest_on_watch )
99
114
watcher .start ()
0 commit comments