summaryrefslogtreecommitdiff
path: root/tools/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/util.py')
-rw-r--r--tools/util.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/util.py b/tools/util.py
new file mode 100644
index 000000000..1d44acd48
--- /dev/null
+++ b/tools/util.py
@@ -0,0 +1,42 @@
+# Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
+# All rights reserved. MIT License.
+import os
+import subprocess
+
+
+def run(args):
+ print " ".join(args)
+ env = os.environ.copy()
+ subprocess.check_call(args, env=env)
+
+
+def remove_and_symlink(target, name, target_is_dir=False):
+ try:
+ os.unlink(name)
+ except:
+ pass
+ symlink(target, name, target_is_dir)
+
+
+def symlink(target, name, target_is_dir=False):
+ if os.name == "nt":
+ import ctypes
+ CreateSymbolicLinkW = ctypes.windll.kernel32.CreateSymbolicLinkW
+ CreateSymbolicLinkW.restype = ctypes.c_ubyte
+ CreateSymbolicLinkW.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p,
+ ctypes.c_uint32)
+
+ flags = 0x02 # SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
+ if (target_is_dir):
+ flags |= 0x01 # SYMBOLIC_LINK_FLAG_DIRECTORY
+ if not CreateSymbolicLinkW(name, target, flags):
+ raise ctypes.WinError()
+ else:
+ os.symlink(target, name)
+
+
+def touch(fname):
+ if os.path.exists(fname):
+ os.utime(fname, None)
+ else:
+ open(fname, 'a').close()