1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2025-12-07 09:03:06 +00:00
kiwi-scp/src/kiwi/subcommands/utils/dockercommand.py

37 lines
1,017 B
Python
Raw Normal View History

import subprocess
from .executable import Executable
2020-08-10 15:40:56 +00:00
class DockerCommand:
__requires_root = None
__exe = None
def __init__(self, exe_name):
2020-08-10 15:40:56 +00:00
if DockerCommand.__requires_root is None:
try:
Executable('docker').run(
['ps'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
2020-08-10 15:40:56 +00:00
DockerCommand.__requires_root = False
except subprocess.CalledProcessError:
2020-08-10 15:40:56 +00:00
DockerCommand.__requires_root = True
self.__exe = Executable(exe_name, DockerCommand.__requires_root)
def __getattr__(self, item):
return getattr(self.__exe, item)
def run_less(self, args, **kwargs):
process = self.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
**kwargs
)
less_process = Executable('less').run(
['-R', '+G'], stdin=process.stdout
)
process.communicate()
return less_process