From a9eaa27bcc0422cf2cc1be7f76831faa2545668c Mon Sep 17 00:00:00 2001
From: Aleksey Lim <alsroot@member.fsf.org>
Date: Tue, 22 Sep 2009 01:37:39 +0000
Subject: Progress bar for reading volumes nevers stops if can't read all volume entries #1412
---
src/jarabe/journal/model.py | 79 +++++++++++++++++++++++++------------------
1 files changed, 46 insertions(+), 33 deletions(-)
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index f452a7f..03dbd5c 100644
a
|
b
|
class InplaceResultSet(BaseResultSet): |
258 | 258 | |
259 | 259 | def setup(self): |
260 | 260 | self._file_list = [] |
| 261 | self._pending_directories = 1 |
261 | 262 | self._recurse_dir(self._mount_point) |
262 | 263 | |
263 | 264 | def stop(self): |
… |
… |
class InplaceResultSet(BaseResultSet): |
293 | 294 | return entries, total_count |
294 | 295 | |
295 | 296 | def _recurse_dir(self, dir_path): |
296 | | if self._stopped: |
297 | | return |
| 297 | try: |
| 298 | if self._stopped: |
| 299 | return |
298 | 300 | |
299 | | for entry in os.listdir(dir_path): |
300 | | if entry.startswith('.'): |
301 | | continue |
302 | | full_path = dir_path + '/' + entry |
303 | 301 | try: |
304 | | stat = os.stat(full_path) |
305 | | if S_IFMT(stat.st_mode) == S_IFDIR: |
306 | | self._pending_directories += 1 |
307 | | gobject.idle_add(lambda s=full_path: self._recurse_dir(s)) |
| 302 | dirs = os.listdir(dir_path) |
| 303 | except Exception: |
| 304 | logging.exception('Error reading directory %r', dir_path) |
| 305 | dirs = [] |
| 306 | |
| 307 | for entry in dirs: |
| 308 | if entry.startswith('.'): |
| 309 | continue |
| 310 | full_path = os.path.join(dir_path, entry) |
| 311 | try: |
| 312 | self._append_file(full_path) |
| 313 | except Exception: |
| 314 | logging.exception('Error reading file %r', full_path) |
| 315 | |
| 316 | finally: |
| 317 | self._pending_directories -= 1 |
| 318 | if self._pending_directories == 0: |
| 319 | self.setup_ready() |
308 | 320 | |
309 | | elif S_IFMT(stat.st_mode) == S_IFREG: |
310 | | add_to_list = True |
| 321 | def _append_file(self, full_path): |
| 322 | stat = os.stat(full_path) |
311 | 323 | |
312 | | if self._regex is not None and \ |
313 | | not self._regex.match(full_path): |
314 | | add_to_list = False |
| 324 | if S_IFMT(stat.st_mode) == S_IFDIR: |
| 325 | self._pending_directories += 1 |
| 326 | gobject.idle_add( |
| 327 | lambda s=full_path: self._recurse_dir(s)) |
315 | 328 | |
316 | | if None not in [self._date_start, self._date_end] and \ |
317 | | (stat.st_mtime < self._date_start or |
318 | | stat.st_mtime > self._date_end): |
319 | | add_to_list = False |
| 329 | elif S_IFMT(stat.st_mode) == S_IFREG: |
| 330 | add_to_list = True |
320 | 331 | |
321 | | if self._mime_types: |
322 | | mime_type = gio.content_type_guess(filename=full_path) |
323 | | if mime_type not in self._mime_types: |
324 | | add_to_list = False |
| 332 | if self._regex is not None and \ |
| 333 | not self._regex.match(full_path): |
| 334 | add_to_list = False |
325 | 335 | |
326 | | if add_to_list: |
327 | | file_info = (full_path, stat, int(stat.st_mtime)) |
328 | | self._file_list.append(file_info) |
| 336 | if None not in [self._date_start, self._date_end] and \ |
| 337 | (stat.st_mtime < self._date_start or |
| 338 | stat.st_mtime > self._date_end): |
| 339 | add_to_list = False |
329 | 340 | |
330 | | self.progress.send(self) |
| 341 | if self._mime_types: |
| 342 | mime_type = gio.content_type_guess( |
| 343 | filename=full_path) |
| 344 | if mime_type not in self._mime_types: |
| 345 | add_to_list = False |
331 | 346 | |
332 | | except Exception: |
333 | | logging.exception('Error reading file %r', full_path) |
| 347 | if add_to_list: |
| 348 | file_info = (full_path, stat, int(stat.st_mtime)) |
| 349 | self._file_list.append(file_info) |
334 | 350 | |
335 | | if self._pending_directories == 0: |
336 | | self.setup_ready() |
337 | | else: |
338 | | self._pending_directories -= 1 |
| 351 | self.progress.send(self) |
339 | 352 | |
340 | 353 | def _get_file_metadata(path, stat): |
341 | 354 | client = gconf.client_get_default() |