-
Notifications
You must be signed in to change notification settings - Fork 9
/
purge_old_ci_builds.py
executable file
·68 lines (59 loc) · 1.93 KB
/
purge_old_ci_builds.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# vim: ts=4:sw=4:expandtab
# Copyright (C) 2016 by Andrew Ziem. All rights reserved.
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.
#
#
"""
Windows builds are frequently and automatically published to
ci.bleachbit.org. This script helps purge the older builds.
"""
import subprocess
args = ['s3cmd', 'ls', 's3://bleachbitci/dl/']
ls_raw = subprocess.check_output(args)
ls_lines = ls_raw.decode().split('\n')
# get relevant directories
dirs = []
for line in ls_lines:
if '' == ls_lines:
break
line_s = line.split()
if not len(line_s) == 2:
break
if line_s[0] != 'DIR':
break
dirs.append(line_s[1])
# sort by version number,keep newest first
def key_ver(path):
"""Convert an S3 path into a StrictVersion for sorting"""
ver_str = path.split('/')[4]
from pkg_resources import parse_version
try:
ret = parse_version(ver_str)
except ValueError:
print('Not a recognizable version:', ver_str)
ret = ver_str
return ret
dirs.sort(key=key_ver, reverse=True)
# Keep the newest builds.
keep_newest_n = 5
print('Keeping the following {} newest directories:'.format(keep_newest_n))
for d in dirs[:keep_newest_n]:
print (' ', d)
print()
# Delete the older builds.
if len(dirs) > keep_newest_n:
print('Issue the following command to perform the delete')
print()
# s3cmd 1.6.1 does not support multiple paths to delete at once
# Support was added in its Git repository November 2016.
# For now, issue separate commands.
#delete_dirs = ' '.join(dirs[keep_newest_n:])
#delete_cmd = 's3cmd del -r {}'.format(delete_dirs)
# print(delete_cmd)
for delete_dir in dirs[keep_newest_n:]:
print('s3cmd del -r {}'.format(delete_dir))
else:
print('nothing to delete')