diff options
Diffstat (limited to 'Master/texmf-dist/scripts/webquiz/webquiz_util.py')
-rwxr-xr-x | Master/texmf-dist/scripts/webquiz/webquiz_util.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz_util.py b/Master/texmf-dist/scripts/webquiz/webquiz_util.py index 7a06108e1b0..ea2e6e7b179 100755 --- a/Master/texmf-dist/scripts/webquiz/webquiz_util.py +++ b/Master/texmf-dist/scripts/webquiz/webquiz_util.py @@ -33,9 +33,11 @@ def shell_command(cmd): def kpsewhich(search): r''' - Short-cut to access kpsewhich output. usage: kpsewhich('-var-value=TEXMFLOCAL') + Short-cut to access kpsewhich output. + + usage: kpsewhich('-var-value=TEXMFLOCAL') ''' - return subprocess.check_output('kpsewhich ' + search, stderr=subprocess.STDOUT, shell=True).decode('ascii').strip() + return subprocess.check_output('kpsewhich ' + search, shell=True).decode('ascii').strip() # --------------------------------------------------------------------------------------- class MetaData(dict): @@ -126,3 +128,34 @@ def copytree(src, dst, symlinks=False, ignore=None): copytree(s, d, symlinks, ignore) else: shutil.copy2(s, d) + +############################################################################### +## shortcuts for running commands +environ = os.environ.copy() + +def run(cmd, shell=False): + r''' + Run commands with output to stdout and errors to stderr + ''' + if shell: + subprocess.call(cmd, env=environ, shell=True) + else: + subprocess.call(cmd.split(), env=environ) + +def quiet_run(cmd, shell=False): + r''' + Run commands with ignoring and sending errors to stderr + ''' + if shell: + subprocess.call(cmd, env=environ, stdout=open(os.devnull, 'wb'), shell=True) + else: + subprocess.call(cmd.split(), env=environ, stdout=open(os.devnull, 'wb')) + +def silent_run(cmd, shell=False): + r''' + Run commands ignoring all output and errors + ''' + if shell: + subprocess.call(cmd, env=environ, stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'), shell=True) + else: + subprocess.call(cmd.split(), env=environ, stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb')) |