| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
"""Shared utilities for Cylc scripts.""" |
| 18 |
|
| 19 |
from itertools import zip_longest |
| 20 |
from ansimarkup import strip |
| 21 |
|
| 22 |
from cylc.flow import __version__ |
| 23 |
from cylc.flow.scripts import _copyright_year |
| 24 |
from cylc.flow.terminal import get_width |
| 25 |
|
| 26 |
# fmt: off |
| 27 |
CYLC_LOGO = [ |
| 28 |
" <yellow>▪</yellow> <blue>■ </blue>", |
| 29 |
" <green>██</green> ", |
| 30 |
"<red>▝▘</red> ", |
| 31 |
] |
| 32 |
# fmt: on |
| 33 |
|
| 34 |
CYLC = ( |
| 35 |
"<b>" |
| 36 |
"<red>C</red>" |
| 37 |
"<yellow>y</yellow>" |
| 38 |
"<green>l</green>" |
| 39 |
"<blue>c</blue>" |
| 40 |
"</b>" |
| 41 |
) |
| 42 |
|
| 43 |
VERSION = f"<b><yellow>{__version__}</yellow></b>" |
| 44 |
|
| 45 |
LICENSE = [ |
| 46 |
f"{CYLC} Workflow Engine {VERSION}", |
| 47 |
f"Copyright (C) 2008-{_copyright_year} NIWA", |
| 48 |
"& British Crown (Met Office) & Contributors" |
| 49 |
] |
| 50 |
|
| 51 |
|
| 52 |
def cylc_header(width=None): |
| 53 |
"""Print copyright and license information.""" |
| 54 |
width = width or get_width() |
| 55 |
lmax = ( |
| 56 |
max(len(strip(line)) for line in LICENSE) + |
| 57 |
len(strip(CYLC_LOGO[0])) |
| 58 |
) |
| 59 |
if width >= lmax + 1: |
| 60 |
header = '\n'.join( |
| 61 |
('{0} {1}').format(*x) |
| 62 |
for x in zip_longest( |
| 63 |
CYLC_LOGO, |
| 64 |
LICENSE |
| 65 |
) |
| 66 |
) |
| 67 |
else: |
| 68 |
header = '\n'.join(CYLC_LOGO) + '\n' + '\n'.join(LICENSE) |
| 69 |
return f"\n{header}\n" |