MCPcopy
hub / github.com/corpnewt/gibMacOS / select_package

Method select_package

MakeInstall.py:333–431  ·  view source on GitHub ↗
(self, disk, clover_version = None, local_file = None)

Source from the content-addressed store, hash-verified

331 self.select_package(disk, clover_version, local_file=local_file)
332
333 def select_package(self, disk, clover_version = None, local_file = None):
334 self.u.head("Select Recovery Package")
335 print("")
336 print("{}. {} - {} ({})".format(
337 disk.get("index",-1),
338 disk.get("model","Unknown"),
339 self.dl.get_size(disk.get("size",-1),strip_zeroes=True),
340 ["Unknown","No Root Dir","Removable","Local","Network","Disc","RAM Disk"][disk.get("type",0)]
341 ))
342 print("")
343 print("M. Main Menu")
344 print("Q. Quit")
345 print("")
346 print("(To copy a file's path, shift + right-click in Explorer and select 'Copy as path')\n")
347 menu = self.u.grab("Please paste the recovery update pkg/dmg path to extract: ")
348 if menu.lower() == "q":
349 self.u.custom_quit()
350 if menu.lower() == "m":
351 return
352 path = self.u.check_path(menu)
353 if not path:
354 self.select_package(disk, clover_version, local_file=local_file)
355 return
356 # Got the package - let's make sure it's named right - just in case
357 if os.path.basename(path).lower().endswith(".hfs"):
358 # We have an hfs image already - bypass extraction
359 self.dd_image(disk, path, clover_version, local_file=local_file)
360 return
361 # If it's a directory, find the first recovery hit
362 if os.path.isdir(path):
363 for f in os.listdir(path):
364 if f.lower().endswith(self.recovery_suffixes):
365 path = os.path.join(path, f)
366 break
367 # Make sure it's named right for recovery stuffs
368 if not path.lower().endswith(self.recovery_suffixes):
369 self.u.head("Invalid Package")
370 print("")
371 print("{} is not in the available recovery package names:\n{}".format(os.path.basename(path), ", ".join(self.recovery_suffixes)))
372 print("")
373 print("Ensure you're passing a proper recovery package.")
374 print("")
375 self.u.grab("Press [enter] to return to package selection...")
376 self.select_package(disk, clover_version, local_file=local_file)
377 return
378 self.u.head("Extracting Package")
379 print("")
380 temp = tempfile.mkdtemp()
381 cwd = os.getcwd()
382 os.chdir(temp)
383 print("Located {}...".format(os.path.basename(path)))
384 if not path.lower().endswith(".dmg"):
385 # Extract in sections and remove any files we run into
386 print("Extracting Recovery dmg...")
387 out = self.r.run({"args":[self.z_path, "e", "-txar", path, "*.dmg"]})
388 if out[2] != 0:
389 shutil.rmtree(temp,ignore_errors=True)
390 print("An error occurred extracting: {}".format(out[2]))

Callers 2

diskpart_eraseMethod · 0.95
mainMethod · 0.95

Calls 7

dd_imageMethod · 0.95
headMethod · 0.80
get_sizeMethod · 0.80
grabMethod · 0.80
custom_quitMethod · 0.80
check_pathMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected