Skip to content

Commit dd694fa

Browse files
committed
fix: viur package update mechanisms fixed
1 parent f26cb1c commit dd694fa

File tree

2 files changed

+26
-41
lines changed

2 files changed

+26
-41
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This file documents any relevant changes.
1212
- feature: implement variable substitution for app.yaml
1313
- feature: make viur package install more handy
1414
- feature: viur cloud setup gcloud now requires deploy diretory in current working directory
15+
- fix: `viur package` update mechanisms fixed
1516
- fix: project.json load on initialization
1617
- fix: redid cloud datastore bucket copy branch
1718
- fix: redid viur create workflow

src/viur_cli/package.py

+25-41
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,24 @@ def get_version_info(software: str, version: str) -> tuple[str, str]:
6363
url = f"https://api.github.com/repos/{repo}/releases/latest"
6464
else:
6565
url = f"https://api.github.com/repos/{repo}/releases/tags/v{version}"
66+
6667
if not (req := requests.get(url)).ok:
6768
echo_error(f"Error while fetching version info (request failed): {req.status_code} {req.reason}")
6869
real_version = None # Unknown
6970
else:
70-
# It's a validated and real existing version, save it to our config
71+
# It's a validated and real existing version, so save it the project.json if necessary!
7172
real_version: str = req.json()["name"]
72-
config["default"][software] = real_version.lstrip("v")
73-
config.save()
73+
version_str = real_version.lstrip("v")
74+
75+
if software not in config["default"]["builds"]:
76+
config["default"]["builds"][software] = {
77+
"kind": "exec",
78+
"command": f"viur package install {software} {version_str if version != 'latest' else ''}".strip()
79+
}
80+
81+
if config["default"]["builds"].get("version") != version_str:
82+
config["default"]["builds"][software]["version"] = version_str
83+
config.save()
7484

7585
if not real_version and version == "latest":
7686
download_url = f"https://github.com/{repo}/releases/latest/download/{download_name}"
@@ -142,23 +152,16 @@ def scriptor(version, target, profile):
142152

143153
real_version, download_url = get_version_info("scriptor", version)
144154

145-
old_version=conf.get('builds').get('scriptor').get('version')
146-
147-
if old_version == real_version.strip("v"):
148-
if not click.confirm(f"You have already installed version {old_version} of scriptor.\n"
149-
f"Do you want to continue and install it again?"):
150-
return
151-
152155
scriptor_path = Path(dist_folder, target)
153156
tmp_zip_file = Path("scriptor.zip")
154157

155158
def step_label(step: int) -> str:
156159
if step == 1:
157160
return f"downloading scriptor..."
161+
elif step == 1:
162+
return f"clearing scriptor..."
158163
elif step == 2:
159164
return f"extracting scriptor..."
160-
elif step == 3:
161-
return f"Editing Project.json"
162165
elif step == 4:
163166
return f"success!"
164167

@@ -168,30 +171,25 @@ def step_label(step: int) -> str:
168171
case 1:
169172
urlretrieve(download_url, tmp_zip_file)
170173
case 2:
174+
if os.path.exists(scriptor_path):
175+
shutil.rmtree(scriptor_path)
176+
case 3:
171177
with zipfile.ZipFile(tmp_zip_file) as zip_f:
172178
zip_f.extractall()
173-
case 3:
174-
config.migrate()
175179
case 4:
176180
tmp_zip_file.unlink()
177181
bar.label = "updated successful"
178182

179-
echo_positive(f"Updated scriptor from {old_version} to {real_version}")
183+
echo_positive(f"Installed admin {real_version}")
184+
180185

181-
def admin(version: str, target: str, profile):
186+
def admin(version: str, target: str, profile: str = "default"):
182187
"""Update the admin to a specific version."""
183188
conf = config.get_profile(profile)
184189
dist_folder = conf["distribution_folder"]
185190

186191
real_version, download_url = get_version_info("admin", version)
187192

188-
old_version=conf.get('builds').get('admin').get('version')
189-
190-
if old_version == real_version.strip("v"):
191-
if not click.confirm(f"You have already installed the version {old_version} of admin.\n"
192-
f"Do you want to continue and install it again?"):
193-
return
194-
195193
admin_path = Path(dist_folder, target)
196194
tmp_zip_file = Path("vi-admin.zip")
197195

@@ -203,11 +201,9 @@ def step_label(step: int) -> str:
203201
elif step == 3:
204202
return f"extracting new admin..."
205203
elif step == 4:
206-
return f"Editing Project.json"
207-
elif step == 5:
208204
return f"success!"
209205

210-
with click.progressbar([1, 2, 3, 4, 5], label="updating admin...", item_show_func=step_label) as bar:
206+
with click.progressbar([1, 2, 3, 4], label="updating admin...", item_show_func=step_label) as bar:
211207
for element in bar:
212208
if element == 1:
213209
urlretrieve(download_url, tmp_zip_file)
@@ -218,12 +214,10 @@ def step_label(step: int) -> str:
218214
with zipfile.ZipFile(tmp_zip_file) as zip_f:
219215
zip_f.extractall(admin_path)
220216
elif element == 4:
221-
config.migrate()
222-
elif element == 5:
223217
tmp_zip_file.unlink()
224218
bar.label = "updated successful"
225219

226-
echo_positive(f"Updated admin from {old_version} to {real_version}")
220+
echo_positive(f"Installed admin {real_version}")
227221

228222

229223
def vi(version, target, profile):
@@ -233,12 +227,6 @@ def vi(version, target, profile):
233227
dist_folder = conf["distribution_folder"]
234228

235229
real_version, download_url = get_version_info("vi", version)
236-
old_version = conf.get('builds').get('vi').get('version')
237-
238-
if old_version == real_version.strip("v"):
239-
if not click.confirm(f"You have already installed the version {old_version} of vi.\n"
240-
f"Do you want to continue and install it again?"):
241-
return
242230

243231
vi_path = Path(dist_folder, target)
244232
tmp_zip_file = Path("vi.zip")
@@ -251,11 +239,9 @@ def step_label(step: int) -> str:
251239
elif step == 3:
252240
return f"extracting new vi..."
253241
elif step == 4:
254-
return f"Editing Project.json"
255-
elif step == 5:
256242
return f"success!"
257243

258-
with click.progressbar([1, 2, 3, 4, 5], label="updating vi...", item_show_func=step_label) as bar:
244+
with click.progressbar([1, 2, 3, 4], label="updating vi...", item_show_func=step_label) as bar:
259245
for element in bar:
260246
if element == 1:
261247
urlretrieve(download_url, tmp_zip_file)
@@ -265,10 +251,8 @@ def step_label(step: int) -> str:
265251
elif element == 3:
266252
with zipfile.ZipFile(tmp_zip_file) as zip_f:
267253
zip_f.extractall(vi_path)
268-
elif element == 4:
269-
config.migrate()
270254
elif element == 5:
271255
tmp_zip_file.unlink()
272256
bar.label = "updated successful"
273257

274-
echo_positive(f"Updated Vi from {old_version} to {real_version}")
258+
echo_positive(f"Installed vi {real_version}")

0 commit comments

Comments
 (0)