| 1 |
#!/usr/bin/env python3 |
| 2 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 3 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
"""cylc tui [WORKFLOW] |
| 19 |
|
| 20 |
View and control running workflows in the terminal. |
| 21 |
|
| 22 |
(Tui = Terminal User Interface) |
| 23 |
|
| 24 |
Tui allows you to monitor and interact with workflows in a manner similar |
| 25 |
to the GUI. |
| 26 |
|
| 27 |
Press "h" whilst running Tui to bring up the help screen, use the arrow |
| 28 |
keys to navigate. |
| 29 |
|
| 30 |
""" |
| 31 |
|
| 32 |
from getpass import getuser |
| 33 |
from textwrap import indent |
| 34 |
from typing import TYPE_CHECKING, Optional |
| 35 |
|
| 36 |
from cylc.flow.id import Tokens |
| 37 |
from cylc.flow.id_cli import parse_id |
| 38 |
from cylc.flow.option_parsers import ( |
| 39 |
OPT_WORKFLOW_ID_ARG_DOC, |
| 40 |
CylcOptionParser as COP, |
| 41 |
) |
| 42 |
from cylc.flow.terminal import cli_function |
| 43 |
from cylc.flow.tui import TUI |
| 44 |
from cylc.flow.tui.util import suppress_logging |
| 45 |
from cylc.flow.tui.app import ( |
| 46 |
TuiApp, |
| 47 |
) |
| 48 |
|
| 49 |
if TYPE_CHECKING: |
| 50 |
from optparse import Values |
| 51 |
|
| 52 |
|
| 53 |
__doc__ += indent(TUI, ' ') |
| 54 |
|
| 55 |
|
| 56 |
def get_option_parser() -> COP: |
| 57 |
parser = COP( |
| 58 |
__doc__, |
| 59 |
argdoc=[OPT_WORKFLOW_ID_ARG_DOC], |
| 60 |
# auto_add=False, NOTE: at present auto_add can not be turned off |
| 61 |
color=False |
| 62 |
) |
| 63 |
|
| 64 |
parser.add_option( |
| 65 |
'--comms-timeout', |
| 66 |
metavar='SEC', |
| 67 |
help=( |
| 68 |
# NOTE: Tui overrides the default client timeout |
| 69 |
"Set the timeout for communication with the running workflow." |
| 70 |
" The default is 5 seconds, you may need to increase this in" |
| 71 |
" order for Tui to keep up with especially busy workflows." |
| 72 |
), |
| 73 |
action='store', |
| 74 |
default=5, |
| 75 |
dest='comms_timeout', |
| 76 |
type=int, |
| 77 |
) |
| 78 |
|
| 79 |
return parser |
| 80 |
|
| 81 |
|
| 82 |
@cli_function(get_option_parser) |
| 83 |
def main(_, options: 'Values', workflow_id: Optional[str] = None) -> None: |
| 84 |
# get workflow ID if specified |
| 85 |
if workflow_id: |
| 86 |
workflow_id, *_ = parse_id( |
| 87 |
workflow_id, |
| 88 |
constraint='workflows', |
| 89 |
) |
| 90 |
tokens = Tokens(workflow_id) |
| 91 |
workflow_id = tokens.duplicate(user=getuser()).id |
| 92 |
|
| 93 |
# start Tui |
| 94 |
with suppress_logging(), TuiApp().main( |
| 95 |
workflow_id, |
| 96 |
client_timeout=options.comms_timeout, |
| 97 |
): |
| 98 |
# tui stops according to user input |
| 99 |
pass |