replace an ugly hack with a proper subprocess.Popen() in the pacman plugin

This commit is contained in:
Von Random 2019-01-16 14:46:52 +03:00
parent 27160d61bd
commit 6fc4d3176d

View file

@ -9,14 +9,21 @@ class PluginThread(plugins.PluginThreadCommon):
'problem': 10 'problem': 10
} }
super(PluginThread, self).__init__(config, defaults) super(PluginThread, self).__init__(config, defaults)
self.format_status(0) self.format_status(list())
def format_status(self, count): def format_status(self, updates):
self.status['full_text'] = 'UPD: ' + str(count) count = int()
for update in updates:
if not '[ignored]' in update:
count += 1
self.hide = count == 0 self.hide = count == 0
self.status['urgent'] = count >= self.conf['problem'] self.status['urgent'] = count >= self.conf['problem']
self.status['full_text'] = 'UPD: ' + str(count)
def main(self): def main(self):
# TODO: this is an ugly hack, fix it with subprocess.Popen someday pacman_qu = subprocess.Popen(
updates = subprocess.getoutput('/usr/bin/pacman -Qu').count(" -> ") ('/usr/bin/pacman', '-Qu'), stdout=subprocess.PIPE,
self.format_status(updates) stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL
)
out = str(pacman_qu.communicate()[0])
self.format_status(out.splitlines())