esgpull 0.9.2__py3-none-any.whl → 0.9.4__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.
esgpull/cli/__init__.py CHANGED
@@ -8,7 +8,7 @@ from esgpull.cli.add import add
8
8
  from esgpull.cli.config import config
9
9
  from esgpull.cli.convert import convert
10
10
  from esgpull.cli.download import download
11
- from esgpull.cli.login import login
11
+ from esgpull.cli.index_nodes import index_nodes
12
12
  from esgpull.cli.plugins import plugins
13
13
  from esgpull.cli.remove import remove
14
14
  from esgpull.cli.retry import retry
@@ -40,7 +40,6 @@ SUBCOMMANDS: list[click.Command] = [
40
40
  # get,
41
41
  self,
42
42
  # install,
43
- login,
44
43
  plugins,
45
44
  remove,
46
45
  retry,
@@ -51,6 +50,7 @@ SUBCOMMANDS: list[click.Command] = [
51
50
  status,
52
51
  # # stats,
53
52
  update,
53
+ index_nodes,
54
54
  ]
55
55
 
56
56
  CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
@@ -0,0 +1,94 @@
1
+ from __future__ import annotations
2
+
3
+ from collections import OrderedDict
4
+
5
+ import click
6
+ from click.exceptions import Abort, Exit
7
+
8
+ from esgpull import Context
9
+ from esgpull.cli.decorators import groups, opts
10
+ from esgpull.cli.utils import init_esgpull, totable
11
+ from esgpull.models import Query
12
+ from esgpull.tui import Verbosity, logger
13
+
14
+
15
+ def check_node(c: Context, node: str) -> bool:
16
+ try:
17
+ c.probe(index_node=node)
18
+ return True
19
+ except:
20
+ return False
21
+
22
+
23
+ def find_nodes(c: Context, node: str) -> list[str]:
24
+ try:
25
+ hints = c.hints(
26
+ Query(), file=False, index_node=node, facets=["index_node"]
27
+ )
28
+ return list(hints[0]["index_node"])
29
+ except:
30
+ return []
31
+
32
+
33
+ @click.command()
34
+ @groups.json_yaml
35
+ @opts.record
36
+ @opts.verbosity
37
+ def index_nodes(
38
+ ## json_yaml
39
+ json: bool,
40
+ yaml: bool,
41
+ record: bool,
42
+ verbosity: Verbosity,
43
+ ) -> None:
44
+ """
45
+ Test index nodes for their current status
46
+ """
47
+ esg = init_esgpull(
48
+ verbosity,
49
+ safe=False,
50
+ record=record,
51
+ )
52
+ with esg.ui.logging("scan", onraise=Abort):
53
+ node_status: dict[str, bool] = {}
54
+ nodes = [
55
+ "esgf-node.ipsl.upmc.fr",
56
+ "esgf-data.dkrz.de",
57
+ "esgf.ceda.ac.uk",
58
+ "esgf-node.ornl.gov/esgf-1-5-bridge",
59
+ ]
60
+
61
+ esg.config.api.http_timeout = 3
62
+ with esg.ui.spinner("Fetching index nodes status"):
63
+ while True:
64
+ if not nodes:
65
+ break
66
+ node = nodes.pop()
67
+ if node in node_status:
68
+ continue
69
+ logger.info(f"check: {node}")
70
+ node_status[node] = check_node(esg.context, node)
71
+ logger.info(f"{node}\tok: {node_status[node]}")
72
+ for node in find_nodes(esg.context, node):
73
+ if node not in node_status:
74
+ nodes.append(node)
75
+ logger.info(f"found index_node: {node}")
76
+ if json:
77
+ esg.ui.print(node_status, json=True)
78
+ elif yaml:
79
+ esg.ui.print(node_status, yaml=True)
80
+ else:
81
+ table = [
82
+ OrderedDict(
83
+ [
84
+ ("node", node),
85
+ (
86
+ "status",
87
+ "[green]OK" if status else "[red]no response",
88
+ ),
89
+ ]
90
+ )
91
+ for node, status in node_status.items()
92
+ ]
93
+ esg.ui.print(totable(table))
94
+ esg.ui.raise_maybe_record(Exit(0))
esgpull/cli/search.py CHANGED
@@ -99,6 +99,7 @@ def search(
99
99
  esg.ui.raise_maybe_record(Exit(0))
100
100
  esg.graph.add(query, force=True)
101
101
  query = esg.graph.expand(query.sha)
102
+ esg.context.probe()
102
103
  hits = esg.context.hits(
103
104
  query,
104
105
  file=file,
esgpull/cli/update.py CHANGED
@@ -78,6 +78,7 @@ def update(
78
78
  if not qfs:
79
79
  esg.ui.print(":stop_sign: Trying to update untracked queries.")
80
80
  esg.ui.raise_maybe_record(Exit(0))
81
+ esg.context.probe()
81
82
  hints = esg.context.hints(
82
83
  *[qf.expanded for qf in qfs],
83
84
  file=True,