Skip to content

Commit 3abb5d3

Browse files
committed
Version bump v2.0.0-beta.17
+ Show progress while scanning files
1 parent 72d7827 commit 3abb5d3

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

codeintel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.0-beta.16'
1+
__version__ = '2.0.0-beta.17'

codeintel/codeintel2/database/langlibbase.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def ensure_all_dirs_scanned(self, ctlr=None):
6161
len(dirs))
6262
except:
6363
pass # eat any errors about reporting progress
64-
self.ensure_dir_scanned(dir, ctlr=ctlr, reporter=lambda msg: None)
64+
self.ensure_dir_scanned(dir, ctlr=ctlr)
6565
scanned.add(dir)
6666
finally:
6767
# report that we have stopped scanning
@@ -79,20 +79,27 @@ def ensure_dir_scanned(self, dir, ctlr=None, reporter=None):
7979
if dir not in self._have_ensured_scanned_from_dir_cache:
8080
if reporter is None:
8181
reporter = self.lang_zone.db.event_reporter
82-
if not callable(reporter):
83-
reporter = None
8482
res_index = self.lang_zone.load_index(dir, "res_index", {})
8583
importables = self._importables_from_dir(dir)
8684
importable_values = [i[0] for i in importables.values()
8785
if i[0] is not None]
86+
removed_values = set(res_index.keys()).difference(importable_values)
87+
current = 0
88+
total = len(importable_values) + len(removed_values)
8889
for base in importable_values:
8990
if ctlr and ctlr.is_aborted():
9091
log.debug("ctlr aborted")
9192
return
93+
current += 1
9294
if base not in res_index:
93-
if reporter:
94-
reporter("scanning %s files in '%s'" % (self.lang, dir))
95-
reporter = None # don't report again
95+
if reporter and hasattr(reporter, "onScanFile"):
96+
try:
97+
reporter.onScanFile("Scanning %s file '%s'" % (self.lang, join(dir, base)),
98+
dir,
99+
current,
100+
total)
101+
except:
102+
pass # eat any errors about reporting progress
96103
try:
97104
buf = self.mgr.buf_from_path(join(dir, base),
98105
lang=self.lang)
@@ -106,14 +113,19 @@ def ensure_dir_scanned(self, dir, ctlr=None, reporter=None):
106113
buf.scan_if_necessary()
107114

108115
# Remove scanned paths that don't exist anymore.
109-
removed_values = set(res_index.keys()).difference(importable_values)
110116
for base in removed_values:
111117
if ctlr and ctlr.is_aborted():
112118
log.debug("ctlr aborted")
113119
return
114-
if reporter:
115-
reporter("scanning %s files in '%s'" % (self.lang, dir))
116-
reporter = None # don't report again
120+
current += 1
121+
if reporter and hasattr(reporter, "onScanFile"):
122+
try:
123+
reporter.onScanFile("Scanning %s file '%s'" % (self.lang, join(dir, base)),
124+
dir,
125+
current,
126+
total)
127+
except:
128+
pass # eat any errors about reporting progress
117129
basename = join(dir, base)
118130
self.lang_zone.remove_path(basename)
119131

codeintel/codeintel2/oop/driver.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,23 @@ def onScanDirectory(self, description, dir_path, current=None, total=None):
239239
completed=len(self._completed_dirs),
240240
total=len(self._dirs))
241241

242+
def onScanFile(self, description, file_path, current=None, total=None):
243+
"""Called when a directory is being scanned (out of possibly many)
244+
@param description {unicode} A string suitable for showing the user
245+
regarding the progress
246+
@param dir {unicode} The directory currently being scanned
247+
@param current {int} The current progress
248+
@param total {int} The total number of directories to scan in this
249+
request
250+
"""
251+
self.debug("scan file: %s (%s %s/%s)",
252+
description, file_path, current, total)
253+
254+
assert file_path, "onScanDirectory got no directory"
255+
self.send(type="scan-progress", message=description,
256+
completed=current,
257+
total=total)
258+
242259
def onScanComplete(self, dirs=set(), scanned=set()):
243260
"""Called when a scan operation is complete
244261
@param dirs {set of unicode} The directories that were intially

0 commit comments

Comments
 (0)