diff --git a/jc/parsers/free.py b/jc/parsers/free.py index e4f582be..7585663f 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -49,6 +49,7 @@ Examples: ] """ import jc.utils +import jc.parsers.universal def process(proc_data): @@ -110,19 +111,12 @@ def parse(data, raw=False, quiet=False): if not quiet: jc.utils.compatibility(__name__, compatible) - # code adapted from Conor Heine at: - # https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 - cleandata = data.splitlines() - headers = [h for h in ' '.join(cleandata[0].lower().strip().split()).split() if h] - headers.insert(0, "type") + cleandata[0] = cleandata[0].lower() + cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache') + cleandata[0] = 'type ' + cleandata[0] - # clean up 'buff/cache' header - # even though forward slash in a key is valid json, it can make things difficult - headers = ['buff_cache' if x == 'buff/cache' else x for x in headers] - - raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:]) - raw_output = [dict(zip(headers, r)) for r in raw_data] + raw_output = jc.parsers.universal.simple_table_parse(cleandata) for entry in raw_output: entry['type'] = entry['type'].rstrip(':')