Last active
August 22, 2019 07:23
-
-
Save a-recknagel/23e1cfd2061e4cf4203a8cc3d9f5c5c8 to your computer and use it in GitHub Desktop.
change pipes in idle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from subprocess import run, PIPE, STDOUT | |
# set pipes | |
IN_IDLE = 'idlelib' in sys.modules | |
if IN_IDLE: | |
STD_OUT = PIPE | |
STD_ERR = STDOUT | |
else: | |
STD_OUT = sys.stdout | |
STD_ERR = sys.stderr | |
def apt_install(pkgs): | |
cmd = ['pkexec', 'apt-get', 'install', '-y'] + pkgs | |
print('Running command: {}'.format(' '.join(cmd))) | |
result = run( | |
cmd, | |
stdout=STD_OUT, | |
stderr=STD_ERR, | |
encoding='utf8', | |
env={**os.environ, 'DEBIAN_FRONTEND': 'noninteractive'} | |
) | |
if IN_IDLE: | |
print("".join(result.stdout)) | |
print(f"Executed command: {result.args}") | |
result.check_returncode() | |
def accept_eula(): | |
cmd = 'echo msttcorefonts msttcorefonts/{}-mscorefonts-eula {} | pkexec debconf-set-selections' | |
read = run(cmd.format("present", "note ''"), stdout=STD_OUT, stderr=STD_ERR, shell=True) | |
accept = run(cmd.format("accepted", "select true"), stdout=STD_OUT, stderr=STD_ERR, shell=True) | |
if IN_IDLE: | |
print("".join(read.stdout)) | |
print("".join(accept.stdout)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment