mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Uniformize check_output calls to use moulinette helpers which shall now automatically decode() automatically + also strip() etc
This commit is contained in:
parent
0434bd5dc2
commit
cce020daac
7 changed files with 24 additions and 25 deletions
|
@ -149,7 +149,8 @@ class BaseSystemDiagnoser(Diagnoser):
|
|||
# "missing some kernel info (see -v), accuracy might be reduced"
|
||||
# Dunno what to do about that but we probably don't want to harass
|
||||
# users with this warning ...
|
||||
output, err = call.communicate()
|
||||
output, _ = call.communicate()
|
||||
output = output.decode()
|
||||
assert call.returncode in (0, 2, 3), "Return code: %s" % call.returncode
|
||||
|
||||
# If there are multiple lines, sounds like there was some messages
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import psutil
|
||||
import subprocess
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from moulinette.utils.process import check_output
|
||||
|
||||
from yunohost.diagnosis import Diagnoser
|
||||
|
||||
|
||||
|
@ -119,7 +120,7 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
def analyzed_kern_log():
|
||||
|
||||
cmd = 'tail -n 10000 /var/log/kern.log | grep "oom_reaper: reaped process" || true'
|
||||
out = subprocess.check_output(cmd, shell=True).strip()
|
||||
out = check_output(cmd)
|
||||
lines = out.split("\n") if out else []
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
|
|
@ -39,7 +39,7 @@ from collections import OrderedDict
|
|||
from moulinette import msignals, m18n, msettings
|
||||
from moulinette.utils.log import getActionLogger
|
||||
from moulinette.utils.network import download_json
|
||||
from moulinette.utils.process import run_commands
|
||||
from moulinette.utils.process import run_commands, check_output
|
||||
from moulinette.utils.filesystem import read_file, read_json, read_toml, read_yaml, write_to_file, write_to_json, write_to_yaml, chmod, chown, mkdir
|
||||
|
||||
from yunohost.service import service_status, _run_service_command
|
||||
|
@ -411,10 +411,7 @@ def app_change_url(operation_logger, app, domain, path):
|
|||
# grab nginx errors
|
||||
# the "exit 0" is here to avoid check_output to fail because 'nginx -t'
|
||||
# will return != 0 since we are in a failed state
|
||||
nginx_errors = subprocess.check_output("nginx -t; exit 0",
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=True).rstrip()
|
||||
|
||||
nginx_errors = check_output("nginx -t; exit 0")
|
||||
raise YunohostError("app_change_url_failed_nginx_reload", nginx_errors=nginx_errors)
|
||||
|
||||
logger.success(m18n.n("app_change_url_success",
|
||||
|
@ -2139,10 +2136,9 @@ def _get_git_last_commit_hash(repository, reference='HEAD'):
|
|||
|
||||
"""
|
||||
try:
|
||||
commit = subprocess.check_output(
|
||||
"git ls-remote --exit-code {0} {1} | awk '{{print $1}}'".format(
|
||||
repository, reference),
|
||||
shell=True)
|
||||
cmd = "git ls-remote --exit-code {0} {1} | awk '{{print $1}}'"\
|
||||
.format(repository, reference)
|
||||
commit = check_output(cmd)
|
||||
except subprocess.CalledProcessError:
|
||||
logger.exception("unable to get last commit from %s", repository)
|
||||
raise ValueError("Unable to get last commit with git")
|
||||
|
|
|
@ -41,6 +41,7 @@ from moulinette import msignals, m18n, msettings
|
|||
from moulinette.utils import filesystem
|
||||
from moulinette.utils.log import getActionLogger
|
||||
from moulinette.utils.filesystem import read_file, mkdir, write_to_yaml, read_yaml
|
||||
from moulinette.utils.process import check_output
|
||||
|
||||
from yunohost.app import (
|
||||
app_info, _is_installed,
|
||||
|
@ -2386,7 +2387,7 @@ def _recursive_umount(directory):
|
|||
Args:
|
||||
directory -- a directory path
|
||||
"""
|
||||
mount_lines = subprocess.check_output("mount").split("\n")
|
||||
mount_lines = check_output("mount").split("\n")
|
||||
|
||||
points_to_umount = [line.split(" ")[2]
|
||||
for line in mount_lines
|
||||
|
@ -2412,8 +2413,8 @@ def disk_usage(path):
|
|||
# We don't do this in python with os.stat because we don't want
|
||||
# to follow symlinks
|
||||
|
||||
du_output = subprocess.check_output(['du', '-sb', path])
|
||||
return int(du_output.split()[0].decode('utf-8'))
|
||||
du_output = check_output(['du', '-sb', path], shell=False)
|
||||
return int(du_output.split()[0])
|
||||
|
||||
|
||||
def binary_to_human(n, customary=False):
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
import os
|
||||
import yaml
|
||||
import subprocess
|
||||
import shutil
|
||||
import hashlib
|
||||
|
||||
|
@ -30,6 +29,7 @@ from datetime import datetime
|
|||
|
||||
from moulinette import m18n
|
||||
from moulinette.utils import log, filesystem
|
||||
from moulinette.utils.process import check_output
|
||||
|
||||
from yunohost.utils.error import YunohostError
|
||||
from yunohost.log import is_unit_operation
|
||||
|
@ -654,10 +654,10 @@ def manually_modified_files():
|
|||
def manually_modified_files_compared_to_debian_default(ignore_handled_by_regenconf=False):
|
||||
|
||||
# from https://serverfault.com/a/90401
|
||||
files = subprocess.check_output("dpkg-query -W -f='${Conffiles}\n' '*' \
|
||||
files = check_output("dpkg-query -W -f='${Conffiles}\n' '*' \
|
||||
| awk 'OFS=\" \"{print $2,$1}' \
|
||||
| md5sum -c 2>/dev/null \
|
||||
| awk -F': ' '$2 !~ /OK/{print $1}'", shell=True)
|
||||
| awk -F': ' '$2 !~ /OK/{print $1}'")
|
||||
files = files.strip().split("\n")
|
||||
|
||||
if ignore_handled_by_regenconf:
|
||||
|
|
|
@ -35,6 +35,7 @@ from datetime import datetime
|
|||
|
||||
from moulinette import m18n
|
||||
from yunohost.utils.error import YunohostError
|
||||
from moulinette.utils.process import check_output
|
||||
from moulinette.utils.log import getActionLogger
|
||||
from moulinette.utils.filesystem import read_file, append_to_file, write_to_file
|
||||
|
||||
|
@ -563,8 +564,7 @@ def _give_lock(action, service, p):
|
|||
while son_PID == 0 and p.poll() is None:
|
||||
# Call systemctl to get the PID
|
||||
# Output of the command is e.g. ControlPID=1234
|
||||
son_PID = subprocess.check_output(cmd_get_son_PID.split()) \
|
||||
.strip().split("=")[1]
|
||||
son_PID = check_output(cmd_get_son_PID).split("=")[1]
|
||||
son_PID = int(son_PID)
|
||||
time.sleep(1)
|
||||
|
||||
|
@ -720,7 +720,7 @@ def _get_journalctl_logs(service, number="all"):
|
|||
services = _get_services()
|
||||
systemd_service = services.get(service, {}).get("actual_systemd_service", service)
|
||||
try:
|
||||
return subprocess.check_output("journalctl --no-hostname --no-pager -u {0} -n{1}".format(systemd_service, number), shell=True)
|
||||
return check_output("journalctl --no-hostname --no-pager -u {0} -n{1}".format(systemd_service, number))
|
||||
except:
|
||||
import traceback
|
||||
return "error while get services logs from journalctl:\n%s" % traceback.format_exc()
|
||||
|
|
|
@ -35,6 +35,7 @@ import copy
|
|||
|
||||
from moulinette import msignals, msettings, m18n
|
||||
from moulinette.utils.log import getActionLogger
|
||||
from moulinette.utils.process import check_output
|
||||
|
||||
from yunohost.utils.error import YunohostError
|
||||
from yunohost.service import service_status
|
||||
|
@ -467,8 +468,7 @@ def user_info(username):
|
|||
else:
|
||||
try:
|
||||
cmd = 'doveadm -f flow quota get -u %s' % user['uid'][0]
|
||||
cmd_result = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
|
||||
shell=True)
|
||||
cmd_result = check_output(cmd)
|
||||
except Exception as e:
|
||||
cmd_result = ""
|
||||
logger.warning("Failed to fetch quota info ... : %s " % str(e))
|
||||
|
|
Loading…
Add table
Reference in a new issue