Create utils.py
This commit is contained in:
parent
8852a1b6d1
commit
0fc44beac5
1 changed files with 26 additions and 0 deletions
26
Tools/utils.py
Normal file
26
Tools/utils.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import os, subprocess
|
||||
|
||||
|
||||
def check_file_exists(path):
|
||||
"""
|
||||
Checks if a file exists or not.
|
||||
"""
|
||||
return os.path.isfile(path)
|
||||
|
||||
|
||||
def check_dir_exists(path):
|
||||
"""
|
||||
Checks if a folder exists or not.
|
||||
"""
|
||||
return os.path.isdir(path)
|
||||
|
||||
|
||||
def run_command(*args, **kwargs):
|
||||
"""
|
||||
Runs an os command using subprocess module.
|
||||
"""
|
||||
redirect_out = list(map(str.strip, " ".join(args).split(" > ")))
|
||||
if len(redirect_out) > 1:
|
||||
args, filepath = redirect_out[0].split(), redirect_out[-1]
|
||||
kwargs.update(stdout=open(filepath, "w"))
|
||||
return subprocess.call(args, **kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue