|
| 1 | +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
| 2 | +# vi: set ft=python sts=4 ts=4 sw=4 et: |
| 3 | +# |
| 4 | +# Copyright 2024 The NiPreps Developers <nipreps@gmail.com> |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +# We support and encourage derived works from this project, please read |
| 19 | +# about our expectations at |
| 20 | +# |
| 21 | +# https://www.nipreps.org/community/licensing/ |
| 22 | +# |
| 23 | +"""Update references to telemetry charts on the landing page.""" |
| 24 | + |
| 25 | +import re |
| 26 | +from pathlib import Path |
| 27 | + |
| 28 | + |
| 29 | +ASSETS_DIR = Path(__file__).parent.parent / "docs" / "assets" |
| 30 | +INDEX_FILE = Path(__file__).parent.parent / "docs" / "index.md" |
| 31 | + |
| 32 | +WEEKLY_RE = re.compile(r"assets/\d{8}_weekly.png") |
| 33 | +VERSIONSTREAM_RE = re.compile(r"assets/\d{8}_versionstream.png") |
| 34 | + |
| 35 | + |
| 36 | +def _latest(pattern: str) -> str | None: |
| 37 | + files = sorted(ASSETS_DIR.glob(pattern)) |
| 38 | + return files[-1].name if files else None |
| 39 | + |
| 40 | + |
| 41 | +def main(argv=None): # noqa: D401 |
| 42 | + """Update the links in the index page to the newest telemetry charts.""" |
| 43 | + weekly_file = _latest("*_weekly.png") |
| 44 | + version_file = _latest("*_versionstream.png") |
| 45 | + |
| 46 | + if not weekly_file or not version_file: |
| 47 | + return |
| 48 | + |
| 49 | + text = INDEX_FILE.read_text() |
| 50 | + text = WEEKLY_RE.sub(f"assets/{weekly_file}", text) |
| 51 | + text = VERSIONSTREAM_RE.sub(f"assets/{version_file}", text) |
| 52 | + INDEX_FILE.write_text(text) |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + main() |
0 commit comments