xxh/xxh_xxh/shell.py

28 lines
621 B
Python
Raw Normal View History

2020-03-17 10:00:51 +00:00
import os
from pathlib import Path
import subprocess
def S(cmd, trace=False):
if type(cmd) == list:
cmd = ' '.join(cmd)
if trace:
print(cmd)
return os.system(cmd)
def SC(cmd):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
[out, err] = proc.communicate()
return (out, err, proc)
def A(args, q=0):
if type(args) == list:
args = ' '.join([str(a) for a in args])
if q == 1:
return f"'{args}'"
elif q == 2:
return f'"{args}"'
return str(args)
def p(path_str):
return Path(path_str).expanduser()