summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Slome <jamie@418sec.com>2021-03-25 06:59:01 +0000
committerGitHub <noreply@github.com>2021-03-25 06:59:01 +0000
commit0fc44beac5c0a940d1ea4cd091eeaeaa6fd21fe2 (patch)
treeeac3ee44618619d4e07f5070764418930746eacf
parent8852a1b6d14ba9d6ab23f7cf8be32830040029a1 (diff)
downloadswig-0fc44beac5c0a940d1ea4cd091eeaeaa6fd21fe2.tar.gz
Create utils.py
-rw-r--r--Tools/utils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Tools/utils.py b/Tools/utils.py
new file mode 100644
index 000000000..496882f19
--- /dev/null
+++ b/Tools/utils.py
@@ -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)