Port the EbuildNestedDie check from trunk since the
authorZac Medico <zmedico@gentoo.org>
Mon, 5 Nov 2007 06:50:39 +0000 (06:50 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 5 Nov 2007 06:50:39 +0000 (06:50 -0000)
python version is much faster than the old one that
uses grep.

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

bin/repoman

index d1445d3d5264143e4275046c6588ac5b27e7ffa6..149dd172931c25e474e4eee483a2f1186d8f6e6f 100755 (executable)
@@ -818,6 +818,24 @@ class EbuildQuote(object):
                                break
                return errors
 
+class EbuildNestedDie(object):
+       """Check ebuild for nested die statements (die statements in subshells"""
+
+       repoman_check_name = 'ebuild.nesteddie'
+       nesteddie_re = re.compile(r'^[^#]*\([^)]*\bdie\b')
+
+       def __init__(self, contents):
+               self.contents = contents
+
+       def Run(self):
+               errors = []
+               for num, line in enumerate(self.contents):
+                       match = self.nesteddie_re.match(line)
+                       if match:
+                               errors.append((num + 1,
+                                       'Ebuild calls die in a subshell on line: %d'))
+               return errors
+
 class EbuildUselessDodoc(object):
        """Check ebuild for useless files in dodoc arguments."""
        repoman_check_name = 'ebuild.minorsyn'
@@ -1403,10 +1421,6 @@ for x in scanlist:
                                stats["usage.obsolete"] += 1
                                fails["usage.obsolete"].append("%s/%s.ebuild: not migrated to modular X" % (x, y))
 
-               # this check needs work, it won't catch (\ndie)
-               if not os.system("egrep '^[^#]*\([^)]*\<die\>' "+checkdir+"/"+y+".ebuild >/dev/null 2>&1"):
-                       stats["ebuild.nesteddie"]=stats["ebuild.nesteddie"]+1
-                       fails["ebuild.nesteddie"].append(x+"/"+y+".ebuild")
                # uselist checks - global
                myuse = []
                default_use = []
@@ -1493,6 +1507,13 @@ for x in scanlist:
                                stats[c.repoman_check_name] += 1
                                fails[c.repoman_check_name].append(x + '/' + y + '.ebuild: %s' % e[1] % e[0])
                del check
+               check = EbuildNestedDie(contents)
+               errors = check.Run()
+               for e in errors:
+                       stats[check.repoman_check_name] += 1
+                       fails[check.repoman_check_name].append(
+                               x + '/' + y + '.ebuild: %s' % e[1] % e[0])
+               del check
 
                gentoo_copyright = re.compile(r'^# Copyright ((1999|200\d)-)?' + str(myear) + r' Gentoo Foundation')
                gentoo_license = re.compile(r'^# Distributed under the terms of the GNU General Public License v2$')