From 7aa3ff5255d18305825ce2caef171dc4dfa56cad Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 31 Oct 2020 18:58:19 +0100 Subject: [PATCH] Added a .strip() to moulinette's check_output because was tired of adding it all over the places --- data/hooks/diagnosis/00-basesystem.py | 6 +++--- data/hooks/diagnosis/12-dnsrecords.py | 2 +- data/hooks/diagnosis/24-mail.py | 2 +- src/yunohost/data_migrations/0015_migrate_to_buster.py | 8 ++++---- src/yunohost/dyndns.py | 4 ++-- src/yunohost/utils/packages.py | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/hooks/diagnosis/00-basesystem.py b/data/hooks/diagnosis/00-basesystem.py index d58ca4aff..d56faec98 100644 --- a/data/hooks/diagnosis/00-basesystem.py +++ b/data/hooks/diagnosis/00-basesystem.py @@ -21,12 +21,12 @@ class BaseSystemDiagnoser(Diagnoser): # Detect virt technology (if not bare metal) and arch # Gotta have this "|| true" because it systemd-detect-virt return 'none' # with an error code on bare metal ~.~ - virt = check_output("systemd-detect-virt || true", shell=True).strip() + virt = check_output("systemd-detect-virt || true", shell=True) if virt.lower() == "none": virt = "bare-metal" # Detect arch - arch = check_output("dpkg --print-architecture").strip() + arch = check_output("dpkg --print-architecture") hardware = dict(meta={"test": "hardware"}, status="INFO", data={"virt": virt, "arch": arch}, @@ -102,7 +102,7 @@ class BaseSystemDiagnoser(Diagnoser): continue cmd = "LC_ALL=C apt policy %s 2>&1 | grep http -B1 | tr -d '*' | grep '+deb' | grep -v 'gbp' | head -n 1 | awk '{print $1}'" % package - version_to_downgrade_to = check_output(cmd).strip() + version_to_downgrade_to = check_output(cmd) yield (package, version_to_downgrade_to) def is_vulnerable_to_meltdown(self): diff --git a/data/hooks/diagnosis/12-dnsrecords.py b/data/hooks/diagnosis/12-dnsrecords.py index 91dec7006..941911147 100644 --- a/data/hooks/diagnosis/12-dnsrecords.py +++ b/data/hooks/diagnosis/12-dnsrecords.py @@ -206,7 +206,7 @@ class DNSRecordsDiagnoser(Diagnoser): Return the expiration datetime of a domain or None """ command = "whois -H %s || echo failed" % (domain) - out = check_output(command).strip().split("\n") + out = check_output(command).split("\n") # Reduce output to determine if whois answer is equivalent to NOT FOUND filtered_out = [line for line in out diff --git a/data/hooks/diagnosis/24-mail.py b/data/hooks/diagnosis/24-mail.py index fca9345ab..ca35d53ad 100644 --- a/data/hooks/diagnosis/24-mail.py +++ b/data/hooks/diagnosis/24-mail.py @@ -201,7 +201,7 @@ class MailDiagnoser(Diagnoser): command = 'postqueue -p | grep -v "Mail queue is empty" | grep -c "^[A-Z0-9]" || true' try: - output = check_output(command).strip() + output = check_output(command) pending_emails = int(output) except (ValueError, CalledProcessError) as e: yield dict(meta={"test": "mail_queue"}, diff --git a/src/yunohost/data_migrations/0015_migrate_to_buster.py b/src/yunohost/data_migrations/0015_migrate_to_buster.py index 2de5c7c08..638f519ae 100644 --- a/src/yunohost/data_migrations/0015_migrate_to_buster.py +++ b/src/yunohost/data_migrations/0015_migrate_to_buster.py @@ -184,7 +184,7 @@ class MyMigration(Migration): " | awk '{print $1}'" \ " | { grep 'ynh-deps$' || true; }" - output = check_output(command).strip() + output = check_output(command) return output.split('\n') if output else [] @@ -214,13 +214,13 @@ class MyMigration(Migration): def validate_and_upgrade_cert_if_necessary(self): - active_certs = set(check_output("grep -roh '/.*crt.pem' /etc/nginx/").strip().split("\n")) + active_certs = set(check_output("grep -roh '/.*crt.pem' /etc/nginx/").split("\n")) cmd = "LC_ALL=C openssl x509 -in %s -text -noout | grep -i 'Signature Algorithm:' | awk '{print $3}' | uniq" default_crt = '/etc/yunohost/certs/yunohost.org/crt.pem' default_key = '/etc/yunohost/certs/yunohost.org/key.pem' - default_signature = check_output(cmd % default_crt).strip() if default_crt in active_certs else None + default_signature = check_output(cmd % default_crt) if default_crt in active_certs else None if default_signature is not None and (default_signature.startswith("md5") or default_signature.startswith("sha1")): logger.warning("%s is using a pretty old certificate incompatible with newer versions of nginx ... attempting to regenerate a fresh one" % default_crt) @@ -233,7 +233,7 @@ class MyMigration(Migration): os.system("mv %s.old %s" % (default_crt, default_crt)) os.system("mv %s.old %s" % (default_key, default_key)) - signatures = {cert: check_output(cmd % cert).strip() for cert in active_certs} + signatures = {cert: check_output(cmd % cert) for cert in active_certs} def cert_is_weak(cert): sig = signatures[cert] diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index 7dcc33cbf..fe2a1bc9b 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -216,8 +216,8 @@ def dyndns_update(operation_logger, dyn_host="dyndns.yunohost.org", domain=None, 'zone %s' % host, ] - old_ipv4 = check_output("dig @%s +short %s" % (dyn_host, domain)).strip() or None - old_ipv6 = check_output("dig @%s +short aaaa %s" % (dyn_host, domain)).strip() or None + old_ipv4 = check_output("dig @%s +short %s" % (dyn_host, domain)) or None + old_ipv6 = check_output("dig @%s +short aaaa %s" % (dyn_host, domain)) or None # Get current IPv4 and IPv6 ipv4_ = get_public_ip() diff --git a/src/yunohost/utils/packages.py b/src/yunohost/utils/packages.py index 6e6a922f6..f9ad385f8 100644 --- a/src/yunohost/utils/packages.py +++ b/src/yunohost/utils/packages.py @@ -95,7 +95,7 @@ def ynh_packages_version(*args, **kwargs): def dpkg_is_broken(): - if check_output("dpkg --audit").strip() != "": + if check_output("dpkg --audit") != "": return True # If dpkg is broken, /var/lib/dpkg/updates # will contains files like 0001, 0002, ...