Steve Dower | bb24087 | 2015-02-05 22:08:48 -0800 | [diff] [blame] | 1 | ''' |
| 2 | Downloads and extracts WiX to a local directory |
| 3 | ''' |
| 4 | |
| 5 | __author__ = 'Steve Dower <steve.dower@microsoft.com>' |
| 6 | |
| 7 | import io |
| 8 | import os |
| 9 | import sys |
| 10 | |
| 11 | from pathlib import Path |
| 12 | from subprocess import Popen |
| 13 | from zipfile import ZipFile |
| 14 | |
| 15 | EXTERNALS_DIR = None |
| 16 | for p in Path(__file__).parents: |
| 17 | if any(p.glob("PCBuild/*.vcxproj")): |
| 18 | EXTERNALS_DIR = p / "externals" |
| 19 | break |
| 20 | |
| 21 | if not EXTERNALS_DIR: |
| 22 | print("Cannot find project root") |
| 23 | sys.exit(1) |
| 24 | |
Steve Dower | e9ae834 | 2015-03-20 22:05:33 -0700 | [diff] [blame] | 25 | WIX_BINARIES_ZIP = 'http://wixtoolset.org/downloads/v3.10.0.1519/wix310-binaries.zip' |
Steve Dower | bb24087 | 2015-02-05 22:08:48 -0800 | [diff] [blame] | 26 | TARGET_BIN_ZIP = EXTERNALS_DIR / "wix.zip" |
| 27 | TARGET_BIN_DIR = EXTERNALS_DIR / "wix" |
| 28 | |
| 29 | POWERSHELL_COMMAND = "[IO.File]::WriteAllBytes('{}', (Invoke-WebRequest {} -UseBasicParsing).Content)" |
| 30 | |
| 31 | if __name__ == '__main__': |
| 32 | if TARGET_BIN_DIR.exists() and any(TARGET_BIN_DIR.glob("*")): |
| 33 | print('WiX is already installed') |
| 34 | sys.exit(0) |
| 35 | |
| 36 | try: |
| 37 | TARGET_BIN_DIR.mkdir() |
| 38 | except FileExistsError: |
| 39 | pass |
| 40 | |
| 41 | print('Downloading WiX to', TARGET_BIN_ZIP) |
| 42 | p = Popen(["powershell.exe", "-Command", POWERSHELL_COMMAND.format(TARGET_BIN_ZIP, WIX_BINARIES_ZIP)]) |
| 43 | p.wait() |
| 44 | print('Extracting WiX to', TARGET_BIN_DIR) |
| 45 | with ZipFile(str(TARGET_BIN_ZIP)) as z: |
| 46 | z.extractall(str(TARGET_BIN_DIR)) |
| 47 | TARGET_BIN_ZIP.unlink() |
| 48 | |
| 49 | print('Extracted WiX') |