@@ -63,14 +63,24 @@ def get_version_info(software: str, version: str) -> tuple[str, str]:
63
63
url = f"https://api.github.com/repos/{ repo } /releases/latest"
64
64
else :
65
65
url = f"https://api.github.com/repos/{ repo } /releases/tags/v{ version } "
66
+
66
67
if not (req := requests .get (url )).ok :
67
68
echo_error (f"Error while fetching version info (request failed): { req .status_code } { req .reason } " )
68
69
real_version = None # Unknown
69
70
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!
71
72
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 ()
74
84
75
85
if not real_version and version == "latest" :
76
86
download_url = f"https://github.com/{ repo } /releases/latest/download/{ download_name } "
@@ -142,23 +152,16 @@ def scriptor(version, target, profile):
142
152
143
153
real_version , download_url = get_version_info ("scriptor" , version )
144
154
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
-
152
155
scriptor_path = Path (dist_folder , target )
153
156
tmp_zip_file = Path ("scriptor.zip" )
154
157
155
158
def step_label (step : int ) -> str :
156
159
if step == 1 :
157
160
return f"downloading scriptor..."
161
+ elif step == 1 :
162
+ return f"clearing scriptor..."
158
163
elif step == 2 :
159
164
return f"extracting scriptor..."
160
- elif step == 3 :
161
- return f"Editing Project.json"
162
165
elif step == 4 :
163
166
return f"success!"
164
167
@@ -168,30 +171,25 @@ def step_label(step: int) -> str:
168
171
case 1 :
169
172
urlretrieve (download_url , tmp_zip_file )
170
173
case 2 :
174
+ if os .path .exists (scriptor_path ):
175
+ shutil .rmtree (scriptor_path )
176
+ case 3 :
171
177
with zipfile .ZipFile (tmp_zip_file ) as zip_f :
172
178
zip_f .extractall ()
173
- case 3 :
174
- config .migrate ()
175
179
case 4 :
176
180
tmp_zip_file .unlink ()
177
181
bar .label = "updated successful"
178
182
179
- echo_positive (f"Updated scriptor from { old_version } to { real_version } " )
183
+ echo_positive (f"Installed admin { real_version } " )
184
+
180
185
181
- def admin (version : str , target : str , profile ):
186
+ def admin (version : str , target : str , profile : str = "default" ):
182
187
"""Update the admin to a specific version."""
183
188
conf = config .get_profile (profile )
184
189
dist_folder = conf ["distribution_folder" ]
185
190
186
191
real_version , download_url = get_version_info ("admin" , version )
187
192
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
-
195
193
admin_path = Path (dist_folder , target )
196
194
tmp_zip_file = Path ("vi-admin.zip" )
197
195
@@ -203,11 +201,9 @@ def step_label(step: int) -> str:
203
201
elif step == 3 :
204
202
return f"extracting new admin..."
205
203
elif step == 4 :
206
- return f"Editing Project.json"
207
- elif step == 5 :
208
204
return f"success!"
209
205
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 :
211
207
for element in bar :
212
208
if element == 1 :
213
209
urlretrieve (download_url , tmp_zip_file )
@@ -218,12 +214,10 @@ def step_label(step: int) -> str:
218
214
with zipfile .ZipFile (tmp_zip_file ) as zip_f :
219
215
zip_f .extractall (admin_path )
220
216
elif element == 4 :
221
- config .migrate ()
222
- elif element == 5 :
223
217
tmp_zip_file .unlink ()
224
218
bar .label = "updated successful"
225
219
226
- echo_positive (f"Updated admin from { old_version } to { real_version } " )
220
+ echo_positive (f"Installed admin { real_version } " )
227
221
228
222
229
223
def vi (version , target , profile ):
@@ -233,12 +227,6 @@ def vi(version, target, profile):
233
227
dist_folder = conf ["distribution_folder" ]
234
228
235
229
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
242
230
243
231
vi_path = Path (dist_folder , target )
244
232
tmp_zip_file = Path ("vi.zip" )
@@ -251,11 +239,9 @@ def step_label(step: int) -> str:
251
239
elif step == 3 :
252
240
return f"extracting new vi..."
253
241
elif step == 4 :
254
- return f"Editing Project.json"
255
- elif step == 5 :
256
242
return f"success!"
257
243
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 :
259
245
for element in bar :
260
246
if element == 1 :
261
247
urlretrieve (download_url , tmp_zip_file )
@@ -265,10 +251,8 @@ def step_label(step: int) -> str:
265
251
elif element == 3 :
266
252
with zipfile .ZipFile (tmp_zip_file ) as zip_f :
267
253
zip_f .extractall (vi_path )
268
- elif element == 4 :
269
- config .migrate ()
270
254
elif element == 5 :
271
255
tmp_zip_file .unlink ()
272
256
bar .label = "updated successful"
273
257
274
- echo_positive (f"Updated Vi from { old_version } to { real_version } " )
258
+ echo_positive (f"Installed vi { real_version } " )
0 commit comments