1
0
mirror of https://github.com/HorlogeSkynet/archey4 synced 2025-05-08 08:00:13 +02:00

Avoids redundant assignments & optimizes string operations on Packages

This commit is contained in:
Samuel FORESTIER 2017-12-08 16:44:22 -05:00
parent b2436b924b
commit 6be0d9e4d5

19
archey

@ -563,17 +563,16 @@ class Terminal:
class Packages: class Packages:
def __init__(self): def __init__(self):
for packagesTool in [ packages = NOT_DETECTED
['pacman', '-Q'], for packagesTool in [['pacman', '-Q'],
['dnf', 'list', 'installed'], ['dnf', 'list', 'installed'],
['dpkg', '--get-selections'], ['dpkg', '--get-selections'],
['zypper', 'search', '--installed-only'], ['zypper', 'search', '--installed-only'],
['emerge', '-ep', 'world'], ['emerge', '-ep', 'world'],
['rpm', '-qa'] ['rpm', '-qa']]:
]:
try: try:
results = check_output(packagesTool, stderr=DEVNULL).decode() results = check_output(packagesTool, stderr=DEVNULL).decode()
packages = len(results.rstrip().split('\n')) packages = results.count('\n')
if 'dpkg' in packagesTool: if 'dpkg' in packagesTool:
packages -= results.count('deinstall') packages -= results.count('deinstall')
@ -581,7 +580,7 @@ class Packages:
break break
except (FileNotFoundError, CalledProcessError): except (FileNotFoundError, CalledProcessError):
packages = NOT_DETECTED pass
self.value = packages self.value = packages