From f917c5e722d7ee5abd58704eb0e5d49072249e94 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 8 Jul 2018 02:24:29 -0400 Subject: Clean up tools/ - Factor out tools/util.py - Move js/*.py to tools. - Rewrite tools/format.sh in python. - Run lint first in travis. --- tools/util.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/util.py (limited to 'tools/util.py') 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 +# 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() -- cgit v1.2.3