| 1 |
import os |
| 2 |
import sys |
| 3 |
|
| 4 |
if os.name != "nt": |
| 5 |
sys.exit("Error: ship scripts require native Python 2.7. (wrong os.name)") |
| 6 |
if sys.version_info[0:2] != (2,7): |
| 7 |
sys.exit("Error: ship scripts require native Python 2.7. (wrong version)") |
| 8 |
|
| 9 |
import glob |
| 10 |
import shutil |
| 11 |
import subprocess |
| 12 |
from distutils.spawn import find_executable |
| 13 |
|
| 14 |
topDir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
| 15 |
|
| 16 |
with open(topDir + "/VERSION.txt", "rt") as f: |
| 17 |
winptyVersion = f.read().strip() |
| 18 |
|
| 19 |
def rmrf(patterns): |
| 20 |
for pattern in patterns: |
| 21 |
for path in glob.glob(pattern): |
| 22 |
if os.path.isdir(path) and not os.path.islink(path): |
| 23 |
print "+ rm -r " + path |
| 24 |
sys.stdout.flush() |
| 25 |
shutil.rmtree(path) |
| 26 |
elif os.path.isfile(path): |
| 27 |
print "+ rm " + path |
| 28 |
sys.stdout.flush() |
| 29 |
os.remove(path) |
| 30 |
|
| 31 |
def mkdir(path): |
| 32 |
if not os.path.isdir(path): |
| 33 |
os.makedirs(path) |
| 34 |
|
| 35 |
def requireExe(name, guesses): |
| 36 |
if find_executable(name) is None: |
| 37 |
for guess in guesses: |
| 38 |
if os.path.exists(guess): |
| 39 |
newDir = os.path.dirname(guess) |
| 40 |
print "Adding " + newDir + " to Path to provide " + name |
| 41 |
os.environ["Path"] = newDir + ";" + os.environ["Path"] |
| 42 |
ret = find_executable(name) |
| 43 |
if ret is None: |
| 44 |
sys.exit("Error: required EXE is missing from Path: " + name) |
| 45 |
return ret |
| 46 |
|
| 47 |
requireExe("git.exe", [ |
| 48 |
"C:\\Program Files\\Git\\cmd\\git.exe", |
| 49 |
"C:\\Program Files (x86)\\Git\\cmd\\git.exe" |
| 50 |
]) |
| 51 |
|
| 52 |
commitHash = subprocess.check_output(["git.exe", "rev-parse", "HEAD"]).decode().strip() |
| 53 |
defaultPathEnviron = "C:\\Windows\\System32;C:\\Windows" |