diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2015-11-29 15:13:11 -0800 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2015-11-29 15:13:11 -0800 |
commit | a88756a60a04f469139077268338c10af29e85df (patch) | |
tree | f7462e6ee33af2f9fa7ac0191f1a21190e309469 /clean-old-deltas.py | |
download | mastermirror-scripts-a88756a60a04f469139077268338c10af29e85df.tar.gz mastermirror-scripts-a88756a60a04f469139077268338c10af29e85df.tar.bz2 mastermirror-scripts-a88756a60a04f469139077268338c10af29e85df.zip |
Initial commit.
Copied from git+ssh://git@git.gentoo.org/infra/cfengine.git repo as:
timestamp 2015-11-29T21:57:00Z
commit 3b63da8fbbb848d5a1f7e7cd7c6989638ed0d817
No passwords, passphrases or key material is contained herein, but it
may reference the pathes to such.
Reviewed-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'clean-old-deltas.py')
-rwxr-xr-x | clean-old-deltas.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/clean-old-deltas.py b/clean-old-deltas.py new file mode 100755 index 0000000..5f7e6b6 --- /dev/null +++ b/clean-old-deltas.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +import os,sys +if len(sys.argv) != 4: + print "need 3 args, first being directory to scan, second being latest, third being it's size" + sys.exit(1) + +path=sys.argv[1] +maxsize=long(sys.argv[3]) +if len(sys.argv[2]) != 8: + print "date arg must be YYYYMMDD" + sys.exit(1) +root = sys.argv[2] + +if not hasattr(__builtins__, "set"): + from sets import Set as set +file_list = [x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))] +pref_name="snapshot-" +post_name=".patch.bz2" +deltas = [x for x in file_list if x.startswith(pref_name) and x.endswith(post_name)] +chains={} +for x in deltas: + try: + start, end = x[len(pref_name):-len(post_name)].split("-") + except ValueError: + continue + if end in chains: + print "warning, end %s already exists; this is a bit weird" % end + continue + chains[end] = start + +save_files = set() +node = root +count = 0 +while node in chains: + s="%s%s-%s%s" % (pref_name, chains[node], node, post_name) + count += os.stat(os.path.join(path, s)).st_size + if count > maxsize: + break + save_files.update([s, s+".md5sum", s+".gpgsig"]) + node = chains[node] + +for x in file_list: + if x not in save_files: + print "nuking %s" % x + try: + os.unlink(os.path.join(path,x)) + except OSError, oe: + print "failed removing %s cause of %s" % (os.path.join(path, x), str(oe)) |