scripts: Use run_as_root instead of run([sudo, ...]).

This commit is contained in:
Rohitt Vashishtha
2019-02-26 19:20:46 +00:00
committed by Tim Abbott
parent 9038230de8
commit ac48925977
4 changed files with 55 additions and 45 deletions

View File

@@ -419,6 +419,13 @@ def is_root() -> bool:
return True
return False
def run_as_root(args, **kwargs):
# type: (List[str], **Any) -> None
sudo_args = kwargs.pop('sudo_args', [])
if not is_root():
args = ['sudo'] + sudo_args + ['--'] + args
run(args, **kwargs)
def assert_not_running_as_root() -> None:
script_name = os.path.abspath(sys.argv[0])
if is_root():