[buildroot] drop the usr/ prefix when scanning for libgcc.a
[openwrt.git] / scripts / dl_cleanup.py
index 41f172d..67ccbda 100755 (executable)
@@ -11,8 +11,6 @@ import os
 import re
 import getopt
 
 import re
 import getopt
 
-DEBUG = 0
-
 # Commandline options
 opt_dryrun = False
 
 # Commandline options
 opt_dryrun = False
 
@@ -27,7 +25,10 @@ def parseVer_1234(match):
 
 def parseVer_123(match):
        progname = match.group(1)
 
 def parseVer_123(match):
        progname = match.group(1)
-       patchlevel = match.group(5)
+       try:
+               patchlevel = match.group(5)
+       except (IndexError), e:
+               patchlevel = None
        if patchlevel:
                patchlevel = ord(patchlevel[0])
        else:
        if patchlevel:
                patchlevel = ord(patchlevel[0])
        else:
@@ -40,7 +41,10 @@ def parseVer_123(match):
 
 def parseVer_12(match):
        progname = match.group(1)
 
 def parseVer_12(match):
        progname = match.group(1)
-       patchlevel = match.group(4)
+       try:
+               patchlevel = match.group(4)
+       except (IndexError), e:
+               patchlevel = None
        if patchlevel:
                patchlevel = ord(patchlevel[0])
        else:
        if patchlevel:
                patchlevel = ord(patchlevel[0])
        else:
@@ -76,18 +80,20 @@ versionRegex = (
        (re.compile(r"(.+)[-_](\d+)\.(\d+)\.(\d+)\.(\d+)"), parseVer_1234),     # xxx-1.2.3.4
        (re.compile(r"(.+)[-_](\d\d\d\d)-?(\d\d)-?(\d\d)"), parseVer_ymd),      # xxx-YYYY-MM-DD
        (re.compile(r"(.+)[-_](\d+)\.(\d+)\.(\d+)(\w?)"), parseVer_123),        # xxx-1.2.3a
        (re.compile(r"(.+)[-_](\d+)\.(\d+)\.(\d+)\.(\d+)"), parseVer_1234),     # xxx-1.2.3.4
        (re.compile(r"(.+)[-_](\d\d\d\d)-?(\d\d)-?(\d\d)"), parseVer_ymd),      # xxx-YYYY-MM-DD
        (re.compile(r"(.+)[-_](\d+)\.(\d+)\.(\d+)(\w?)"), parseVer_123),        # xxx-1.2.3a
+       (re.compile(r"(.+)[-_](\d+)_(\d+)_(\d+)"), parseVer_123),               # xxx-1_2_3
        (re.compile(r"(.+)[-_](\d+)\.(\d+)(\w?)"), parseVer_12),                # xxx-1.2a
        (re.compile(r"(.+)[-_]r?(\d+)"), parseVer_r),                           # xxx-r1111
 )
 
        (re.compile(r"(.+)[-_](\d+)\.(\d+)(\w?)"), parseVer_12),                # xxx-1.2a
        (re.compile(r"(.+)[-_]r?(\d+)"), parseVer_r),                           # xxx-r1111
 )
 
-blacklist = (
-       re.compile(r"wl_apsta.*"),
-       re.compile(r"boost.*"),
-       re.compile(r".*\.fw"),
-       re.compile(r".*\.arm"),
-       re.compile(r".*\.bin"),
-       re.compile(r"RT\d+_Firmware.*"),
-)
+blacklist = [
+       ("linux",               re.compile(r"linux-.*")),
+       ("gcc",                 re.compile(r"gcc-.*")),
+       ("wl_apsta",            re.compile(r"wl_apsta.*")),
+       (".fw",                 re.compile(r".*\.fw")),
+       (".arm",                re.compile(r".*\.arm")),
+       (".bin",                re.compile(r".*\.bin")),
+       ("rt-firmware",         re.compile(r"RT[\d\w]+_Firmware.*")),
+]
 
 class EntryParseError(Exception): pass
 
 
 class EntryParseError(Exception): pass
 
@@ -102,8 +108,7 @@ class Entry:
                                filename = filename[0:0-len(ext)]
                                break
                else:
                                filename = filename[0:0-len(ext)]
                                break
                else:
-                       if DEBUG:
-                               print "Extension did not match on", filename
+                       print self.filename, "has an unknown file-extension"
                        raise EntryParseError("ext")
                for (regex, parseVersion) in versionRegex:
                        match = regex.match(filename)
                        raise EntryParseError("ext")
                for (regex, parseVersion) in versionRegex:
                        match = regex.match(filename)
@@ -111,8 +116,7 @@ class Entry:
                                (self.progname, self.version) = parseVersion(match)
                                break
                else:
                                (self.progname, self.version) = parseVersion(match)
                                break
                else:
-                       if DEBUG:
-                               print "Version regex did not match on", filename
+                       print self.filename, "has an unknown version pattern"
                        raise EntryParseError("ver")
 
        def deleteFile(self):
                        raise EntryParseError("ver")
 
        def deleteFile(self):
@@ -132,16 +136,19 @@ def usage():
        print "Usage: " + sys.argv[0] + " [OPTIONS] <path/to/dl>"
        print ""
        print " -d|--dry-run            Do a dry-run. Don't delete any files"
        print "Usage: " + sys.argv[0] + " [OPTIONS] <path/to/dl>"
        print ""
        print " -d|--dry-run            Do a dry-run. Don't delete any files"
+       print " -B|--show-blacklist     Show the blacklist and exit"
+       print " -w|--whitelist ITEM     Remove ITEM from blacklist"
 
 def main(argv):
        global opt_dryrun
 
        try:
                (opts, args) = getopt.getopt(argv[1:],
 
 def main(argv):
        global opt_dryrun
 
        try:
                (opts, args) = getopt.getopt(argv[1:],
-                       "hd",
-                       [ "help", "dry-run", ])
+                       "hdBw:",
+                       [ "help", "dry-run", "show-blacklist", "whitelist=", ])
                if len(args) != 1:
                if len(args) != 1:
-                       raise getopt.GetoptError()
+                       usage()
+                       return 1
        except getopt.GetoptError:
                usage()
                return 1
        except getopt.GetoptError:
                usage()
                return 1
@@ -152,14 +159,28 @@ def main(argv):
                        return 0
                if o in ("-d", "--dry-run"):
                        opt_dryrun = True
                        return 0
                if o in ("-d", "--dry-run"):
                        opt_dryrun = True
+               if o in ("-w", "--whitelist"):
+                       for i in range(0, len(blacklist)):
+                               (name, regex) = blacklist[i]
+                               if name == v:
+                                       del blacklist[i]
+                                       break
+                       else:
+                               print "Whitelist error: Item", v,\
+                                     "is not in blacklist"
+                               return 1
+               if o in ("-B", "--show-blacklist"):
+                       for (name, regex) in blacklist:
+                               print name
+                       return 0
 
        # Create a directory listing and parse the file names.
        entries = []
        for filename in os.listdir(directory):
                if filename == "." or filename == "..":
                        continue
 
        # Create a directory listing and parse the file names.
        entries = []
        for filename in os.listdir(directory):
                if filename == "." or filename == "..":
                        continue
-               for black in blacklist:
-                       if black.match(filename):
+               for (name, regex) in blacklist:
+                       if regex.match(filename):
                                if opt_dryrun:
                                        print filename, "is blacklisted"
                                break
                                if opt_dryrun:
                                        print filename, "is blacklisted"
                                break
This page took 0.027506 seconds and 4 git commands to generate.