From ebbdedef6cfa0ac5528fc513c7eee909ce7b739a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 30 Jan 2020 13:59:12 -0700 Subject: [PATCH] Added get_fstype_macos() --- scripts/wk/hw/ddrescue.py | 28 +++++++++++++++++++++++++--- scripts/wk/hw/obj.py | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/scripts/wk/hw/ddrescue.py b/scripts/wk/hw/ddrescue.py index fe47461e..e3433598 100644 --- a/scripts/wk/hw/ddrescue.py +++ b/scripts/wk/hw/ddrescue.py @@ -727,6 +727,8 @@ class State(): self.update_progress_pane('Idle') self.confirm_selections('Start recovery?') + # TODO: Unmount source and/or destination under macOS + # Prep destination if self.mode == 'Clone': self.prep_destination(source_parts, dry_run=docopt_args['--dry-run']) @@ -1196,7 +1198,6 @@ def build_directory_report(path): line = f'{path:<{width}}{line}' report.append(line) else: - # TODO Get dir details under macOS report.append(std.color_string('PATH', 'BLUE')) report.append(str(path)) @@ -1449,8 +1450,11 @@ def fstype_is_ok(path, map_dir=False): # Get fstype if PLATFORM == 'Darwin': - # TODO: Determine fstype under macOS - pass + try: + fstype = get_fstype_macos(path) + except (IndexError, TypeError, ValueError): + # Ignore for now + pass elif PLATFORM == 'Linux': cmd = [ 'findmnt', @@ -1517,6 +1521,24 @@ def get_etoc(): return etoc +def get_fstype_macos(path): + """Get fstype for path under macOS, returns str. + + NOTE: This method is not very effecient. + """ + cmd = ['df', path] + + # Get device based on the path + proc = exe.run_program(cmd, check=False) + dev = proc.stdout.splitlines()[1].split()[0] + + # Get device details + dev = hw_obj.Disk(dev) + + # Done + return dev.details['fstype'] + + def get_object(path): """Get object based on path, returns obj.""" obj = None diff --git a/scripts/wk/hw/obj.py b/scripts/wk/hw/obj.py index a8719358..dc6175ea 100644 --- a/scripts/wk/hw/obj.py +++ b/scripts/wk/hw/obj.py @@ -321,6 +321,7 @@ class Disk(BaseObj): self.details['bus'] = str(self.details.get('bus', '???')).upper() self.details['bus'] = self.details['bus'].replace('IMAGE', 'Image') self.details['bus'] = self.details['bus'].replace('NVME', 'NVMe') + self.details['fstype'] = self.details.get('fstype', 'Unknown') self.details['log-sec'] = self.details.get('log-sec', 512) self.details['model'] = self.details.get('model', 'Unknown Model') self.details['name'] = self.details.get('name', self.path)