diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/condprofile/condprof/changelog.py | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/condprofile/condprof/changelog.py')
-rw-r--r-- | testing/condprofile/condprof/changelog.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/condprofile/condprof/changelog.py b/testing/condprofile/condprof/changelog.py new file mode 100644 index 0000000000..72c8e7e8ea --- /dev/null +++ b/testing/condprofile/condprof/changelog.py @@ -0,0 +1,56 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This module needs to stay Python 2 and 3 compatible +# +""" +Maintains a unique file that lists all artifacts operations. +""" +import json +import os +import sys +from datetime import datetime + + +# XXX we should do one per platform and use platform-changelog.json as a name +class Changelog: + def __init__(self, archives_dir): + self.archives_dir = archives_dir + self.location = os.path.join(archives_dir, "changelog.json") + if os.path.exists(self.location): + with open(self.location) as f: + self._data = json.loads(f.read()) + if "changes" not in self._data: + self._data["changes"] = [] + else: + self._data = {"changes": []} + + def append(self, action, platform=sys.platform, **metadata): + now = datetime.timestamp(datetime.now()) + log = {"action": action, "platform": platform, "when": now} + log.update(metadata) + # adding taskcluster specific info if we see it in the env + for key in ( + "TC_SCHEDULER_ID", + "TASK_ID", + "TC_OWNER", + "TC_SOURCE", + "TC_PROJECT", + ): + if key in os.environ: + log[key] = os.environ[key] + self._data["changes"].append(log) + + def save(self, archives_dir=None): + if archives_dir is not None and archives_dir != self.archives_dir: + self.location = os.path.join(archives_dir, "changelog.json") + # we need to resolve potential r/w conflicts on TC here + with open(self.location, "w") as f: + f.write(json.dumps(self._data)) + + def history(self): + """From older to newer""" + return sorted( + self._data["changes"], key=lambda entry: entry["when"], reverse=True + ) |