10
10
CompleteHandleFileEvent ,
11
11
PDFFileProgressEvent ,
12
12
PDFFileStep ,
13
+ HandleFileOperation ,
13
14
)
14
15
15
16
@@ -27,9 +28,15 @@ class InterruptionStatus(IntEnum):
27
28
@dataclass
28
29
class HandingFile :
29
30
path : str
31
+ operation : HandleFileOperation
30
32
pdf_handing : tuple [int , int ] | None = None
31
33
pdf_indexing : tuple [int , int ] | None = None
32
34
35
+ @dataclass
36
+ class File :
37
+ path : str
38
+ operation : HandleFileOperation
39
+
33
40
class ProgressEvents :
34
41
def __init__ (self ):
35
42
self ._phase : ProgressPhase = ProgressPhase .READY
@@ -38,7 +45,7 @@ def __init__(self):
38
45
self ._handing_file : HandingFile | None = None
39
46
self ._error : str | None = None
40
47
self ._interruption_status : InterruptionStatus = InterruptionStatus .No
41
- self ._completed_files : list [str ] = []
48
+ self ._completed_files : list [File ] = []
42
49
self ._fetcher_lock : Lock = Lock ()
43
50
self ._fetcher_queues : list [Queue [dict ]] = []
44
51
@@ -69,10 +76,11 @@ def _init_events(self) -> list[dict]:
69
76
"kind" : "scanCompleted" ,
70
77
"count" : self ._updated_files ,
71
78
})
72
- for path in self ._completed_files :
79
+ for file in self ._completed_files :
73
80
events .append ({
74
81
"kind" : "completeHandingFile" ,
75
- "path" : path ,
82
+ "path" : file .path ,
83
+ "operation" : file .operation .value ,
76
84
})
77
85
if self ._phase == ProgressPhase .COMPLETED :
78
86
events .append ({ "kind" : "completed" })
@@ -82,6 +90,7 @@ def _init_events(self) -> list[dict]:
82
90
events .append ({
83
91
"kind" : "startHandingFile" ,
84
92
"path" : self ._handing_file .path ,
93
+ "operation" : self ._handing_file .operation .value ,
85
94
})
86
95
if self ._handing_file .pdf_handing is not None :
87
96
index , total = self ._handing_file .pdf_handing
@@ -114,7 +123,7 @@ def receive_event(self, event: ProgressEvent):
114
123
if isinstance (event , ScanCompletedEvent ):
115
124
self ._on_scan_completed (event .updated_files )
116
125
elif isinstance (event , StartHandleFileEvent ):
117
- self ._on_start_handle_file (event .path )
126
+ self ._on_start_handle_file (event .path , event . operation )
118
127
elif isinstance (event , CompleteHandleFileEvent ):
119
128
self ._on_complete_handle_file (event .path )
120
129
elif isinstance (event , PDFFileProgressEvent ):
@@ -133,25 +142,35 @@ def _on_scan_completed(self, updated_files: int):
133
142
"count" : updated_files ,
134
143
})
135
144
136
- def _on_start_handle_file (self , path : str ):
145
+ def _on_start_handle_file (self , path : str , operation : HandleFileOperation ):
137
146
with self ._status_lock :
138
- self ._handing_file = HandingFile (path = path )
139
-
147
+ self ._handing_file = HandingFile (
148
+ path = path ,
149
+ operation = operation ,
150
+ )
140
151
self ._emit_event ({
141
152
"kind" : "startHandingFile" ,
142
153
"path" : path ,
154
+ "operation" : operation .value ,
143
155
})
144
156
145
157
def _on_complete_handle_file (self , path : str ):
158
+ file : File | None = None
146
159
with self ._status_lock :
147
- self ._completed_files .append (path )
148
160
if self ._handing_file is not None and self ._handing_file .path == path :
161
+ file = File (
162
+ path = path ,
163
+ operation = self ._handing_file .operation ,
164
+ )
165
+ self ._completed_files .append (file )
149
166
self ._handing_file = None
150
167
151
- self ._emit_event ({
152
- "kind" : "completeHandingFile" ,
153
- "path" : path ,
154
- })
168
+ if file is not None :
169
+ self ._emit_event ({
170
+ "kind" : "completeHandingFile" ,
171
+ "path" : file .path ,
172
+ "operation" : file .operation .value ,
173
+ })
155
174
156
175
def _on_pdf_parse_progress (self , page_index : int , total_pages : int ):
157
176
with self ._status_lock :
0 commit comments