dl_cleanup: Add dry-run option
SVN-Revision: 19081
This commit is contained in:
parent
8ed8fe14b2
commit
4a2465a295
1 changed files with 26 additions and 6 deletions
|
@ -9,9 +9,13 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import getopt
|
||||||
|
|
||||||
DEBUG = 0
|
DEBUG = 0
|
||||||
|
|
||||||
|
# Commandline options
|
||||||
|
opt_dryrun = False
|
||||||
|
|
||||||
|
|
||||||
def parseVer_1234(match):
|
def parseVer_1234(match):
|
||||||
progname = match.group(1)
|
progname = match.group(1)
|
||||||
|
@ -114,7 +118,7 @@ class Entry:
|
||||||
def deleteFile(self):
|
def deleteFile(self):
|
||||||
path = (self.directory + "/" + self.filename).replace("//", "/")
|
path = (self.directory + "/" + self.filename).replace("//", "/")
|
||||||
print "Deleting", path
|
print "Deleting", path
|
||||||
if not DEBUG:
|
if not opt_dryrun:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|
||||||
def __eq__(self, y):
|
def __eq__(self, y):
|
||||||
|
@ -125,13 +129,29 @@ class Entry:
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print "OpenWRT download directory cleanup utility"
|
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):
|
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()
|
usage()
|
||||||
return 1
|
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.
|
# Create a directory listing and parse the file names.
|
||||||
entries = []
|
entries = []
|
||||||
|
@ -140,7 +160,7 @@ def main(argv):
|
||||||
continue
|
continue
|
||||||
for black in blacklist:
|
for black in blacklist:
|
||||||
if black.match(filename):
|
if black.match(filename):
|
||||||
if DEBUG:
|
if opt_dryrun:
|
||||||
print filename, "is blacklisted"
|
print filename, "is blacklisted"
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -167,7 +187,7 @@ def main(argv):
|
||||||
for version in versions:
|
for version in versions:
|
||||||
if version != lastVersion:
|
if version != lastVersion:
|
||||||
version.deleteFile()
|
version.deleteFile()
|
||||||
if DEBUG:
|
if opt_dryrun:
|
||||||
print "Keeping", lastVersion.filename
|
print "Keeping", lastVersion.filename
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue