Mass Update
* Util Module
* Provides: color class (for specialty stdout logging)
* Provides: constants classes for rpm, errors, and mock
* Provides: error classes for generic error handling and future fault
handler
* Provides: generic classes for generic, repeatable use cases
* Provides: rpmutil with rpm utilities that range from basic to
advanced metadata handling
* Add mock module
* Can generate a usable mock config based on input provided
* Can generate mock plugin configuration as provided
* cache related plugins are hardcoded as disabled
* Supports plugins: chroot scanning, embedding files, bind mounts
* Can generate basic dnf configs with repo information
* (Currently limited) Error handler
* Runs mock commands (such as build, buildsrpm, init, shell)
* Add modularity module (very limited, doesn't really do much)
* Add peridotpb example (does nothing, will likely be its own thing)
* Add MIT license
2023-06-14 07:39:36 +00:00
|
|
|
# -*-:python; coding:utf-8; -*-
|
|
|
|
# author: Louis Abel <label@rockylinux.org>
|
|
|
|
"""
|
|
|
|
Provides subprocess utilities
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
from pv2.util import error as err
|
|
|
|
|
|
|
|
# todo: remove python 3.6 checks. nodes won't be on el8.
|
|
|
|
|
|
|
|
def run_proc_foreground(command: list):
|
|
|
|
"""
|
|
|
|
Takes in the command in the form of a list and runs it via subprocess.
|
|
|
|
Everything should be in the foreground. The return is just for the exit
|
|
|
|
code.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
processor = subprocess.run(args=command, check=False)
|
|
|
|
except Exception as exc:
|
|
|
|
raise err.GenericError(f'There was an error with your command: {exc}')
|
|
|
|
|
|
|
|
return processor
|
|
|
|
|
2023-06-28 00:20:44 +00:00
|
|
|
def run_proc_foreground_shell(command: str):
|
|
|
|
"""
|
|
|
|
Takes in the command in the form of a list and runs it via subprocess.
|
|
|
|
Everything should be in the foreground. The return is just for the exit
|
|
|
|
code.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
processor = subprocess.run(args=command, shell=True, check=False)
|
|
|
|
except Exception as exc:
|
|
|
|
raise err.GenericError(f'There was an error with your command: {exc}')
|
|
|
|
|
|
|
|
return processor
|
|
|
|
|
Mass Update
* Util Module
* Provides: color class (for specialty stdout logging)
* Provides: constants classes for rpm, errors, and mock
* Provides: error classes for generic error handling and future fault
handler
* Provides: generic classes for generic, repeatable use cases
* Provides: rpmutil with rpm utilities that range from basic to
advanced metadata handling
* Add mock module
* Can generate a usable mock config based on input provided
* Can generate mock plugin configuration as provided
* cache related plugins are hardcoded as disabled
* Supports plugins: chroot scanning, embedding files, bind mounts
* Can generate basic dnf configs with repo information
* (Currently limited) Error handler
* Runs mock commands (such as build, buildsrpm, init, shell)
* Add modularity module (very limited, doesn't really do much)
* Add peridotpb example (does nothing, will likely be its own thing)
* Add MIT license
2023-06-14 07:39:36 +00:00
|
|
|
def run_proc_no_output(command: list):
|
|
|
|
"""
|
|
|
|
Output will be stored in stdout and stderr as needed.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
if sys.version_info <= (3, 6):
|
|
|
|
processor = subprocess.run(args=command, check=False,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
universal_newlines=True)
|
|
|
|
else:
|
|
|
|
processor = subprocess.run(args=command, check=False, capture_output=True,
|
|
|
|
text=True)
|
|
|
|
except Exception as exc:
|
|
|
|
raise err.GenericError(f'There was an error with your command: {exc}')
|
|
|
|
|
|
|
|
return processor
|
|
|
|
|
2023-06-28 00:20:44 +00:00
|
|
|
def run_proc_no_output_shell(command: str):
|
|
|
|
"""
|
|
|
|
Output will be stored in stdout and stderr as needed.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
if sys.version_info <= (3, 6):
|
|
|
|
processor = subprocess.run(args=command, check=False,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
universal_newlines=True,
|
|
|
|
shell=True)
|
|
|
|
else:
|
|
|
|
processor = subprocess.run(args=command, check=False, capture_output=True,
|
|
|
|
text=True, shell=True)
|
|
|
|
except Exception as exc:
|
|
|
|
raise err.GenericError(f'There was an error with your command: {exc}')
|
|
|
|
|
|
|
|
return processor
|
|
|
|
|
|
|
|
|
Mass Update
* Util Module
* Provides: color class (for specialty stdout logging)
* Provides: constants classes for rpm, errors, and mock
* Provides: error classes for generic error handling and future fault
handler
* Provides: generic classes for generic, repeatable use cases
* Provides: rpmutil with rpm utilities that range from basic to
advanced metadata handling
* Add mock module
* Can generate a usable mock config based on input provided
* Can generate mock plugin configuration as provided
* cache related plugins are hardcoded as disabled
* Supports plugins: chroot scanning, embedding files, bind mounts
* Can generate basic dnf configs with repo information
* (Currently limited) Error handler
* Runs mock commands (such as build, buildsrpm, init, shell)
* Add modularity module (very limited, doesn't really do much)
* Add peridotpb example (does nothing, will likely be its own thing)
* Add MIT license
2023-06-14 07:39:36 +00:00
|
|
|
def popen_proc_no_output(command: list):
|
|
|
|
"""
|
|
|
|
This opens a process, but is non-blocking.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
if sys.version_info <= (3, 6):
|
|
|
|
processor = subprocess.Popen(args=command, stdout=subprocess.PIPE,
|
|
|
|
universal_newlines=True)
|
|
|
|
else:
|
|
|
|
# pylint: disable=consider-using-with
|
|
|
|
processor = subprocess.Popen(args=command, stdout=subprocess.PIPE,
|
|
|
|
text=True)
|
|
|
|
except Exception as exc:
|
|
|
|
raise err.GenericError(f'There was an error with your command: {exc}')
|
|
|
|
|
|
|
|
return processor
|
|
|
|
|
|
|
|
def run_check_call(command: list) -> int:
|
|
|
|
"""
|
|
|
|
Runs subprocess check_call and returns an integer.
|
|
|
|
"""
|
|
|
|
env = os.environ
|
|
|
|
try:
|
|
|
|
subprocess.check_call(command, env=env)
|
|
|
|
except subprocess.CalledProcessError as exc:
|
|
|
|
sys.stderr.write(f'Run failed: {exc}\n')
|
|
|
|
return 1
|
|
|
|
return 0
|