Added a .strip() to moulinette's check_output because was tired of adding it all over the places

This commit is contained in:
Alexandre Aubin 2020-10-31 18:58:19 +01:00
parent 5c19fb0a42
commit 7aa3ff5255
6 changed files with 12 additions and 12 deletions

View file

@ -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):

View file

@ -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

View file

@ -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"},

View file

@ -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]

View file

@ -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()

View file

@ -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, ...