Replace subprocess usage with os.system
This commit is contained in:
@@ -3,21 +3,21 @@
|
|||||||
import piksemel
|
import piksemel
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import tempfile
|
||||||
|
|
||||||
ROOT_MOUNT_SOURCE_COMMAND = ["findmnt", "-n", "-o", "SOURCE", "/"]
|
ROOT_MOUNT_SOURCE_COMMAND = "findmnt -n -o SOURCE /"
|
||||||
PARTITION_SUFFIX_PATTERN = r"p?\d+$"
|
PARTITION_SUFFIX_PATTERN = r"p?\d+$"
|
||||||
ROTATIONAL_FLAG_PATH_TEMPLATE = "/sys/block/{disk_name}/queue/rotational"
|
ROTATIONAL_FLAG_PATH_TEMPLATE = "/sys/block/{disk_name}/queue/rotational"
|
||||||
|
|
||||||
|
|
||||||
def _get_root_mount_source():
|
def _get_root_mount_source():
|
||||||
result = subprocess.run(
|
with tempfile.NamedTemporaryFile(mode="r") as output_file:
|
||||||
ROOT_MOUNT_SOURCE_COMMAND,
|
result = os.system("%s > %s" % (ROOT_MOUNT_SOURCE_COMMAND, output_file.name))
|
||||||
capture_output=True,
|
if result != 0:
|
||||||
text=True,
|
raise OSError("Failed to get root mount source")
|
||||||
check=True,
|
|
||||||
)
|
output_file.seek(0)
|
||||||
return result.stdout.strip()
|
return output_file.read().strip()
|
||||||
|
|
||||||
|
|
||||||
def _strip_partition_suffix(device_path):
|
def _strip_partition_suffix(device_path):
|
||||||
@@ -30,7 +30,7 @@ def _is_rotational_disk(disk_name):
|
|||||||
if not os.path.exists(rotational_flag_path):
|
if not os.path.exists(rotational_flag_path):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with open(rotational_flag_path, "r", encoding="utf-8") as rotational_file:
|
with open(rotational_flag_path, "r") as rotational_file:
|
||||||
return int(rotational_file.read().strip()) == 1
|
return int(rotational_file.read().strip()) == 1
|
||||||
|
|
||||||
|
|
||||||
@@ -46,17 +46,13 @@ def _is_root_on_hdd():
|
|||||||
|
|
||||||
return _is_rotational_disk(root_disk_name)
|
return _is_rotational_disk(root_disk_name)
|
||||||
|
|
||||||
except (OSError, subprocess.CalledProcessError, ValueError):
|
except (OSError, ValueError):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _run_update_mime_database(path, use_fsync_opt):
|
def _run_update_mime_database(path, use_fsync_opt):
|
||||||
"""Runs /usr/bin/update-mime-database for the given path.
|
"""Runs /usr/bin/update-mime-database for the given path.
|
||||||
If use_fsync_opt is True, sets PKGSYSTEM_ENABLE_FSYNC=0."""
|
If use_fsync_opt is True, sets PKGSYSTEM_ENABLE_FSYNC=0."""
|
||||||
cmd = ["/usr/bin/update-mime-database", path]
|
os.system("%s/usr/bin/update-mime-database %s" % ("/usr/PKGSYSTEM_ENABLE_FSYNC=0 " if use_fsync_opt else "", path))
|
||||||
env = os.environ.copy()
|
|
||||||
if use_fsync_opt:
|
|
||||||
env["PKGSYSTEM_ENABLE_FSYNC"] = "0"
|
|
||||||
subprocess.run(cmd, env=env, check=False)
|
|
||||||
|
|
||||||
def updateMimeTypes(filepath):
|
def updateMimeTypes(filepath):
|
||||||
parse = piksemel.parse(filepath)
|
parse = piksemel.parse(filepath)
|
||||||
|
|||||||
Reference in New Issue
Block a user