From 3550da73e6da062d69dd0d7f1f6889b684abb15d Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Tue, 5 Jul 2022 17:11:26 +0200 Subject: image_create: partial integration into python Integrates some parts of this operation into native code, eg: the md5 checksum computation. Wraps non native processes and commands using the subprocess module. For example, legacy.py stores bash commands pending integration. Supports python >=3.6, expected until more modern ogLives are put into production environments. --- src/utils/fs.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/utils/fs.py') diff --git a/src/utils/fs.py b/src/utils/fs.py index 191fb86..cd58383 100644 --- a/src/utils/fs.py +++ b/src/utils/fs.py @@ -6,10 +6,11 @@ # Free Software Foundation; either version 3 of the License, or # (at your option) any later version. +import logging import os import subprocess -from subprocess import DEVNULL +from subprocess import DEVNULL, PIPE import psutil @@ -74,3 +75,28 @@ def get_usedperc(mountpoint): except FileNotFoundError: return '0' return str(perc) + + +def ogReduceFs(disk, part): + """ + Bash function 'ogReduceFs' wrapper + """ + proc = subprocess.run(f'ogReduceFs {disk} {part}', + shell=True, stdout=PIPE) + + if proc.returncode == 0: + subprocess.run(f'ogUnmount {disk} {part}', + shell=True, stdout=PIPE) + return proc.stdout.decode().replace('\n', '') + + logging.warn(f'ogReduceFS exited with code {proc.returncode}') + return None + + +def ogExtendFs(disk, part): + """ + Bash function 'ogExtendFs' wrapper + """ + proc = subprocess.run(f'ogExtendFs {disk} {part}', + shell=True) + return proc.returncode -- cgit v1.2.3-18-g5258