33 lines
686 B
Python
33 lines
686 B
Python
|
|
import sys as _sys
|
||
|
|
import os as _os
|
||
|
|
|
||
|
|
from string import *
|
||
|
|
|
||
|
|
|
||
|
|
def execute(
|
||
|
|
command,
|
||
|
|
options = None
|
||
|
|
):
|
||
|
|
options = (
|
||
|
|
{
|
||
|
|
"directory": None,
|
||
|
|
"show": False,
|
||
|
|
"run": True,
|
||
|
|
}
|
||
|
|
|
|
||
|
|
(options or {})
|
||
|
|
)
|
||
|
|
command_complete = string_wrap(
|
||
|
|
command,
|
||
|
|
string_coin("cd {{directory}} && ", {"directory": (options["directory"] or "")}),
|
||
|
|
string_coin(" ; cd - > /dev/null", {}),
|
||
|
|
{
|
||
|
|
"mode": (not (options["directory"] is None))
|
||
|
|
}
|
||
|
|
)
|
||
|
|
if (options["show"]):
|
||
|
|
_sys.stderr.write(">> %s\n" % command_complete)
|
||
|
|
if (options["run"]):
|
||
|
|
_os.system(command_complete)
|
||
|
|
|