X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/948d8682662f6ecbf93a1a8a8cf28e11679bbba3..df5dee93df2a481490c260c5378c72725aef43e3:/scripts/dl_cleanup.py diff --git a/scripts/dl_cleanup.py b/scripts/dl_cleanup.py index ff38a158f..67ccbda91 100755 --- a/scripts/dl_cleanup.py +++ b/scripts/dl_cleanup.py @@ -11,8 +11,6 @@ import os import re import getopt -DEBUG = 0 - # Commandline options opt_dryrun = False @@ -27,7 +25,10 @@ def parseVer_1234(match): 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: @@ -40,7 +41,10 @@ def parseVer_123(match): 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: @@ -76,6 +80,7 @@ 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+)"), 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 ) @@ -83,12 +88,11 @@ versionRegex = ( blacklist = [ ("linux", re.compile(r"linux-.*")), ("gcc", re.compile(r"gcc-.*")), - ("boost", re.compile(r"boost.*")), ("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+_Firmware.*")), + ("rt-firmware", re.compile(r"RT[\d\w]+_Firmware.*")), ] class EntryParseError(Exception): pass @@ -104,8 +108,7 @@ class Entry: 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) @@ -113,8 +116,7 @@ class Entry: (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): @@ -145,7 +147,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