From 02417974e952f0c26e1a1c24ec42204be22bc1a2 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 27 May 2007 02:10:23 +0000 Subject: In the WorldHandler class, add support for an onProgress callback that can be used notify the user of job progress. This isn't really useful for WorldHandler since it completes quickly, but it will be useful for longer running tasks. svn path=/main/trunk/; revision=6637 --- bin/emaint | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/emaint b/bin/emaint index d91734833..0e9ba853d 100755 --- a/bin/emaint +++ b/bin/emaint @@ -27,13 +27,20 @@ class WorldHandler(object): self.world_file = os.path.join("/", portage.const.WORLD_FILE) self.found = os.access(self.world_file, os.R_OK) + def _check_world(self, onProgress): categories = set(portage.settings.categories) myroot = portage.settings["ROOT"] vardb = portage.db[myroot]["vartree"].dbapi - for atom in open(self.world_file).read().split(): + world_atoms = open(self.world_file).read().split() + maxval = len(world_atoms) + if onProgress: + onProgress(maxval, 0) + for i, atom in enumerate(world_atoms): if not portage.isvalidatom(atom): self.invalid.append(atom) + if onProgress: + onProgress(maxval, i+1) continue okay = True if not vardb.match(atom): @@ -44,8 +51,11 @@ class WorldHandler(object): okay = False if okay: self.okay.append(atom) + if onProgress: + onProgress(maxval, i+1) - def check(self): + def check(self, onProgress=None): + self._check_world(onProgress) errors = [] if self.found: errors += map(lambda x: "'%s' is not a valid atom" % x, self.invalid) @@ -55,7 +65,8 @@ class WorldHandler(object): errors.append(self.world_file + " could not be opened for reading") return errors - def fix(self): + def fix(self, onProgress=None): + self._check_world(onProgress) errors = [] try: portage.write_atomic(self.world_file, "\n".join(self.okay)) -- cgit v1.2.3-1-g7c22