diff options
author | Christian Tismer <tismer@stackless.com> | 2020-07-11 13:59:05 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2020-07-14 16:34:54 +0200 |
commit | 96df55f9fdc7406971baba18a622ea8f947ec916 (patch) | |
tree | 69533859dc97e609cf4a76efd4adf4a478c70a3c /testing | |
parent | 907c23751b66468471d08dfd4d175e55348f1a58 (diff) |
testing: Automate pruning of old history entries
The always growing list of invalid directory entries
in the history will get pruned to only keep the latest
days entries.
Change-Id: Ie104ca9874f985f0040950f650390798f45fc6d5
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'testing')
-rw-r--r-- | testing/buildlog.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/testing/buildlog.py b/testing/buildlog.py index 0cea8c934..47815d6d5 100644 --- a/testing/buildlog.py +++ b/testing/buildlog.py @@ -49,6 +49,7 @@ BuildLog.classifiers finds the set of classifier strings. import os import sys +import shutil from collections import namedtuple from textwrap import dedent @@ -74,7 +75,6 @@ class BuildLog(object): continue fpath = os.path.join(log_dir, 'build_dir.txt') if not os.path.exists(fpath): - print("Warning: %s not found, skipped" % fpath) continue with open(fpath) as f: f_contents = f.read().strip() @@ -109,6 +109,31 @@ class BuildLog(object): build_history.sort() self.history = build_history self._buildno = None + self.prune_old_entries(history_dir) + + def prune_old_entries(self, history_dir): + lst = [] + for timestamp in os.listdir(history_dir): + log_dir = os.path.join(history_dir, timestamp) + if not os.path.isdir(log_dir): + continue + lst.append(log_dir) + if lst: + def warn_problem(func, path, exc_info): + cls, ins, tb = exc_info + print("rmtree({}) warning: problem with {}:\n {}: {}".format( + func.__name__, path, + cls.__name__, ins.args)) + + lst.sort() + log_dir = lst[-1] + fname = os.path.basename(log_dir) + ref_date_str = fname[:10] + for log_dir in lst: + fname = os.path.basename(log_dir) + date_str = fname[:10] + if date_str != ref_date_str: + shutil.rmtree(log_dir, onerror=warn_problem) def set_buildno(self, buildno): self.history[buildno] # test |