summaryrefslogtreecommitdiff
path: root/tools/util.py
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-07-08 02:24:29 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-07-08 13:40:18 -0400
commitf917c5e722d7ee5abd58704eb0e5d49072249e94 (patch)
tree48eb2e95d18c9d1fbdfcd0864ca09a6e64d79f5a /tools/util.py
parent6c79b471aa5cf2c87d237015f5dacc5a7ed03b67 (diff)
Clean up tools/
- Factor out tools/util.py - Move js/*.py to tools. - Rewrite tools/format.sh in python. - Run lint first in travis.
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()