pac0-cli 0.6.0__py3-none-any.whl → 0.7.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.
- pac0/cli/command/run.py +21 -10
- pac0/cli/command/setup.py +38 -5
- pac0/cli/lib/setup.py +202 -0
- {pac0_cli-0.6.0.dist-info → pac0_cli-0.7.0.dist-info}/METADATA +2 -1
- {pac0_cli-0.6.0.dist-info → pac0_cli-0.7.0.dist-info}/RECORD +7 -6
- {pac0_cli-0.6.0.dist-info → pac0_cli-0.7.0.dist-info}/WHEEL +0 -0
- {pac0_cli-0.6.0.dist-info → pac0_cli-0.7.0.dist-info}/entry_points.txt +0 -0
pac0/cli/command/run.py
CHANGED
|
@@ -22,10 +22,12 @@ services = [
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
def _run_service(
|
|
25
|
+
ctx: typer.Context,
|
|
25
26
|
service: str,
|
|
27
|
+
tools: list[str],
|
|
26
28
|
):
|
|
27
29
|
# TODO: check/install tools
|
|
28
|
-
setup.tool(
|
|
30
|
+
setup.tool(ctx, tools)
|
|
29
31
|
# TODO: get app folder
|
|
30
32
|
setup.source()
|
|
31
33
|
# TODO: clone if necessary
|
|
@@ -65,30 +67,39 @@ def _call(
|
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
@app.command(name="1", help="lance le service 01-api-gateway ...")
|
|
68
|
-
def _(
|
|
70
|
+
def _(ctx: typer.Context):
|
|
71
|
+
_run_service("01-api-gateway", ["git"])
|
|
69
72
|
|
|
70
73
|
@app.command(name='2', help='lance le service 02-esb-central ...')
|
|
71
|
-
def _(
|
|
74
|
+
def _(ctx: typer.Context):
|
|
75
|
+
_run_service(ctx, "02-esb-central", ["git", "nats-server"])
|
|
72
76
|
|
|
73
77
|
@app.command(name='3', help='lance le service 03-controle-formats ...')
|
|
74
|
-
def _(
|
|
78
|
+
def _(ctx: typer.Context):
|
|
79
|
+
_run_service(ctx, "03-controle-formats", ["git"])
|
|
75
80
|
|
|
76
81
|
@app.command(name='4', help='lance le service 04-validation-metier ...')
|
|
77
|
-
def _(
|
|
82
|
+
def _(ctx: typer.Context):
|
|
83
|
+
_run_service(ctx, "04-validation-metier", ["git"])
|
|
78
84
|
|
|
79
85
|
@app.command(name='5', help='lance le service 05-conversion-formats ...')
|
|
80
|
-
def _(
|
|
86
|
+
def _(ctx: typer.Context):
|
|
87
|
+
_run_service(ctx, "05-conversion-formats", ["git"])
|
|
81
88
|
|
|
82
89
|
@app.command(name='6', help='lance le service 06-annuaire-local ...')
|
|
83
|
-
def _(
|
|
90
|
+
def _(ctx: typer.Context):
|
|
91
|
+
_run_service(ctx, "06-annuaire-local", ["git"])
|
|
84
92
|
|
|
85
93
|
@app.command(name='7', help='lance le service 07-routage") ...')
|
|
86
|
-
def _(
|
|
94
|
+
def _(ctx: typer.Context):
|
|
95
|
+
_run_service(ctx, "07-routage", ["git"])
|
|
87
96
|
|
|
88
97
|
@app.command(name='8', help='lance le service 08-transmission-fiscale ...')
|
|
89
|
-
def _(
|
|
98
|
+
def _(ctx: typer.Context):
|
|
99
|
+
_run_service(ctx, "08-transmission-fiscale", ["git"])
|
|
90
100
|
|
|
91
101
|
@app.command(name='9', help='lance le service 09-gestion-cycle ...')
|
|
92
|
-
def _(
|
|
102
|
+
def _(ctx: typer.Context):
|
|
103
|
+
_run_service(ctx, "09-gestion-cycle-vie", ["git"])
|
|
93
104
|
|
|
94
105
|
|
pac0/cli/command/setup.py
CHANGED
|
@@ -1,25 +1,58 @@
|
|
|
1
1
|
import subprocess
|
|
2
2
|
from pathlib import Path
|
|
3
|
+
from typing import Annotated
|
|
3
4
|
|
|
4
5
|
import typer
|
|
5
6
|
|
|
6
7
|
from .. import utils
|
|
8
|
+
from ..lib import setup
|
|
9
|
+
from rich.table import Table
|
|
10
|
+
from rich.console import Console
|
|
7
11
|
|
|
8
12
|
|
|
9
13
|
app = typer.Typer()
|
|
14
|
+
console = Console()
|
|
10
15
|
|
|
11
16
|
DEFAULT_REPO_URL = "https://github.com/paxpar-tech/PA_Communautaire"
|
|
12
17
|
|
|
13
18
|
|
|
14
19
|
@app.command()
|
|
15
20
|
def tool(
|
|
16
|
-
|
|
21
|
+
tool: Annotated[list[str], typer.Argument()],
|
|
22
|
+
install: bool = True,
|
|
23
|
+
summary: bool = True,
|
|
17
24
|
):
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
installed_tools: list[setup.SetupTool] = []
|
|
26
|
+
if tool == ["all"]:
|
|
27
|
+
tool = [t.name for t in setup.tools]
|
|
28
|
+
for single_tool in tool:
|
|
29
|
+
for t in setup.tools:
|
|
30
|
+
if single_tool in (t.name, ""):
|
|
31
|
+
installed_tools.append(t)
|
|
32
|
+
if install:
|
|
33
|
+
t.setup()
|
|
34
|
+
if single_tool != "":
|
|
35
|
+
# return only if single tool install, stay for all
|
|
36
|
+
break
|
|
37
|
+
else:
|
|
38
|
+
if single_tool != "":
|
|
39
|
+
# only if ask for a specific tool
|
|
40
|
+
print(f"tool {single_tool} not supported !")
|
|
21
41
|
|
|
22
|
-
|
|
42
|
+
if summary:
|
|
43
|
+
table = Table(title="installed pp tools")
|
|
44
|
+
|
|
45
|
+
table.add_column("tool", style="cyan", no_wrap=True)
|
|
46
|
+
table.add_column("required", justify="right", style="magenta")
|
|
47
|
+
table.add_column("installed", justify="right", style="green")
|
|
48
|
+
|
|
49
|
+
for t in installed_tools:
|
|
50
|
+
valid = t.check()
|
|
51
|
+
table.add_row(
|
|
52
|
+
t.name, t.version, t.checked_version, style="red" if not valid else None
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
console.print(table)
|
|
23
56
|
|
|
24
57
|
|
|
25
58
|
@app.command()
|
pac0/cli/lib/setup.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import subprocess
|
|
3
|
+
from packaging.version import Version
|
|
4
|
+
from packaging.specifiers import SpecifierSet
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
# cf https://peps.python.org/pep-0440/#version-specifiers
|
|
8
|
+
SPEC_SPECIAL_CHARS = "~=!<>"
|
|
9
|
+
|
|
10
|
+
# ~=: Compatible release clause
|
|
11
|
+
# ==: Version matching clause
|
|
12
|
+
# !=: Version exclusion clause
|
|
13
|
+
# <=, >=: Inclusive ordered comparison clause
|
|
14
|
+
# <, >: Exclusive ordered comparison clause
|
|
15
|
+
# ===: Arbitrary equality clause
|
|
16
|
+
def _version_strip(version: str | None) -> str:
|
|
17
|
+
if version:
|
|
18
|
+
for char in SPEC_SPECIAL_CHARS:
|
|
19
|
+
version = version.replace(char, "")
|
|
20
|
+
return version or ""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class SetupTool:
|
|
25
|
+
name: str
|
|
26
|
+
version: str | None = None
|
|
27
|
+
checked_version: str | None = None
|
|
28
|
+
version_get: str | None = None
|
|
29
|
+
install: str | None = None
|
|
30
|
+
|
|
31
|
+
def _current_version_extract(
|
|
32
|
+
self,
|
|
33
|
+
) -> str:
|
|
34
|
+
if self.version_get is None:
|
|
35
|
+
return "0.0.0"
|
|
36
|
+
try:
|
|
37
|
+
query = subprocess.run(
|
|
38
|
+
self.version_get.strip(),
|
|
39
|
+
shell=True,
|
|
40
|
+
stdout=subprocess.PIPE,
|
|
41
|
+
# cwd=cwd,
|
|
42
|
+
executable="/bin/bash",
|
|
43
|
+
check=True,
|
|
44
|
+
#on_error="print_ignore",
|
|
45
|
+
#extra_envvars=extra_envvars,
|
|
46
|
+
)
|
|
47
|
+
version_current = query.stdout.decode().strip()
|
|
48
|
+
except subprocess.CalledProcessError:
|
|
49
|
+
return "0.0.0"
|
|
50
|
+
# print('version_current====', version_current)
|
|
51
|
+
match = re.search(r"(\d+\.\d+\.\d+)", version_current)
|
|
52
|
+
self.checked_version = match.group(0) if match else "0.0.0"
|
|
53
|
+
return self.checked_version
|
|
54
|
+
|
|
55
|
+
# see https://packaging.pypa.io/en/stable/specifiers.html#usage
|
|
56
|
+
def _version_valid(
|
|
57
|
+
self,
|
|
58
|
+
version: str | None,
|
|
59
|
+
) -> bool:
|
|
60
|
+
if self.version:
|
|
61
|
+
version = version or "0.0.0"
|
|
62
|
+
if self.version[0] in SPEC_SPECIAL_CHARS:
|
|
63
|
+
v = Version(version)
|
|
64
|
+
v_spec = SpecifierSet(self.version or "0.0.0")
|
|
65
|
+
return v in v_spec
|
|
66
|
+
else:
|
|
67
|
+
return self.version in version
|
|
68
|
+
else:
|
|
69
|
+
return True
|
|
70
|
+
|
|
71
|
+
def setup(
|
|
72
|
+
self,
|
|
73
|
+
):
|
|
74
|
+
version_current = self._current_version_extract()
|
|
75
|
+
# if version_current is None:
|
|
76
|
+
if not self._version_valid(version_current) and self.install:
|
|
77
|
+
print(f"Installing {self.name}{self.version} ...")
|
|
78
|
+
|
|
79
|
+
subprocess.run(
|
|
80
|
+
# run install snippet from /tmp
|
|
81
|
+
f"""
|
|
82
|
+
pushd /tmp
|
|
83
|
+
{self.install.format(version=_version_strip(self.version))}
|
|
84
|
+
popd
|
|
85
|
+
""".strip(),
|
|
86
|
+
shell=True,
|
|
87
|
+
executable="/bin/bash",
|
|
88
|
+
)
|
|
89
|
+
version_current = self._current_version_extract()
|
|
90
|
+
|
|
91
|
+
def check(
|
|
92
|
+
self,
|
|
93
|
+
) -> bool:
|
|
94
|
+
version_current = self._current_version_extract()
|
|
95
|
+
valid = self._version_valid(version_current)
|
|
96
|
+
if valid:
|
|
97
|
+
print(f"{self.name}{self.version} ok (found {version_current})")
|
|
98
|
+
else:
|
|
99
|
+
print(
|
|
100
|
+
f"{self.name}{self.version} not found ! (found {version_current})"
|
|
101
|
+
)
|
|
102
|
+
return valid
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
tools: list[SetupTool] = [
|
|
106
|
+
SetupTool(
|
|
107
|
+
name="build-essential",
|
|
108
|
+
version=">=12.10",
|
|
109
|
+
install="""
|
|
110
|
+
apt update
|
|
111
|
+
apt install --yes build-essential
|
|
112
|
+
""",
|
|
113
|
+
version_get="""apt show build-essential | grep Version | cut -d: -f2 | xargs""",
|
|
114
|
+
),
|
|
115
|
+
SetupTool(
|
|
116
|
+
name="git",
|
|
117
|
+
version=">=2.43.0",
|
|
118
|
+
install="""
|
|
119
|
+
apt update
|
|
120
|
+
apt install --yes git
|
|
121
|
+
""",
|
|
122
|
+
version_get="""git -v""",
|
|
123
|
+
),
|
|
124
|
+
SetupTool(
|
|
125
|
+
name="nats-cli",
|
|
126
|
+
version=">=0.3.0",
|
|
127
|
+
install="""
|
|
128
|
+
wget https://github.com/nats-io/natscli/releases/download/v${version}/nats-${version}-linux-amd64.zip
|
|
129
|
+
unzip nats-*-linux-amd64.zip
|
|
130
|
+
mv nats-*-linux-amd64/nats /usr/local/bin/
|
|
131
|
+
rm -Rf nats-*-linux-amd64*
|
|
132
|
+
""",
|
|
133
|
+
version_get="nats --version",
|
|
134
|
+
),
|
|
135
|
+
SetupTool(
|
|
136
|
+
name="nats-server",
|
|
137
|
+
version=">=2.12.3",
|
|
138
|
+
install="""
|
|
139
|
+
wget https://github.com/nats-io/nats-server/releases/download/v${version}/nats-server-v${version}-linux-amd64.tar.gz
|
|
140
|
+
tar xvf nats-server-v*-linux-amd64.tar.gz
|
|
141
|
+
mv nats-server-v*-linux-amd64/nats-server /usr/local/bin/
|
|
142
|
+
rm -Rf nats-server-v*-linux-amd64*
|
|
143
|
+
""",
|
|
144
|
+
version_get="nats-server -v",
|
|
145
|
+
),
|
|
146
|
+
SetupTool(
|
|
147
|
+
name="hx",
|
|
148
|
+
version=">=25.07.1",
|
|
149
|
+
install="""
|
|
150
|
+
curl -sLO "https://github.com/helix-editor/helix/releases/download/{version}/helix-{version}-x86_64-linux.tar.xz"
|
|
151
|
+
tar xf helix-{version}-x86_64-linux.tar.xz
|
|
152
|
+
rm helix-{version}-x86_64-linux.tar.xz
|
|
153
|
+
sudo mv helix-{version}-x86_64-linux/hx /usr/local/bin/
|
|
154
|
+
mkdir -p ~/.config/helix/runtime
|
|
155
|
+
mv helix-{version}-x86_64-linux/runtime ~/.config/helix/runtime
|
|
156
|
+
rm -Rf helix-{version}-x86_64-linux
|
|
157
|
+
""",
|
|
158
|
+
version_get="hx --version",
|
|
159
|
+
),
|
|
160
|
+
SetupTool(
|
|
161
|
+
name="k9s",
|
|
162
|
+
version=">=0.50.4",
|
|
163
|
+
install="""
|
|
164
|
+
curl -sLO "https://github.com/derailed/k9s/releases/download/v{version}/k9s_Linux_amd64.tar.gz"
|
|
165
|
+
tar xf k9s_Linux_amd64.tar.gz
|
|
166
|
+
sudo mv k9s /usr/local/bin/
|
|
167
|
+
""",
|
|
168
|
+
version_get="k9s version",
|
|
169
|
+
),
|
|
170
|
+
SetupTool(
|
|
171
|
+
name="kubectl",
|
|
172
|
+
# curl -L -s https://dl.k8s.io/release/stable.txt
|
|
173
|
+
version=">=1.35.0",
|
|
174
|
+
install="""
|
|
175
|
+
curl -LO "https://dl.k8s.io/release/v{version}/bin/linux/amd64/kubectl"
|
|
176
|
+
chmod a+x kubectl
|
|
177
|
+
sudo mv kubectl /usr/local/bin/
|
|
178
|
+
""",
|
|
179
|
+
version_get="""kubectl version --client""",
|
|
180
|
+
),
|
|
181
|
+
SetupTool(
|
|
182
|
+
name="rclone",
|
|
183
|
+
version=">=1.69.2",
|
|
184
|
+
install="""
|
|
185
|
+
curl -sLO "https://github.com/rclone/rclone/releases/download/v1.69.2/rclone-v1.69.2-linux-amd64.zip"
|
|
186
|
+
unzip rclone-v1.69.2-linux-amd64.zip
|
|
187
|
+
sudo mv rclone-v1.69.2-linux-amd64/rclone /usr/local/bin/
|
|
188
|
+
""",
|
|
189
|
+
version_get="""rclone version""",
|
|
190
|
+
),
|
|
191
|
+
SetupTool(
|
|
192
|
+
name="typst",
|
|
193
|
+
version=">=0.13.1",
|
|
194
|
+
install="""
|
|
195
|
+
curl -LO "https://github.com/typst/typst/releases/download/v{version}/typst-x86_64-unknown-linux-musl.tar.xz"
|
|
196
|
+
tar xvf typst-x86_64-unknown-linux-musl.tar.xz
|
|
197
|
+
sudo mv typst-x86_64-unknown-linux-musl/typst /usr/local/bin/
|
|
198
|
+
rm -Rf typst-x86_64-unknown-linux-musl
|
|
199
|
+
""",
|
|
200
|
+
version_get="""typst --version""",
|
|
201
|
+
),
|
|
202
|
+
]
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pac0-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Outil en ligne de commande (CLI) du projet PAC
|
|
5
5
|
Author: Philippe ENTZMANN
|
|
6
6
|
Author-email: Philippe ENTZMANN <philippe@entzmann.name>
|
|
7
7
|
Requires-Dist: typer>=0.9.0
|
|
8
8
|
Requires-Dist: textual>=0.70.0
|
|
9
9
|
Requires-Dist: pyyaml>=6.0
|
|
10
|
+
Requires-Dist: packaging>=25.0
|
|
10
11
|
Requires-Python: >=3.13
|
|
11
12
|
Description-Content-Type: text/markdown
|
|
12
13
|
|
|
@@ -5,12 +5,13 @@ pac0/cli/command/console/screens/stats.py,sha256=72en91wLKU6XXGFpvHNNvYk5ZfF2vVn
|
|
|
5
5
|
pac0/cli/command/console/screens/tests.py,sha256=3Sz0pK7TDtA22ewhYCqefAmoHsqZe1QE9ZUrqiH-5l8,1046
|
|
6
6
|
pac0/cli/command/console/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
pac0/cli/command/console/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
pac0/cli/command/run.py,sha256=
|
|
9
|
-
pac0/cli/command/setup.py,sha256
|
|
8
|
+
pac0/cli/command/run.py,sha256=toZQEdMuirLAZNrAgibcaWIK4mdrzHNaKv7vZdHE3XQ,3147
|
|
9
|
+
pac0/cli/command/setup.py,sha256=0Sdr7akcWTRlMeobxTDKS2CVIFIOCqe5GLVsTftC-BU,2385
|
|
10
10
|
pac0/cli/command/test.py,sha256=J76CpfOIpLD49_0It6UG8uWzoayg8HjmfD3a4LHRihA,198
|
|
11
|
+
pac0/cli/lib/setup.py,sha256=pw7lAceYkF5ex1OfdvJOhM-6fT9OGWHdyfIKwm2xXGo,6722
|
|
11
12
|
pac0/cli/main.py,sha256=efutWmz90cn56p2mrnQv04RxOyQkqp8L9keD8f2s_qE,1128
|
|
12
13
|
pac0/cli/utils.py,sha256=9ZBTpndp0Y8WTUyNtd3AHewYToTHGB9VkUlGTltpCvY,1035
|
|
13
|
-
pac0_cli-0.
|
|
14
|
-
pac0_cli-0.
|
|
15
|
-
pac0_cli-0.
|
|
16
|
-
pac0_cli-0.
|
|
14
|
+
pac0_cli-0.7.0.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
|
|
15
|
+
pac0_cli-0.7.0.dist-info/entry_points.txt,sha256=G1ivGStFhWmI22qni1eUpRnPi-hQhrDGKEpMmISBmzo,126
|
|
16
|
+
pac0_cli-0.7.0.dist-info/METADATA,sha256=mKMxSdu18jVMKXu09Odo1qvC-VHwaxVi1lbcIsjzXI4,2164
|
|
17
|
+
pac0_cli-0.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|