diff options
Diffstat (limited to 'host/utils/usrp2_card_burner.py')
| -rwxr-xr-x | host/utils/usrp2_card_burner.py | 21 | 
1 files changed, 21 insertions, 0 deletions
diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py index 60aca9133..d47a4f5f4 100755 --- a/host/utils/usrp2_card_burner.py +++ b/host/utils/usrp2_card_burner.py @@ -22,6 +22,7 @@ import subprocess  import urllib  import optparse  import os +import re  ########################################################################  # constants @@ -107,6 +108,26 @@ def get_raw_device_hints():          return sorted(set(devs))      #################################################################### +    # Platform Mac OS X: parse diskutil list and info commands +    #################################################################### +    if platform.system() == 'Darwin': +        devs = map(lambda d: d.split()[0], filter(lambda l: l.startswith('/dev'), command('diskutil', 'list').splitlines())) +        def output_to_info(output): +            return dict([map(str.strip, pair.lower().split(':')) for pair in filter(lambda l: ':' in l, output.splitlines())]) +        def is_dev_valid(dev): +            info = output_to_info(command('diskutil', 'info', dev)) +            try: +                if info.has_key('internal'): assert info['internal'] == 'no' +                if info.has_key('ejectable'): assert info['ejectable'] == 'yes' +                if info.has_key('total size'): +                    size_match = re.match('^.*\((\d+)\s*bytes\).*$', info['total size']) +                    if size_match: assert int(size_match.groups()[0]) <= MAX_SD_CARD_SIZE +                return True +            except: return False + +        return sorted(set(filter(is_dev_valid, devs))) + +    ####################################################################      # Platform Others:      ####################################################################      return ()  | 
