From 435d14ea9559334200d5a2b86188738d0e2b4466 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 16 Jun 2011 10:24:59 -0700 Subject: usrp2: removed asserts in card burner, remove ascii decode --- host/utils/usrp2_card_burner.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'host/utils') diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py index 26adb91c7..29370ca49 100755 --- a/host/utils/usrp2_card_burner.py +++ b/host/utils/usrp2_card_burner.py @@ -50,7 +50,7 @@ def command(*args): stderr=subprocess.STDOUT, ) ret = p.wait() - verbose = p.stdout.read().decode('ascii') + verbose = p.stdout.read().decode() if ret != 0: raise Exception(verbose) return verbose @@ -92,12 +92,12 @@ def get_raw_device_hints(): if in_info: info += '\n'+line.strip() def is_info_valid(info): try: - assert 'link to' in info + if 'link to' not in info: return False #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 + if 'remov' not in info.lower(): return False + if 'size is' in info and int(extract_info_value(info, 'size is')) > MAX_SD_CARD_SIZE: return False except: return False + return True def extract_info_name(info): for key in ('Mounted on', 'link to'): if key in info: return extract_info_value(info, key) @@ -110,13 +110,11 @@ def get_raw_device_hints(): #################################################################### if platform.system() == 'Linux': devs = list() - try: output = open('/proc/partitions', 'r').read().decode('ascii') - except: return devs - for line in output.splitlines(): + for line in command('cat', '/proc/partitions').splitlines(): try: major, minor, blocks, name = line.split() - assert not name[-1].isdigit() or int(minor) == 0 - assert int(blocks)*1024 <= MAX_SD_CARD_SIZE + if not name[-1].isdigit() and int(minor) == 0: continue + if int(blocks)*1024 > MAX_SD_CARD_SIZE: continue except: continue devs.append(os.path.join('/dev', name)) @@ -132,13 +130,13 @@ def get_raw_device_hints(): def is_dev_valid(dev): info = output_to_info(command('diskutil', 'info', dev)) try: - if 'internal' in info: assert info['internal'] == 'no' - if 'ejectable' in info: assert info['ejectable'] == 'yes' + if 'internal' in info and info['internal'] == 'yes': return False + if 'ejectable' in info and info['ejectable'] == 'no': return False if 'total size' in info: 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 + if size_match and int(size_match.groups()[0]) > MAX_SD_CARD_SIZE: return False except: return False + return True return sorted(set(filter(is_dev_valid, devs))) -- cgit v1.2.3 From a18b7e0168108556a0be93853ef672d6fd32ab72 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 16 Jun 2011 11:46:13 -0700 Subject: usrp2: macosx fix, use object's strip, not str (could be unicode) --- host/utils/usrp2_card_burner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/utils') diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py index 29370ca49..43689dd20 100755 --- a/host/utils/usrp2_card_burner.py +++ b/host/utils/usrp2_card_burner.py @@ -126,7 +126,7 @@ def get_raw_device_hints(): if platform.system() == 'Darwin': devs = [d.split()[0] for d in [l for l in command('diskutil', 'list').splitlines() if l.startswith('/dev')]] def output_to_info(output): - return dict([list(map(str.strip, pair.lower().split(':'))) for pair in [l for l in output.splitlines() if ':' in l]]) + return dict([list(map(lambda x: x.strip(), pair.lower().split(':'))) for pair in [l for l in output.splitlines() if ':' in l]]) def is_dev_valid(dev): info = output_to_info(command('diskutil', 'info', dev)) try: -- cgit v1.2.3