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

Method diskpart_erase

MakeInstall.py:267–331  ·  view source on GitHub ↗
(self, disk, gpt=False, clover_version = None, local_file = None)

Source from the content-addressed store, hash-verified

265 self.u.grab("Press [enter] to return...")
266
267 def diskpart_erase(self, disk, gpt=False, clover_version = None, local_file = None):
268 # Generate a script that we can pipe to diskpart to erase our disk
269 self.u.head("Erasing With DiskPart")
270 print("")
271 # Then we'll re-gather our disk info on success and move forward
272 # Using MBR to effectively set the individual partition types
273 # Keeps us from having issues mounting the EFI on Windows -
274 # and also lets us explicitly set the partition id for the main
275 # data partition.
276 if not gpt:
277 print("Using MBR...")
278 dp_script = "\n".join([
279 "select disk {}".format(disk.get("index",-1)),
280 "clean",
281 "convert mbr",
282 "create partition primary size=200",
283 "format quick fs=fat32 label='BOOT'",
284 "active",
285 "create partition primary",
286 "select part 2",
287 "set id=AB", # AF = HFS, AB = Recovery
288 "select part 1",
289 "assign"
290 ])
291 else:
292 print("Using GPT...")
293 dp_script = "\n".join([
294 "select disk {}".format(disk.get("index",-1)),
295 "clean",
296 "convert gpt",
297 "create partition primary size=200",
298 "format quick fs=fat32 label='BOOT'",
299 "create partition primary id={}".format(self.hfs_id)
300 ])
301 temp = tempfile.mkdtemp()
302 script = os.path.join(temp, "diskpart.txt")
303 try:
304 with open(script,"w") as f:
305 f.write(dp_script)
306 except:
307 shutil.rmtree(temp)
308 print("Error creating script!")
309 print("")
310 self.u.grab("Press [enter] to return...")
311 return
312 # Let's try to run it!
313 out = self.r.run({"args":[self.diskpart,"/s",script],"stream":True})
314 # Ditch our script regardless of whether diskpart worked or not
315 shutil.rmtree(temp)
316 if out[2] != 0:
317 # Error city!
318 print("")
319 print("DiskPart exited with non-zero status ({}). Aborting.".format(out[2]))
320 print("")
321 self.u.grab("Press [enter] to return...")
322 return
323 # We should now have a fresh drive to work with
324 # Let's write an image or something

Callers 1

mainMethod · 0.95

Calls 6

select_packageMethod · 0.95
headMethod · 0.80
writeMethod · 0.80
grabMethod · 0.80
runMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected