From c7b052d60c43a92f06a54b73bac6ff65f0c02194 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 19 Jun 2018 13:07:09 -0400 Subject: [PATCH] Refactor to use slightly more efficient list construction Appending is a bit faster than constucting new lists on top of the old ones. It also avoids the need to use two lists. --- src/aurman/wrappers.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/aurman/wrappers.py b/src/aurman/wrappers.py index 1af053b..89c5254 100644 --- a/src/aurman/wrappers.py +++ b/src/aurman/wrappers.py @@ -88,18 +88,18 @@ def pacman(options_as_string: str, fetch_output: bool, dir_to_execute: str = Non :return: empty list in case of "fetch_output"=False, otherwise the lines of the pacman output as list. one line of output is one item in the list. """ - # I cannot be bothered to untangle the tremendous layers of strings absolutely everywhere. - # Ruthlessly paper over this by using a shell-like parser to convert the weird string - # representation into proper lists. FIXME: teach aurman to natively use lists everywhere. - options = shlex.split(options_as_string) + if sudo: + pacman_query = ["sudo", "pacman"] + else: + pacman_query = ["pacman"] if use_ask: - options = ['--ask=4'] + options + pacman_query += ['--ask=4'] - if sudo: - pacman_query = ["sudo", "pacman"] + options - else: - pacman_query = ["pacman"] + options + # I cannot be bothered to untangle the tremendous layers of strings absolutely everywhere. + # Ruthlessly paper over this by using a shell-like parser to convert the weird string + # representation into proper lists. FIXME: teach aurman to natively use lists everywhere. + pacman_query += shlex.split(options_as_string) kwargs = {'cwd': dir_to_execute}