aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Hjortshoej <fyoucon@gmail.com>2020-04-19 21:38:59 +0200
committerMikkel Hjortshoej <fyoucon@gmail.com>2020-04-19 21:38:59 +0200
commit8eda24f2d180a89905f45f8ae4bf6c29e0c18ae6 (patch)
tree80752179cdb3fd23104df86521bb61131b8bc59b
parent3dac1c34fa963d6a4828f36a2b6f1d6fc3722d8b (diff)
Actually include script to delete binaries
-rw-r--r--ci/delete_old_binaries.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/ci/delete_old_binaries.py b/ci/delete_old_binaries.py
new file mode 100644
index 000000000..206d849f5
--- /dev/null
+++ b/ci/delete_old_binaries.py
@@ -0,0 +1,34 @@
+import subprocess
+import sys
+import json
+import datetime
+import urllib.parse
+import sys
+
+def main():
+ files_by_date = {}
+ bucket = sys.argv[1]
+ days_to_keep = int(sys.argv[2])
+ print(f"Looking for binaries to delete older than {days_to_keep} days")
+
+ files_lines = execute_cli(f"b2 ls --long --versions {bucket} nightly").split("\n")
+ for x in files_lines:
+ parts = [y for y in x.split(' ') if y]
+
+ if parts and parts[0]:
+ date = datetime.datetime.strptime(parts[2], '%Y-%m-%d').replace(hour=0, minute=0, second=0, microsecond=0)
+ now = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
+ delta = now - date
+
+ if delta.days > days_to_keep:
+ print(f'Deleting {parts[5]}')
+ execute_cli(f'b2 delete-file-version {parts[0]}')
+
+
+def execute_cli(command):
+ sb = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
+ return sb.stdout.read().decode("utf-8");
+
+if __name__ == '__main__':
+ sys.exit(main())
+