From 36f2812d5a7a94c412e098233c026d99d5205b60 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 17 Dec 2019 10:58:00 -0800 Subject: [PATCH] add support for legacy output --- jc/parsers/pip_list.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/jc/parsers/pip_list.py b/jc/parsers/pip_list.py index 33125c36..cabd6d8a 100644 --- a/jc/parsers/pip_list.py +++ b/jc/parsers/pip_list.py @@ -89,15 +89,23 @@ def parse(data, raw=False, quiet=False): # Clear any blank lines cleandata = list(filter(None, linedata)) - # clear separator line - for i, line in reversed(list(enumerate(cleandata))): - if line.find('---') != -1: - cleandata.pop(i) + # detect legacy output type + if cleandata[0].find(' (') != -1: + for row in cleandata: + raw_output.append({'package': row.split(' (')[0], + 'version': row.split(' (')[1].rstrip(')')}) - cleandata[0] = cleandata[0].lower() + # otherwise normal table output + else: + # clear separator line + for i, line in reversed(list(enumerate(cleandata))): + if line.find('---') != -1: + cleandata.pop(i) - if cleandata: - raw_output = jc.parsers.universal.simple_table_parse(cleandata) + cleandata[0] = cleandata[0].lower() + + if cleandata: + raw_output = jc.parsers.universal.simple_table_parse(cleandata) if raw: return raw_output