From a051e403f714e5c0a810215edc103986821aa2b5 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 1 Dec 2013 15:01:26 +0100 Subject: [PATCH] Update apt.py: Python golf! --- aero/adapters/apt.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/aero/adapters/apt.py b/aero/adapters/apt.py index 7834b18..e11a41c 100644 --- a/aero/adapters/apt.py +++ b/aero/adapters/apt.py @@ -14,22 +14,13 @@ def adapter_command(self): def search(self, query): response = self._execute_command(self.search_command, ['search', query])[0].decode(*enc) - lst = {} - from re import match - lst.update([ - match('^([^ ]*) - (.*)', 'apt:'+line).groups() - for line in response.splitlines() - if match('^([^ ]*) - (.*)', line) - ]) - return lst + import re + regex = re.compile('^([^ ]*) - (.*)') + return { 'apt:'+m.group(1): m.group(2) for m in map(regex.match, response.splitlines()) if m } def info(self, query): response = self._execute_command(self.search_command, ['show', query])[0].decode(*enc) - lst = [ - line.split(': ') if line.find(': ') > 0 else ('',line) - for line in response.splitlines() - ] - return self.munge_lines(lst) + return self.munge_lines([(a, b) for a, _, b in map(lambda s: s.rpartition(': '), response.splitlines)]) def install(self, query): return self.shell('install', query)