Exemple #1
0
def run_command(
        commands,  # type: Union[list, str]
        cwd=None,  # type: str
):
    command = commands if isinstance(commands, str) else " ".join(commands)
    with safe_chdir(cwd):
        rtn_code = os.system(command)
        if rtn_code:
            raise subprocess.CalledProcessError(rtn_code, commands)
Exemple #2
0
 def func(*args, **kwargs):
     dir_name = 'utdir_' + method.__name__
     os.makedirs(dir_name, exist_ok=True)
     try:
         with safe_chdir(dir_name):
             method(*args, **kwargs)
     except Exception as identifier:
         raise identifier
     finally:
         to_screen(f"trying to remove {dir_name}")
         # ! rmtree not work on windows
         os.system(f'rm -rf {dir_name}')