summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authormb <mb@3c298f89-4303-0410-b956-a3cf2f4a3e73>2010-01-09 18:06:54 +0000
committermb <mb@3c298f89-4303-0410-b956-a3cf2f4a3e73>2010-01-09 18:06:54 +0000
commit631583226f8a7d0b8e8995caa853b0bef3bea116 (patch)
tree22e53fab51a95e9f0dc43156483fcec7ce8d6b70 /scripts
parent08fa74f3bdfc369c8836d27631d62e4fb3a9f519 (diff)
dl_cleanup: Add dry-run option
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@19081 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dl_cleanup.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/scripts/dl_cleanup.py b/scripts/dl_cleanup.py
index e83c82ac2..41f172de5 100755
--- a/scripts/dl_cleanup.py
+++ b/scripts/dl_cleanup.py
@@ -9,9 +9,13 @@
import sys
import os
import re
+import getopt
DEBUG = 0
+# Commandline options
+opt_dryrun = False
+
def parseVer_1234(match):
progname = match.group(1)
@@ -114,7 +118,7 @@ class Entry:
def deleteFile(self):
path = (self.directory + "/" + self.filename).replace("//", "/")
print "Deleting", path
- if not DEBUG:
+ if not opt_dryrun:
os.unlink(path)
def __eq__(self, y):
@@ -125,13 +129,29 @@ class Entry:
def usage():
print "OpenWRT download directory cleanup utility"
- print "Usage: " + sys.argv[0] + " path/to/dl"
+ print "Usage: " + sys.argv[0] + " [OPTIONS] <path/to/dl>"
+ print ""
+ print " -d|--dry-run Do a dry-run. Don't delete any files"
def main(argv):
- if len(argv) != 2:
+ global opt_dryrun
+
+ try:
+ (opts, args) = getopt.getopt(argv[1:],
+ "hd",
+ [ "help", "dry-run", ])
+ if len(args) != 1:
+ raise getopt.GetoptError()
+ except getopt.GetoptError:
usage()
return 1
- directory = argv[1]
+ directory = args[0]
+ for (o, v) in opts:
+ if o in ("-h", "--help"):
+ usage()
+ return 0
+ if o in ("-d", "--dry-run"):
+ opt_dryrun = True
# Create a directory listing and parse the file names.
entries = []
@@ -140,7 +160,7 @@ def main(argv):
continue
for black in blacklist:
if black.match(filename):
- if DEBUG:
+ if opt_dryrun:
print filename, "is blacklisted"
break
else:
@@ -167,7 +187,7 @@ def main(argv):
for version in versions:
if version != lastVersion:
version.deleteFile()
- if DEBUG:
+ if opt_dryrun:
print "Keeping", lastVersion.filename
return 0