summaryrefslogtreecommitdiffstats
path: root/host/utils
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-05-21 15:06:54 -0700
committerJosh Blum <josh@joshknows.com>2010-05-21 15:06:54 -0700
commit98bd3e1ddc0189f45f209c02b7dc7877ab377960 (patch)
tree2b5d4d7b26e197a699e187dc75ee8308e068036a /host/utils
parent221909b36b2a08a5817e75a3d13ebfe56716c7da (diff)
downloaduhd-98bd3e1ddc0189f45f209c02b7dc7877ab377960.tar.gz
uhd-98bd3e1ddc0189f45f209c02b7dc7877ab377960.tar.bz2
uhd-98bd3e1ddc0189f45f209c02b7dc7877ab377960.zip
clean up parsing of dd.exe --list for windows usrp2 card burner
Diffstat (limited to 'host/utils')
-rwxr-xr-xhost/utils/usrp2_card_burner.py46
1 files changed, 22 insertions, 24 deletions
diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py
index c39fb9d19..60aca9133 100755
--- a/host/utils/usrp2_card_burner.py
+++ b/host/utils/usrp2_card_burner.py
@@ -66,30 +66,28 @@ def get_raw_device_hints():
# Platform Windows: parse the output of dd.exe --list
####################################################################
if platform.system() == 'Windows':
- volumes = list()
- try: output = command(get_dd_path(), '--list')
- except: return volumes
-
- #coagulate info for identical links
- link_to_info = dict()
- for info in output.replace('\r', '').split('\n\\\\'):
- if 'link to' not in info: continue
- link = info.split('link to')[-1].split()[0].strip()
- if not link_to_info.has_key(link): link_to_info[link] = '\n\n'
- link_to_info[link] += info
-
- #parse info only keeping viable volumes
- for link, info in link_to_info.iteritems():
- if 'removable' not in info.lower(): continue
- if 'size is' in info:
- size = info.split('size is')[-1].split()[0].strip()
- if int(size) > MAX_SD_CARD_SIZE: continue
- if 'Mounted on' in info:
- volumes.append(info.split('Mounted on')[-1].split()[0])
- continue
- volumes.append(link)
-
- return sorted(set(volumes))
+ def extract_info_value(info, key):
+ return info.split(key)[-1].split()[0]
+ def get_info_list(output):
+ in_info = False
+ for line in output.splitlines():
+ if line.startswith('\\\\'): in_info = True; info = ''
+ elif in_info and not line.strip(): in_info = False; yield info
+ if in_info: info += '\n'+line.strip()
+ def is_info_valid(info):
+ try:
+ assert 'link to' in info
+ #handles two spellings of remov(e)able:
+ assert 'remov' in info.lower()
+ if 'size is' in info: assert int(extract_info_value(info, 'size is')) <= MAX_SD_CARD_SIZE
+ return True
+ except: return False
+ def extract_info_name(info):
+ for key in ('Mounted on', 'link to'):
+ if key in info: return extract_info_value(info, key)
+ return info.splitlines()[0].strip()
+
+ return sorted(set(map(extract_info_name, filter(is_info_valid, get_info_list(command(get_dd_path(), '--list'))))))
####################################################################
# Platform Linux: parse procfs /proc/partitions