Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #200 from chrisgrande/master
Browse files Browse the repository at this point in the history
Auto detect Volume Format for eraseVolume
  • Loading branch information
grahamgilbert committed Apr 27, 2018
2 parents fef4c30 + 9e70ef3 commit 42df723
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Imagr/MainController.py
Expand Up @@ -1688,8 +1688,22 @@ def eraseTargetVolume(self, name='Macintosh HD', format='Journaled HFS+', progre
Erases the target volume.
'name' can be used to rename the volume on reformat.
'format' can be used to specify a format type.
'format' type of 'auto_hfs_or_apfs' will check for HFS+ or APFS
If no options are provided, it will format the volume with name 'Macintosh HD' with JHFS+.
"""
NSLog("Format is: %@", format)

if format == 'auto_hfs_or_apfs':
if self.targetVolume._attributes['FilesystemType'] == 'hfs':
format='Journaled HFS+'
NSLog("Detected HFS+ - erasing target")
elif self.targetVolume._attributes['FilesystemType'] == 'apfs':
format='APFS'
NSLog("Detected APFS - erasing target")
else:
NSLog("Volume not HFS+ or APFS, system returned: %@", self.targetVolume._attributes['FilesystemType'])
self.errorMessage = "Not HFS+ or APFS - specify volume format and reload workflows."

cmd = ['/usr/sbin/diskutil', 'eraseVolume', format, name, self.targetVolume.mountpoint ]
NSLog("%@", cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down

0 comments on commit 42df723

Please sign in to comment.