viur-cli 3.0.0b2__tar.gz → 3.0.0b3__tar.gz
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.
- {viur_cli-3.0.0b2/src/viur_cli.egg-info → viur_cli-3.0.0b3}/PKG-INFO +1 -1
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/scriptor/cli.py +77 -13
- viur_cli-3.0.0b3/src/viur_cli/version.py +2 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3/src/viur_cli.egg-info}/PKG-INFO +1 -1
- viur_cli-3.0.0b2/src/viur_cli/version.py +0 -2
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/LICENSE +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/README.md +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/pyproject.toml +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/setup.cfg +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/__init__.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/_docs_cli.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/build.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/cli.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/cloud.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/conf.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/deprecated.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/local.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/package.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/scriptor/__init__.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/scriptor/login.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/scripts/__init__.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/scripts/get_pyodide.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/setup.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/update.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli/utils.py +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli.egg-info/SOURCES.txt +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli.egg-info/dependency_links.txt +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli.egg-info/entry_points.txt +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli.egg-info/requires.txt +0 -0
- {viur_cli-3.0.0b2 → viur_cli-3.0.0b3}/src/viur_cli.egg-info/top_level.txt +0 -0
|
@@ -4,6 +4,7 @@ import json
|
|
|
4
4
|
import requests
|
|
5
5
|
import os
|
|
6
6
|
import hashlib
|
|
7
|
+
import difflib
|
|
7
8
|
import asyncio
|
|
8
9
|
import sys
|
|
9
10
|
import glob
|
|
@@ -34,7 +35,7 @@ def script():
|
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
@script.command()
|
|
37
|
-
@click.option('--url', default=None, help='Set the url')
|
|
38
|
+
@click.option('--url', default=None, help='Set the server url')
|
|
38
39
|
@click.option('--username', default=None, help='Set the username')
|
|
39
40
|
@click.option('--working_dir', default=None, help='Set the working directory where scripts are stored to')
|
|
40
41
|
def configure(url: str, username: str, working_dir: str):
|
|
@@ -43,15 +44,32 @@ def configure(url: str, username: str, working_dir: str):
|
|
|
43
44
|
Only flags that are passed are written; the rest of the
|
|
44
45
|
`viur_scriptor_config.json` keeps its previous values.
|
|
45
46
|
"""
|
|
47
|
+
if not any([url, username, working_dir]):
|
|
48
|
+
click.echo("No parameters provided. Use one or more of the following options:")
|
|
49
|
+
click.echo(" --url Set the server URL")
|
|
50
|
+
click.echo(" --username Set the username")
|
|
51
|
+
click.echo(" --working_dir Set the working directory where scripts are stored to")
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
changed = []
|
|
46
55
|
|
|
47
56
|
if url:
|
|
48
57
|
scriptor_config["base_url"] = url
|
|
58
|
+
changed.append(f"url = {url}")
|
|
49
59
|
|
|
50
60
|
if username:
|
|
51
61
|
scriptor_config["username"] = username
|
|
62
|
+
changed.append(f"username = {username}")
|
|
52
63
|
|
|
53
64
|
if working_dir:
|
|
54
65
|
scriptor_config["working_dir"] = working_dir.replace("\\", "/")
|
|
66
|
+
changed.append(f"working_dir = {working_dir}")
|
|
67
|
+
|
|
68
|
+
click.echo("Configuration updated:")
|
|
69
|
+
for entry in changed:
|
|
70
|
+
click.echo(f" {entry}")
|
|
71
|
+
|
|
72
|
+
scriptor_config.save()
|
|
55
73
|
|
|
56
74
|
|
|
57
75
|
@script.command()
|
|
@@ -115,7 +133,8 @@ def check_session(ctx: click.Context):
|
|
|
115
133
|
get_modules()
|
|
116
134
|
|
|
117
135
|
@script.command()
|
|
118
|
-
@click.option('--force', default=False,
|
|
136
|
+
@click.option('--force', default=False, is_flag=True,
|
|
137
|
+
help='Overwrite local files without asking for confirmation')
|
|
119
138
|
@click.pass_context
|
|
120
139
|
def pull(ctx: click.Context, force: bool):
|
|
121
140
|
"""Download all server-side Scriptor scripts into the local working_dir.
|
|
@@ -131,36 +150,74 @@ def pull(ctx: click.Context, force: bool):
|
|
|
131
150
|
tree = await modules.get_module("script")
|
|
132
151
|
working_dir = scriptor_config.get("working_dir")
|
|
133
152
|
|
|
153
|
+
stats = {"new": 0, "updated": 0, "skipped": 0, "unchanged": 0, "dirs": 0}
|
|
154
|
+
|
|
134
155
|
async def process_entry(entry: dict, is_node: bool):
|
|
135
156
|
_path = os.path.join(working_dir, entry["path"].lstrip("/"))
|
|
136
157
|
|
|
137
158
|
if is_node:
|
|
138
159
|
if not os.path.exists(_path):
|
|
160
|
+
click.echo(click.style(f" mkdir {entry['path']}", fg="blue"))
|
|
139
161
|
os.makedirs(_path)
|
|
162
|
+
stats["dirs"] += 1
|
|
140
163
|
else:
|
|
164
|
+
click.echo(f" check {entry['path']}", nl=False)
|
|
165
|
+
|
|
141
166
|
def create_file():
|
|
142
167
|
with open(_path, "a+") as f:
|
|
143
168
|
f.write(entry["script"])
|
|
144
169
|
|
|
145
|
-
click.echo(f"Pull {_path}")
|
|
146
|
-
|
|
147
170
|
if os.path.exists(_path):
|
|
148
171
|
if force:
|
|
172
|
+
with open(_path, "r") as f:
|
|
173
|
+
changed = f.read().splitlines() != entry["script"].splitlines()
|
|
149
174
|
os.remove(_path)
|
|
150
175
|
create_file()
|
|
176
|
+
if changed:
|
|
177
|
+
click.echo(click.style(" [updated]", fg="yellow"))
|
|
178
|
+
stats["updated"] += 1
|
|
179
|
+
else:
|
|
180
|
+
click.echo(click.style(" [ok]", fg="green"))
|
|
181
|
+
stats["unchanged"] += 1
|
|
151
182
|
else:
|
|
152
183
|
with open(_path, "r") as f:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
184
|
+
local_content = f.read()
|
|
185
|
+
remote_content = entry["script"]
|
|
186
|
+
diff = list(difflib.unified_diff(
|
|
187
|
+
remote_content.splitlines(),
|
|
188
|
+
local_content.splitlines(),
|
|
189
|
+
fromfile=f"server/{entry['path'].lstrip('/')}",
|
|
190
|
+
tofile=f"local/{entry['path'].lstrip('/')}",
|
|
191
|
+
lineterm="",
|
|
192
|
+
))
|
|
193
|
+
if diff:
|
|
194
|
+
click.echo(click.style(" [diff]", fg="yellow"))
|
|
195
|
+
for line in diff:
|
|
196
|
+
if line.startswith("+++") or line.startswith("---"):
|
|
197
|
+
click.echo(click.style(line, bold=True))
|
|
198
|
+
elif line.startswith("@@"):
|
|
199
|
+
click.echo(click.style(line, fg="cyan"))
|
|
200
|
+
elif line.startswith("+"):
|
|
201
|
+
click.echo(click.style(line, fg="green"))
|
|
202
|
+
elif line.startswith("-"):
|
|
203
|
+
click.echo(click.style(line, fg="red"))
|
|
204
|
+
else:
|
|
205
|
+
click.echo(line)
|
|
206
|
+
if click.confirm(f"Overwrite local {entry['path']} with remote version?"):
|
|
207
|
+
os.remove(_path)
|
|
208
|
+
create_file()
|
|
209
|
+
stats["updated"] += 1
|
|
210
|
+
else:
|
|
211
|
+
stats["skipped"] += 1
|
|
212
|
+
else:
|
|
213
|
+
click.echo(click.style(" [ok]", fg="green"))
|
|
214
|
+
stats["unchanged"] += 1
|
|
162
215
|
else:
|
|
216
|
+
click.echo(click.style(" [new]", fg="green"))
|
|
163
217
|
create_file()
|
|
218
|
+
stats["new"] += 1
|
|
219
|
+
|
|
220
|
+
click.echo("Fetching scripts from server...")
|
|
164
221
|
|
|
165
222
|
# Process nodes first
|
|
166
223
|
async for node in tree.list(skel_type="node"):
|
|
@@ -170,6 +227,13 @@ def pull(ctx: click.Context, force: bool):
|
|
|
170
227
|
async for leaf in tree.list(skel_type="leaf"):
|
|
171
228
|
await process_entry(leaf, False)
|
|
172
229
|
|
|
230
|
+
click.echo("")
|
|
231
|
+
click.echo(click.style("Summary:", bold=True))
|
|
232
|
+
click.echo(f" new: {stats['new']}")
|
|
233
|
+
click.echo(f" updated: {stats['updated']}")
|
|
234
|
+
click.echo(f" skipped: {stats['skipped']}")
|
|
235
|
+
click.echo(f" unchanged: {stats['unchanged']}")
|
|
236
|
+
|
|
173
237
|
asyncio.run(main())
|
|
174
238
|
|
|
175
239
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|