Menu

[r10232]: / trunk / tools / clean_builds.py  Maximize  Restore  History

Download this file

56 lines (39 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3.2
"""
Simple script for pruning old builds.
Garrett Cooper, February 2012
"""
import argparse
import os
import sys
import time
# Seconds in a day.
DAY = 24 * 3600
def rm_old_dirs(rootdir, expire_time=(30 * DAY)):
"""Nuke everything under '''rootdir''' older than '''expire_time'''.
"""
os.chdir(rootdir)
expiration_date = time.time() - expire_time
for dirname in \
filter(lambda e: os.path.isdir(e) and os.stat(e).st_ctime < expiration_date,
os.listdir('.')):
print('Removing %s' % (dirname, ))
for root, dirs, files, in os.walk(dirname, topdown=False):
for f in files:
os.unlink(os.path.join(root, f))
os.rmdir(dirname)
def main(argv):
"""main"""
parser = argparse.ArgumentParser()
parser.add_argument('-e', '--expire-date',
type=int,
default=30,
help='number of days before builds expire',
)
args, dirs = parser.parse_known_args()
if not dirs:
parser.error('you must specify one or more directories')
for buildroot in dirs:
rm_old_dirs(buildroot, expire_time=(args.expire_date * DAY))
if __name__ == '__main__':
main(sys.argv[1:])
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.