From c0f31381e40bb752910aab1f61275952550d64f6 Mon Sep 17 00:00:00 2001 From: Ave Date: Fri, 31 Jul 2020 23:13:24 +0300 Subject: [PATCH] Add cleanartifacts script to ctcci Closes #75 --- ctcci/cleanartifacts.py | 25 +++++++++++++++++++++++++ ctcci/ctcconfig.example.py | 3 +++ 2 files changed, 28 insertions(+) create mode 100644 ctcci/cleanartifacts.py diff --git a/ctcci/cleanartifacts.py b/ctcci/cleanartifacts.py new file mode 100644 index 0000000..173859e --- /dev/null +++ b/ctcci/cleanartifacts.py @@ -0,0 +1,25 @@ +import os +from ctcconfig import * + +verdata = {} + +# Get all APKs from the dir +for file in os.listdir(RESULT_FOLDER): + if not file.startswith("cutthecord-"): + continue + + filedata = file.replace("cutthecord-", "").replace(".apk", "").split("-") + if filedata[1] not in verdata: + verdata[filedata[1]] = [] + + verdata[filedata[1]].append(int(filedata[0])) + +# Delete the older APKs +for branch in verdata: + vers = verdata[branch] + vers.sort() + if len(vers) <= CLEAN_ARTIFACT_KEEP_COUNT: + continue + for ver in vers[0:-1 * CLEAN_ARTIFACT_KEEP_COUNT]: + file = os.path.join(RESULT_FOLDER, f"cutthecord-{branch}-{ver}.apk") + os.unlink(file) diff --git a/ctcci/ctcconfig.example.py b/ctcci/ctcconfig.example.py index bc2e998..7f9a9ad 100644 --- a/ctcci/ctcconfig.example.py +++ b/ctcci/ctcconfig.example.py @@ -74,3 +74,6 @@ FONTS = {"ellie": {"whitney_bold.ttf": "/home/ave/fonts/GoogleSans-Bold.ttf", "whitney_medium.ttf": "/home/ave/fonts/comic.ttf"}, "ave": {"sourcecodepro_semibold.ttf": "/home/ave/fonts/comic.ttf"}, "default": {}} + +# Amount of last builds cleanartifacts.py should keep +CLEAN_ARTIFACT_KEEP_COUNT = 2