In the WorldHandler class, add support for an onProgress callback that can be used...
authorZac Medico <zmedico@gentoo.org>
Sun, 27 May 2007 02:10:23 +0000 (02:10 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 27 May 2007 02:10:23 +0000 (02:10 -0000)
svn path=/main/trunk/; revision=6637

bin/emaint

index d917348330a1238842f9dcf9a7ff6ae219514f64..0e9ba853d8f770d037935886065b84e45eda92c3 100755 (executable)
@@ -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))