cgse-tools 2025.0.8.dev1__py3-none-any.whl → 2025.0.8.dev3__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.
cgse_tools/__init__.py ADDED
File without changes
@@ -0,0 +1,185 @@
1
+ import re
2
+ import subprocess
3
+ import sys
4
+ import textwrap
5
+ from pathlib import Path
6
+ from typing import Annotated
7
+
8
+ import rich
9
+ import typer
10
+
11
+ from egse.system import format_datetime
12
+
13
+ app = typer.Typer()
14
+
15
+
16
+ @app.command()
17
+ def top():
18
+ """
19
+ A top-like interface for core services and device control servers.
20
+
21
+ Not yet implemented.
22
+ """
23
+ print("This fancy top is not yet implemented.")
24
+
25
+
26
+ @app.command()
27
+ def init(project: str = ""):
28
+ """Initialize your project."""
29
+ from rich.prompt import Prompt, Confirm
30
+
31
+ project = project.upper()
32
+ site_id = None
33
+
34
+ rich.print("[light_steel_blue]Please note default values are given between \[brackets].[/]")
35
+
36
+ answer = Prompt.ask(f"What is the name of the project [{project}] ?")
37
+ if answer:
38
+ project = answer.upper()
39
+ while not site_id:
40
+ answer = Prompt.ask("What is the site identifier ?")
41
+ if answer:
42
+ site_id = answer.upper()
43
+ else:
44
+ answer = Confirm.ask("Abort?")
45
+ if answer:
46
+ return
47
+
48
+ data_storage_location = f"~/data/{project}/{site_id}/"
49
+ answer = Prompt.ask(f"Where can the project data be stored [{data_storage_location}] ?")
50
+ if answer:
51
+ data_storage_location = answer
52
+
53
+ conf_data_location = f"~/data/{project}/{site_id}/conf/"
54
+ answer = Prompt.ask(f"Where will the configuration data be located [{conf_data_location}] ?")
55
+ if answer:
56
+ conf_data_location = answer
57
+
58
+ log_file_location = f"~/data/{project}/{site_id}/log/"
59
+ answer = Prompt.ask(f"Where will the logging messages be stored [{log_file_location}] ?")
60
+ if answer:
61
+ log_file_location = answer
62
+
63
+ local_settings_path = f"~/data/{project}/{site_id}/local_settings.yaml"
64
+ answer = Prompt.ask(f"Where shall I create a local settings YAML file [{local_settings_path}] ?")
65
+ if answer:
66
+ local_settings_path = answer
67
+
68
+ Path(data_storage_location).expanduser().mkdir(exist_ok=True, parents=True)
69
+ (Path(data_storage_location).expanduser() / "daily").mkdir(exist_ok=True, parents=True)
70
+ (Path(data_storage_location).expanduser() / "obs").mkdir(exist_ok=True, parents=True)
71
+ Path(conf_data_location).expanduser().mkdir(exist_ok=True, parents=True)
72
+ Path(log_file_location).expanduser().mkdir(exist_ok=True, parents=True)
73
+
74
+ with open(Path(local_settings_path).expanduser(), 'w') as fd:
75
+ fd.write(
76
+ textwrap.dedent(
77
+ f"""\
78
+ SITE:
79
+ ID: {site_id}
80
+ """
81
+ )
82
+ )
83
+
84
+ answer = Confirm.ask("Shall I add the environment to your ~/bash_profile ?")
85
+ if answer:
86
+ with open(Path("~/.bash_profile").expanduser(), 'a') as fd:
87
+ fd.write(
88
+ textwrap.dedent(
89
+ f"""
90
+ # Environment for project {project} added by `cgse init` at {format_datetime()}
91
+ export PROJECT={project}
92
+ export SITE_ID={site_id}
93
+ export {project}_DATA_STORAGE_LOCATION={data_storage_location}
94
+ export {project}_CONF_DATA_LOCATION={conf_data_location}
95
+ export {project}_LOG_FILE_LOCATION={log_file_location}
96
+ export {project}_LOCAL_SETTINGS={local_settings_path}
97
+ """
98
+ )
99
+ )
100
+
101
+
102
+ show = typer.Typer(help="Show information about settings, environment, setup, ...", no_args_is_help=True)
103
+
104
+
105
+ @show.command(name="settings")
106
+ def show_settings():
107
+ proc = subprocess.Popen(
108
+ [sys.executable, "-m", "egse.settings"],
109
+ stdout=subprocess.PIPE,
110
+ stderr=subprocess.PIPE
111
+ )
112
+ stdout, stderr = proc.communicate()
113
+ rich.print(stdout.decode(), end='')
114
+ if stderr:
115
+ rich.print(f"[red]{stderr.decode()}[/]")
116
+
117
+
118
+ @show.command(name="env")
119
+ def show_env(
120
+ mkdir: Annotated[bool, typer.Option(help="Create the missing folder")] = None,
121
+ full: Annotated[bool, typer.Option(help="Provide additional info")] = None,
122
+ doc: Annotated[bool, typer.Option(help="Provide documentation on environment variables")] = None,
123
+ ):
124
+ options = [opt for opt, flag in [("--mkdir", mkdir), ("--full", full), ("--doc", doc)] if flag]
125
+
126
+ cmd = [sys.executable, "-m", "egse.env"]
127
+ cmd += options if options else []
128
+
129
+ proc = subprocess.Popen(
130
+ cmd,
131
+ stdout=subprocess.PIPE,
132
+ stderr=subprocess.PIPE
133
+ )
134
+ stdout, stderr = proc.communicate()
135
+ rich.print(stdout.decode(), end='')
136
+ if stderr:
137
+ rich.print(f"[red]{stderr.decode()}[/]")
138
+
139
+
140
+ check = typer.Typer(help="Check installation, settings, required files, etc.", no_args_is_help=True)
141
+
142
+
143
+ @check.command(name="setups")
144
+ def check_setups():
145
+ """Perform a number of checks on the SETUP files."""
146
+
147
+ # What can we check with respect to the setups?
148
+ #
149
+ # - CONF_DATA_LOCATION
150
+
151
+ from egse.env import get_conf_data_location
152
+ from egse.env import get_site_id
153
+ from egse.config import find_files
154
+
155
+ any_errors = 0
156
+
157
+ conf_data_location = get_conf_data_location()
158
+ site_id = get_site_id()
159
+
160
+ # ---------- check if the <PROJECT>_CONF_DATA_LOCATION is set
161
+
162
+ if not conf_data_location:
163
+ any_errors += 1
164
+ rich.print("[red]The location of the configuration data can not be determined, check your environment.[/]")
165
+
166
+ if not Path(conf_data_location).exists():
167
+ any_errors += 1
168
+ rich.print(f"[red]The location of the configuration data doesn't exist: {conf_data_location!s}[/]")
169
+
170
+ # ---------- check if there is at least one SETUP in the configuration data folder
171
+
172
+ files = list(find_files("SETUP*.yaml", root=conf_data_location))
173
+
174
+ if not files:
175
+ any_errors += 1
176
+ rich.print(f"[red]No SETUP files were found at {conf_data_location}[/]")
177
+
178
+ regex = re.compile(f"SETUP_{site_id}_00000_.*.yaml")
179
+
180
+ if not any(True for file in files if regex.search(str(file))):
181
+ any_errors += 1
182
+ rich.print(f"[red]The is no Zero SETUP for {site_id} in {conf_data_location}[/]")
183
+
184
+ if not any_errors:
185
+ rich.print("[green]everything seems to be ok.[/]")
@@ -0,0 +1,28 @@
1
+ # An example plugin for the `cgse {start,stop,status} service` command from `cgse-core`.
2
+ #
3
+ import rich
4
+ import typer
5
+
6
+ dev_x = typer.Typer(
7
+ name="dev-x",
8
+ help="device-x is an imaginary device that serves as an example",
9
+ no_args_is_help=True
10
+ )
11
+
12
+
13
+ @dev_x.command(name="start")
14
+ def start_dev_x():
15
+ """Start the dev-x service."""
16
+ rich.print("Starting service dev_x")
17
+
18
+
19
+ @dev_x.command(name="stop")
20
+ def stop_dev_x():
21
+ """Stop the dev-x service."""
22
+ rich.print("Terminating service dev_x")
23
+
24
+
25
+ @dev_x.command(name="status")
26
+ def status_dev_x():
27
+ """Print status information on the dev-x service."""
28
+ rich.print("Printing the status of dev_x")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cgse-tools
3
- Version: 2025.0.8.dev1
3
+ Version: 2025.0.8.dev3
4
4
  Summary: Tools for CGSE
5
5
  Author: IVS KU Leuven
6
6
  Maintainer-email: Rik Huygen <rik.huygen@kuleuven.be>, Sara Regibo <sara.regibo@kuleuven.be>
@@ -0,0 +1,8 @@
1
+ cgse_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ cgse_tools/cgse_commands.py,sha256=Rz2J8LUV_SOXDzAaD2cyLsYELL9NI8TpyTP_uakeUtg,6095
3
+ cgse_tools/cgse_services.py,sha256=ZERds5uCHuR5_R4YpBkc2yUTGImtVdKlItherlfL5IM,661
4
+ egse/tools/status.py,sha256=2PFjU760X-E2aeLI5sWOZJ_rqHWCG6YwjmqreYpJ6_c,2188
5
+ cgse_tools-2025.0.8.dev3.dist-info/METADATA,sha256=l9Xf3xEMjeFI4k8g6ehNTSFtfWLIGW0cESRA-5vUuw8,613
6
+ cgse_tools-2025.0.8.dev3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ cgse_tools-2025.0.8.dev3.dist-info/entry_points.txt,sha256=asDXVFTyqyl1w9ypPj7KqktTlRCk_wAFekHAl2eL3H4,327
8
+ cgse_tools-2025.0.8.dev3.dist-info/RECORD,,
@@ -4,6 +4,7 @@ cgse-status = egse.tools.status:main
4
4
  [cgse.command.plugins]
5
5
  check = cgse_tools.cgse_commands:check[group]
6
6
  dev-x = cgse_tools.cgse_services:dev_x[group]
7
+ init = cgse_tools.cgse_commands:init
7
8
  show = cgse_tools.cgse_commands:show[group]
8
9
  top = cgse_tools.cgse_commands:top
9
10
 
@@ -1,5 +0,0 @@
1
- egse/tools/status.py,sha256=2PFjU760X-E2aeLI5sWOZJ_rqHWCG6YwjmqreYpJ6_c,2188
2
- cgse_tools-2025.0.8.dev1.dist-info/METADATA,sha256=cV4BynOM8bzUTeg43z_SNwMQ8knFo-06SDnFZNw8oiM,613
3
- cgse_tools-2025.0.8.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
- cgse_tools-2025.0.8.dev1.dist-info/entry_points.txt,sha256=JY7rD8p4H2_MS_4Al0KNsdB5s9uCEawa8NE4pMKlcfc,290
5
- cgse_tools-2025.0.8.dev1.dist-info/RECORD,,