[brcm63xx] Remove patch 140-new_bcm96348gw_leds because it is really the GW6200 leds...
[openwrt.git] / scripts / dl_cleanup.py
index 7adc475..81c69f7 100755 (executable)
@@ -11,13 +11,11 @@ import os
 import re
 import getopt
 
-DEBUG = 0
-
 # Commandline options
 opt_dryrun = False
 
 
-def parseVer_1234(match):
+def parseVer_1234(match, filepath):
        progname = match.group(1)
        progversion = (int(match.group(2)) << 64) |\
                      (int(match.group(3)) << 48) |\
@@ -25,7 +23,7 @@ def parseVer_1234(match):
                      (int(match.group(5)) << 16)
        return (progname, progversion)
 
-def parseVer_123(match):
+def parseVer_123(match, filepath):
        progname = match.group(1)
        try:
                patchlevel = match.group(5)
@@ -41,7 +39,7 @@ def parseVer_123(match):
                      patchlevel
        return (progname, progversion)
 
-def parseVer_12(match):
+def parseVer_12(match, filepath):
        progname = match.group(1)
        try:
                patchlevel = match.group(4)
@@ -56,18 +54,24 @@ def parseVer_12(match):
                      patchlevel
        return (progname, progversion)
 
-def parseVer_r(match):
+def parseVer_r(match, filepath):
        progname = match.group(1)
        progversion = (int(match.group(2)) << 64)
        return (progname, progversion)
 
-def parseVer_ymd(match):
+def parseVer_ymd(match, filepath):
        progname = match.group(1)
        progversion = (int(match.group(2)) << 64) |\
                      (int(match.group(3)) << 48) |\
                      (int(match.group(4)) << 32)
        return (progname, progversion)
 
+def parseVer_GIT(match, filepath):
+       progname = match.group(1)
+       st = os.stat(filepath)
+       progversion = int(st.st_mtime) << 64
+       return (progname, progversion)
+
 extensions = (
        ".tar.gz",
        ".tar.bz2",
@@ -79,6 +83,7 @@ extensions = (
 )
 
 versionRegex = (
+       (re.compile(r"(.+)[-_]([0-9a-fA-F]{40,40})"), parseVer_GIT),            # xxx-GIT_SHASUM
        (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
@@ -94,7 +99,7 @@ blacklist = [
        (".fw",                 re.compile(r".*\.fw")),
        (".arm",                re.compile(r".*\.arm")),
        (".bin",                re.compile(r".*\.bin")),
-       ("rt-firmware",         re.compile(r"RT\d+_Firmware.*")),
+       ("rt-firmware",         re.compile(r"RT[\d\w]+_Firmware.*")),
 ]
 
 class EntryParseError(Exception): pass
@@ -104,23 +109,24 @@ class Entry:
                self.directory = directory
                self.filename = filename
                self.progname = ""
+               self.fileext = ""
 
                for ext in extensions:
                        if filename.endswith(ext):
                                filename = filename[0:0-len(ext)]
+                               self.fileext = 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)
                        if match:
-                               (self.progname, self.version) = parseVersion(match)
+                               (self.progname, self.version) = parseVersion(
+                                       match, directory + "/" + filename + self.fileext)
                                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):
@@ -151,7 +157,8 @@ def main(argv):
                        "hdBw:",
                        [ "help", "dry-run", "show-blacklist", "whitelist=", ])
                if len(args) != 1:
-                       raise getopt.GetoptError()
+                       usage()
+                       return 1
        except getopt.GetoptError:
                usage()
                return 1
This page took 0.022013 seconds and 4 git commands to generate.