Bug #199311 - Make dblink.getcontents() show the path of the
authorZac Medico <zmedico@gentoo.org>
Wed, 21 Nov 2007 00:02:53 +0000 (00:02 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 21 Nov 2007 00:02:53 +0000 (00:02 -0000)
CONTENTS file when any kind of parse error occurs.
(trunk r8511)

svn path=/main/branches/2.1.2/; revision=8563

pym/portage.py

index e25c856781198fffd2645d40960f7bdf37b238fb..8bdb1548e06192dbdff8dbc7f1eb2f4bd3782e64 100644 (file)
@@ -7574,13 +7574,11 @@ class dblink:
                if myroot == os.path.sep:
                        myroot = None
                pos = 0
-               for line in mylines:
-                       pos += 1
+               errors = []
+               for pos, line in enumerate(mylines):
                        if null_byte in line:
                                # Null bytes are a common indication of corruption.
-                               writemsg("!!! Null byte found in contents " + \
-                                       "file, line %d: '%s'\n" % (pos, contents_file),
-                                       noiselevel=-1)
+                               errors.append((pos + 1, "Null byte found in CONTENTS entry"))
                                continue
                        line = line.rstrip("\n")
                        # Split on " " so that even file paths that
@@ -7597,8 +7595,7 @@ class dblink:
                                        try:
                                                splitter = mydat.index("->", 2, len(mydat) - 2)
                                        except ValueError:
-                                               writemsg("!!! Unrecognized CONTENTS entry on " + \
-                                                       "line %d: '%s'\n" % (pos, line), noiselevel=-1)
+                                               errors.append((pos + 1, "Unrecognized CONTENTS entry"))
                                                continue
                                        spaces_in_path = splitter - 2
                                        spaces_in_target = spaces_total - spaces_in_path
@@ -7638,11 +7635,13 @@ class dblink:
                                        #format: type
                                        pkgfiles[mydat[1]] = [mydat[0]]
                                else:
-                                       writemsg("!!! Unrecognized CONTENTS entry on " + \
-                                               "line %d: '%s'\n" % (pos, line), noiselevel=-1)
+                                       errors.append((pos + 1, "Unrecognized CONTENTS entry"))
                        except (KeyError, IndexError):
-                               writemsg("!!! Unrecognized CONTENTS entry on " + \
-                                       "line %d: '%s'\n" % (pos, line), noiselevel=-1)
+                               errors.append((pos + 1, "Unrecognized CONTENTS entry"))
+               if errors:
+                       writemsg("!!! Parse error in '%s'\n" % contents_file, noiselevel=-1)
+                       for pos, e in errors:
+                               writemsg("!!!   line %d: %s\n" % (pos, e), noiselevel=-1)
                self.contentscache = pkgfiles
                return pkgfiles