mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-04-12 00:00:19 +02:00
Avoids redundant assignments & optimizes string operations on Packages
This commit is contained in:
parent
b2436b924b
commit
6be0d9e4d5
19
archey
19
archey
@ -563,17 +563,16 @@ class Terminal:
|
||||
|
||||
class Packages:
|
||||
def __init__(self):
|
||||
for packagesTool in [
|
||||
['pacman', '-Q'],
|
||||
['dnf', 'list', 'installed'],
|
||||
['dpkg', '--get-selections'],
|
||||
['zypper', 'search', '--installed-only'],
|
||||
['emerge', '-ep', 'world'],
|
||||
['rpm', '-qa']
|
||||
]:
|
||||
packages = NOT_DETECTED
|
||||
for packagesTool in [['pacman', '-Q'],
|
||||
['dnf', 'list', 'installed'],
|
||||
['dpkg', '--get-selections'],
|
||||
['zypper', 'search', '--installed-only'],
|
||||
['emerge', '-ep', 'world'],
|
||||
['rpm', '-qa']]:
|
||||
try:
|
||||
results = check_output(packagesTool, stderr=DEVNULL).decode()
|
||||
packages = len(results.rstrip().split('\n'))
|
||||
packages = results.count('\n')
|
||||
|
||||
if 'dpkg' in packagesTool:
|
||||
packages -= results.count('deinstall')
|
||||
@ -581,7 +580,7 @@ class Packages:
|
||||
break
|
||||
|
||||
except (FileNotFoundError, CalledProcessError):
|
||||
packages = NOT_DETECTED
|
||||
pass
|
||||
|
||||
self.value = packages
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user