vortex-cli 8.2.0__py3-none-any.whl → 8.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vortex/cli.py +245 -3
- vortex/commands/file.py +573 -0
- vortex/commands/info.py +2 -0
- vortex/commands/log.py +384 -12
- vortex/commands/stats.py +247 -0
- vortex/commands/weblog.py +387 -0
- vortex/main.py +32 -0
- vortex/models.py +36 -1
- vortex/registry.py +7 -0
- vortex/webdesign.py +337 -9
- {vortex_cli-8.2.0.dist-info → vortex_cli-8.3.0.dist-info}/METADATA +210 -7
- {vortex_cli-8.2.0.dist-info → vortex_cli-8.3.0.dist-info}/RECORD +16 -13
- {vortex_cli-8.2.0.dist-info → vortex_cli-8.3.0.dist-info}/WHEEL +0 -0
- {vortex_cli-8.2.0.dist-info → vortex_cli-8.3.0.dist-info}/entry_points.txt +0 -0
- {vortex_cli-8.2.0.dist-info → vortex_cli-8.3.0.dist-info}/licenses/LICENSE +0 -0
- {vortex_cli-8.2.0.dist-info → vortex_cli-8.3.0.dist-info}/top_level.txt +0 -0
vortex/cli.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import functools
|
|
4
|
+
import re
|
|
4
5
|
from argparse import ArgumentParser
|
|
5
6
|
from argparse import ArgumentTypeError
|
|
6
7
|
from argparse import Namespace
|
|
@@ -8,6 +9,9 @@ from argparse import RawDescriptionHelpFormatter
|
|
|
8
9
|
from argparse import _ArgumentGroup
|
|
9
10
|
from argparse import _MutuallyExclusiveGroup
|
|
10
11
|
from argparse import _SubParsersAction
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from datetime import time
|
|
14
|
+
from datetime import timedelta
|
|
11
15
|
from pathlib import Path
|
|
12
16
|
from typing import NamedTuple
|
|
13
17
|
|
|
@@ -119,6 +123,73 @@ def _check_int_in_range(val: str, min_: int = 1, max_: int | None = 50) -> int:
|
|
|
119
123
|
return new_val
|
|
120
124
|
|
|
121
125
|
|
|
126
|
+
_DURATION_PART_RE = re.compile(r"(\d+)([smhdw])")
|
|
127
|
+
_DURATION_UNITS = {"s": 1, "m": 60, "h": 3600, "d": 86400, "w": 604800}
|
|
128
|
+
# 520 weeks (10 years): past any log, and the window's start still reads
|
|
129
|
+
# right as the gateway's two-digit yy/MM/dd (and timedelta can't overflow)
|
|
130
|
+
_MAX_DURATION_SECONDS = 520 * 604800
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _duration(val: str) -> timedelta:
|
|
134
|
+
"""'vortex log --since': 90s, 30m, 2h, 3d, 1w or a run of them (1h30m)."""
|
|
135
|
+
text = val.strip().lower()
|
|
136
|
+
parts = _DURATION_PART_RE.findall(text)
|
|
137
|
+
if not parts or "".join(n + u for n, u in parts) != text:
|
|
138
|
+
raise ArgumentTypeError(
|
|
139
|
+
f"invalid duration '{val}': expected e.g. 30m, 2h, 3d or 1h30m"
|
|
140
|
+
)
|
|
141
|
+
seconds = sum(int(n) * _DURATION_UNITS[u] for n, u in parts)
|
|
142
|
+
if seconds <= 0:
|
|
143
|
+
raise ArgumentTypeError(f"invalid duration '{val}': must be more than 0")
|
|
144
|
+
if seconds > _MAX_DURATION_SECONDS:
|
|
145
|
+
raise ArgumentTypeError(
|
|
146
|
+
f"invalid duration '{val}': at most {_MAX_DURATION_SECONDS // 604800}w"
|
|
147
|
+
)
|
|
148
|
+
return timedelta(seconds=seconds)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
_LOG_DAY_RE = re.compile(r"\d{4}-\d{2}-\d{2}")
|
|
152
|
+
_LOG_CLOCK_RE = re.compile(r"(\d{1,2})(:\d{2}(?::\d{2})?)([Zz]|[+-]\d{2}:\d{2})?")
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _log_time(val: str, end_of_day: bool = False) -> datetime | time:
|
|
156
|
+
"""
|
|
157
|
+
'vortex log --from/--to': HH:MM[:SS] (a time today), YYYY-MM-DD, or
|
|
158
|
+
YYYY-MM-DD[ |T]HH:MM[:SS] - all on the server's clock - or a date and
|
|
159
|
+
time with an offset (Z, +10:00) for an exact instant. A time alone
|
|
160
|
+
takes no offset: which day "today" is depends on the zone. A date
|
|
161
|
+
alone is the start of that day, or with end_of_day (--to) its last
|
|
162
|
+
second.
|
|
163
|
+
"""
|
|
164
|
+
text = val.strip()
|
|
165
|
+
day: str | None = None
|
|
166
|
+
if _LOG_DAY_RE.match(text) and text[10:11] in ("", " ", "T", "t"):
|
|
167
|
+
day, text = text[:10], text[11:]
|
|
168
|
+
clock = _LOG_CLOCK_RE.fullmatch(text)
|
|
169
|
+
try:
|
|
170
|
+
if day is not None and not text:
|
|
171
|
+
start = datetime.fromisoformat(day)
|
|
172
|
+
if end_of_day:
|
|
173
|
+
return start.replace(hour=23, minute=59, second=59)
|
|
174
|
+
return start
|
|
175
|
+
if clock and day is None and not clock.group(3):
|
|
176
|
+
return time.fromisoformat(f"{int(clock.group(1)):02d}{clock.group(2)}")
|
|
177
|
+
if clock and day is not None:
|
|
178
|
+
hour, rest, offset = clock.groups()
|
|
179
|
+
offset = "+00:00" if offset in ("Z", "z") else offset or ""
|
|
180
|
+
return datetime.fromisoformat(f"{day} {int(hour):02d}{rest}{offset}")
|
|
181
|
+
except ValueError:
|
|
182
|
+
pass
|
|
183
|
+
if clock and day is None and clock.group(3):
|
|
184
|
+
raise ArgumentTypeError(
|
|
185
|
+
f"invalid time '{val}': an offset needs a date, e.g. 2026-10-14T02:00Z"
|
|
186
|
+
)
|
|
187
|
+
raise ArgumentTypeError(
|
|
188
|
+
f"invalid time '{val}': expected e.g. 02:00, 2026-10-14, "
|
|
189
|
+
"'2026-10-14 02:00' or 2026-10-14T02:00+10:00"
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
122
193
|
def _app_id(val: str) -> int:
|
|
123
194
|
"""A numeric application (or object) ID - every gateway route takes one."""
|
|
124
195
|
if not val.isdigit() or int(val) <= 0:
|
|
@@ -502,23 +573,81 @@ def add_clean_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
|
|
|
502
573
|
|
|
503
574
|
def add_log_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
|
|
504
575
|
log_parser = command_parser.add_parser(
|
|
505
|
-
"log",
|
|
576
|
+
"log",
|
|
577
|
+
help="View the last items in the server log",
|
|
578
|
+
description=(
|
|
579
|
+
"The newest entries in the server log (PMALOG), optionally within a "
|
|
580
|
+
"time window. Times are the server's clock - the clock the entries "
|
|
581
|
+
"are printed in. Without --since/--from/--to the gateway reads only "
|
|
582
|
+
"the last 24 hours; --to alone reads the 24 hours before it."
|
|
583
|
+
),
|
|
506
584
|
)
|
|
507
585
|
log_parser.add_argument(
|
|
508
586
|
"--limit",
|
|
509
587
|
"-n",
|
|
510
|
-
type=_check_int_in_range,
|
|
511
|
-
help=
|
|
588
|
+
type=functools.partial(_check_int_in_range, max_=500),
|
|
589
|
+
help=(
|
|
590
|
+
"The number of logs to return, or per page with --page/--all-pages "
|
|
591
|
+
"(max 500). Default is %(default)s"
|
|
592
|
+
),
|
|
512
593
|
default=10,
|
|
513
594
|
)
|
|
514
595
|
log_parser.add_argument("--source", help="Filter the logs returned by their source")
|
|
515
596
|
log_parser.add_argument(
|
|
516
597
|
"--message", "-m", help="Filter the logs returned by their message"
|
|
517
598
|
)
|
|
599
|
+
log_parser.add_argument(
|
|
600
|
+
"--search",
|
|
601
|
+
metavar="TEXT",
|
|
602
|
+
help="Only entries whose message, user or server name contains TEXT",
|
|
603
|
+
)
|
|
518
604
|
log_type_mutex = log_parser.add_mutually_exclusive_group()
|
|
519
605
|
log_type_mutex.add_argument("--errors-only", action="store_true")
|
|
520
606
|
log_type_mutex.add_argument("--debug-only", action="store_true")
|
|
521
607
|
log_type_mutex.add_argument("--info-only", action="store_true")
|
|
608
|
+
|
|
609
|
+
window = log_parser.add_mutually_exclusive_group()
|
|
610
|
+
window.add_argument(
|
|
611
|
+
"--since",
|
|
612
|
+
type=_duration,
|
|
613
|
+
metavar="DURATION",
|
|
614
|
+
help="Only entries from the last DURATION, e.g. 30m, 2h, 3d",
|
|
615
|
+
)
|
|
616
|
+
window.add_argument(
|
|
617
|
+
"--from",
|
|
618
|
+
dest="date_from",
|
|
619
|
+
type=_log_time,
|
|
620
|
+
metavar="WHEN",
|
|
621
|
+
help=(
|
|
622
|
+
"Only entries from WHEN: 02:00 (today), 2026-10-14, "
|
|
623
|
+
"'2026-10-14 02:00', or ISO with an offset"
|
|
624
|
+
),
|
|
625
|
+
)
|
|
626
|
+
log_parser.add_argument(
|
|
627
|
+
"--to",
|
|
628
|
+
dest="date_to",
|
|
629
|
+
type=functools.partial(_log_time, end_of_day=True),
|
|
630
|
+
metavar="WHEN",
|
|
631
|
+
help=(
|
|
632
|
+
"Only entries up to WHEN (inclusive; a date alone is the whole day). "
|
|
633
|
+
"Without --since/--from: the 24 hours before WHEN"
|
|
634
|
+
),
|
|
635
|
+
)
|
|
636
|
+
paging = log_parser.add_mutually_exclusive_group()
|
|
637
|
+
paging.add_argument(
|
|
638
|
+
"--page",
|
|
639
|
+
type=functools.partial(_check_int_in_range, max_=None),
|
|
640
|
+
metavar="N",
|
|
641
|
+
help="Page N of -n entries, newest first (needs the gateway)",
|
|
642
|
+
)
|
|
643
|
+
paging.add_argument(
|
|
644
|
+
"--all-pages",
|
|
645
|
+
action="store_true",
|
|
646
|
+
help=(
|
|
647
|
+
"Every page of -n entries, one request each, up to 20 pages "
|
|
648
|
+
"(needs the gateway)"
|
|
649
|
+
),
|
|
650
|
+
)
|
|
522
651
|
log_parser.add_argument("--keep-alive", "-k", action="store_true")
|
|
523
652
|
|
|
524
653
|
_positive_int = functools.partial(_check_int_in_range, min_=1)
|
|
@@ -537,6 +666,119 @@ def add_log_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
|
|
|
537
666
|
_add_json_option(log_parser)
|
|
538
667
|
|
|
539
668
|
|
|
669
|
+
def add_weblog_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
|
|
670
|
+
weblog_parser = command_parser.add_parser(
|
|
671
|
+
"weblog",
|
|
672
|
+
help="View the server's HTTP access log (needs the gateway)",
|
|
673
|
+
description=(
|
|
674
|
+
"The server's HTTP access log (HTTPTextLog) through the gateway, "
|
|
675
|
+
"printed as the server wrote it. Needs GatewaySystem."
|
|
676
|
+
),
|
|
677
|
+
)
|
|
678
|
+
weblog_parser.add_argument(
|
|
679
|
+
"--limit",
|
|
680
|
+
"-n",
|
|
681
|
+
type=functools.partial(_check_int_in_range, min_=0, max_=None),
|
|
682
|
+
help=(
|
|
683
|
+
"The number of lines to show - as many as fit in the 256 KB the "
|
|
684
|
+
"gateway returns (0 with --keep-alive: only new lines). "
|
|
685
|
+
"Default is %(default)s"
|
|
686
|
+
),
|
|
687
|
+
default=20,
|
|
688
|
+
)
|
|
689
|
+
weblog_parser.add_argument(
|
|
690
|
+
"--match",
|
|
691
|
+
"-m",
|
|
692
|
+
metavar="TEXT",
|
|
693
|
+
help="Only lines containing TEXT (case-insensitive), filtered client side",
|
|
694
|
+
)
|
|
695
|
+
weblog_parser.add_argument(
|
|
696
|
+
"--regex",
|
|
697
|
+
action="store_true",
|
|
698
|
+
help="Treat --match as a Python regular expression (case-sensitive)",
|
|
699
|
+
)
|
|
700
|
+
weblog_parser.add_argument(
|
|
701
|
+
"--file",
|
|
702
|
+
metavar="NAME",
|
|
703
|
+
help="An older log file (see --list) instead of the current one",
|
|
704
|
+
)
|
|
705
|
+
mode = weblog_parser.add_mutually_exclusive_group()
|
|
706
|
+
mode.add_argument("--list", action="store_true", help="List the web log files")
|
|
707
|
+
mode.add_argument(
|
|
708
|
+
"--all",
|
|
709
|
+
action="store_true",
|
|
710
|
+
help="The whole file, read in pieces, instead of its last lines",
|
|
711
|
+
)
|
|
712
|
+
mode.add_argument(
|
|
713
|
+
"--output",
|
|
714
|
+
"-o",
|
|
715
|
+
type=Path,
|
|
716
|
+
metavar="PATH",
|
|
717
|
+
help="Save the whole file (after --match) to PATH - implies --all",
|
|
718
|
+
)
|
|
719
|
+
mode.add_argument(
|
|
720
|
+
"--keep-alive",
|
|
721
|
+
"-k",
|
|
722
|
+
action="store_true",
|
|
723
|
+
help="Keep printing new lines as they are written",
|
|
724
|
+
)
|
|
725
|
+
weblog_parser.add_argument(
|
|
726
|
+
"--delay",
|
|
727
|
+
"-d",
|
|
728
|
+
type=functools.partial(_check_int_in_range, min_=1),
|
|
729
|
+
help=(
|
|
730
|
+
"Used only with --keep-alive. "
|
|
731
|
+
"The number of seconds between requests for new lines. Default is %(default)s"
|
|
732
|
+
),
|
|
733
|
+
default=3,
|
|
734
|
+
metavar="SECONDS",
|
|
735
|
+
)
|
|
736
|
+
_add_server_option(weblog_parser)
|
|
737
|
+
_add_json_option(weblog_parser)
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
def add_stats_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
|
|
741
|
+
stats_parser = command_parser.add_parser(
|
|
742
|
+
"stats",
|
|
743
|
+
help="View the server's addin statistics (needs the gateway)",
|
|
744
|
+
description=(
|
|
745
|
+
"Each loaded addin's statistics (CPU, memory, threads, errors, "
|
|
746
|
+
"logins, HTTP traffic, ...) through the gateway: the value now and "
|
|
747
|
+
"the min/avg/max over the periods the server holds in memory. "
|
|
748
|
+
"Needs GatewaySystem."
|
|
749
|
+
),
|
|
750
|
+
)
|
|
751
|
+
stats_parser.add_argument(
|
|
752
|
+
"--addin",
|
|
753
|
+
metavar="NAME",
|
|
754
|
+
help="Only this addin: a short name like HTTP or STATS, or the class name",
|
|
755
|
+
)
|
|
756
|
+
stats_parser.add_argument(
|
|
757
|
+
"--key",
|
|
758
|
+
metavar="KEY",
|
|
759
|
+
help="Only this statistic, e.g. stats.cpuusageperminute",
|
|
760
|
+
)
|
|
761
|
+
stats_parser.add_argument(
|
|
762
|
+
"--keep-alive",
|
|
763
|
+
"-k",
|
|
764
|
+
action="store_true",
|
|
765
|
+
help="Keep polling and reprinting the statistics",
|
|
766
|
+
)
|
|
767
|
+
stats_parser.add_argument(
|
|
768
|
+
"--delay",
|
|
769
|
+
"-d",
|
|
770
|
+
type=functools.partial(_check_int_in_range, min_=1),
|
|
771
|
+
help=(
|
|
772
|
+
"Used only with --keep-alive. "
|
|
773
|
+
"The number of seconds between polls. Default is %(default)s"
|
|
774
|
+
),
|
|
775
|
+
default=5,
|
|
776
|
+
metavar="SECONDS",
|
|
777
|
+
)
|
|
778
|
+
_add_server_option(stats_parser)
|
|
779
|
+
_add_json_option(stats_parser)
|
|
780
|
+
|
|
781
|
+
|
|
540
782
|
def add_docs_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
|
|
541
783
|
docs_parser = command_parser.add_parser(
|
|
542
784
|
"docs", help="Open the Tornado Server Blackbook"
|