From 980a84326bf2daa398b201fd3722696476c4913d Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 11 Dec 2016 23:07:47 +0100 Subject: InstallBuilder (#1826) --- .appveyor.yml | 28 ++++- release/hooks/hook-cryptography.py | 3 +- release/hooks/hook-pydivert.py | 2 +- release/installbuilder/.gitignore | 2 + release/installbuilder/license.xml.enc | 1 + release/installbuilder/logo-installer-icon.png | Bin 0 -> 4506 bytes release/installbuilder/logo-installer.png | Bin 0 -> 39467 bytes release/installbuilder/logo.ico | Bin 0 -> 98065 bytes release/installbuilder/mitmproxy.xml | 135 +++++++++++++++++++++++++ release/rtool.py | 52 ++++++++-- release/setup.py | 1 + setup.cfg | 2 +- tox.ini | 4 +- 13 files changed, 216 insertions(+), 14 deletions(-) create mode 100644 release/installbuilder/.gitignore create mode 100644 release/installbuilder/license.xml.enc create mode 100644 release/installbuilder/logo-installer-icon.png create mode 100644 release/installbuilder/logo-installer.png create mode 100644 release/installbuilder/logo.ico create mode 100644 release/installbuilder/mitmproxy.xml diff --git a/.appveyor.yml b/.appveyor.yml index 5cf194a9..b95b23e3 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,6 +16,8 @@ environment: secure: 6yBwmO5gv4vAwoFYII8qjQ== SNAPSHOT_PASS: secure: LPjrtFrWxYhOVGXzfPRV1GjtZE/wHoKq9m/PI6hSalfysUK5p2DxTG9uHlb4Q9qV + RTOOL_KEY: + secure: 0a+UUNbA+JjquyAbda4fd0JmiwL06AdG6torRPdCvbPDbKHnaW/BHHp1nRPytOKM install: - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" @@ -30,6 +32,29 @@ test_script: tox -e wheel tox -e rtool -- bdist + - ps: | + if( + ($Env:TOXENV -match "py35") -and + (($Env:APPVEYOR_REPO_BRANCH -In ("master", "pyinstaller")) -or ($Env:APPVEYOR_REPO_TAG -match "true")) + ) { + tox -e rtool -- decrypt release\installbuilder\license.xml.enc release\installbuilder\license.xml + if (!(Test-Path "C:\projects\mitmproxy\release\installbuilder-installer.exe")) { + "Download InstallBuilder..." + (New-Object System.Net.WebClient).DownloadFile( + "https://installbuilder.bitrock.com/installbuilder-enterprise-16.11.1-windows-installer.exe", + "C:\projects\mitmproxy\release\installbuilder-installer.exe" + ) + } + Start-Process "C:\projects\mitmproxy\release\installbuilder-installer.exe" "--mode unattended --unattendedmodeui none" -Wait + & 'C:\Program Files (x86)\BitRock InstallBuilder Enterprise 16.11.1\bin\builder-cli.exe' ` + build ` + .\release\installbuilder\mitmproxy.xml ` + windows ` + --license .\release\installbuilder\license.xml ` + --setvars project.version=$Env:VERSION ` + --verbose + } + deploy_script: # we build binaries on every run, but we only upload them for master snapshots or tags. ps: | @@ -37,10 +62,11 @@ deploy_script: ($Env:TOXENV -match "py35") -and (($Env:APPVEYOR_REPO_BRANCH -In ("master", "pyinstaller")) -or ($Env:APPVEYOR_REPO_TAG -match "true")) ) { - tox -e rtool -- upload-snapshot --bdist --wheel + tox -e rtool -- upload-snapshot --bdist --wheel --installer } cache: + - C:\projects\mitmproxy\release\installbuilder-installer.exe -> .appveyor.yml - C:\Users\appveyor\AppData\Local\pip\cache notifications: diff --git a/release/hooks/hook-cryptography.py b/release/hooks/hook-cryptography.py index d53a438b..5ecbd6cc 100644 --- a/release/hooks/hook-cryptography.py +++ b/release/hooks/hook-cryptography.py @@ -1,4 +1,5 @@ # Taken from the latest pyinstaller master on 2016-11-27 (0729a2b). +# flake8: noqa #----------------------------------------------------------------------------- # Copyright (c) 2005-2016, PyInstaller Development Team. @@ -40,4 +41,4 @@ cryptography_dir = os.path.dirname(get_module_file_attribute('cryptography')) for ext in EXTENSION_SUFFIXES: ffimods = glob.glob(os.path.join(cryptography_dir, '*_cffi_*%s*' % ext)) for f in ffimods: - binaries.append((f, 'cryptography')) \ No newline at end of file + binaries.append((f, 'cryptography')) diff --git a/release/hooks/hook-pydivert.py b/release/hooks/hook-pydivert.py index 3fe8c552..72b7eb7d 100644 --- a/release/hooks/hook-pydivert.py +++ b/release/hooks/hook-pydivert.py @@ -1,3 +1,3 @@ from PyInstaller.utils.hooks import collect_data_files -datas = collect_data_files('pydivert.windivert_dll') \ No newline at end of file +datas = collect_data_files('pydivert.windivert_dll') diff --git a/release/installbuilder/.gitignore b/release/installbuilder/.gitignore new file mode 100644 index 00000000..00c10a2d --- /dev/null +++ b/release/installbuilder/.gitignore @@ -0,0 +1,2 @@ +license.xml +*.xml.backup \ No newline at end of file diff --git a/release/installbuilder/license.xml.enc b/release/installbuilder/license.xml.enc new file mode 100644 index 00000000..3df7210a --- /dev/null +++ b/release/installbuilder/license.xml.enc @@ -0,0 +1 @@ +gAAAAABYSXtgysddnqWL5sAreDTENJZdFkEf9p2nfMZTynY2hEep8vIDwR0P1glL40C04kLUv3piHkqyz0I893b-_YpnZC-W7qwfhChoFxnAQd0NY_d1mLsCHF1nQK0k907IbextZ3XHSCqSkS2nw0S41p9sEbzWLludSRRqJRn-AmxAKdm5s43kheNpP5iArWKtBrtubgytIDanulTfibdAPHaZedyx3JDww3hIUgo2shird7L4q2xQsE0bBDBgGrlndZ6lYGJDKf600LpOPSzSON6uXdPefhPD1bZP0GAFTNMAkm0K39e9J-j9Xz5ao7bEswfR6pcYO1uQC9VmxJYdLkuY9vYiltED6m5dW--NXVx0pudr_e5BXfpT5-RdUHaGM0Od6EZggeD5PNgUtWXxmXd6C0gFBZZEx_KobDXrCD9s8tmRJjb3ACBSCh2NdfFCCfOU3JRHeSgANTDYzY0pcJicoE5UcvP2dEICVvEORwbTumtfWbuDSbXwHqcynVjkJbwxHhRMMeJtjnx4dbb6_wdp2RjOUilTb2ob40OWyU0szgpSe2-5XS_F7ixL7vMf00OHFtTDk0Wg_dv15IR3C-zK8WFWEr4b4POc1P6pRrKOLKIFIKBGGZWF-S-u3gedAL2VLpFoUCG5FMnnJGv2iNfNYkG20zObn9K6FG5uNq6T0ZvfJIjJYNvXV45mx7jhOg2R5HAkZXlx16iIv95qlHIvJR6UZKHqWr_Hp3YvaxatkqbFwpXxQU0xtMJO3dXafATFMW_l \ No newline at end of file diff --git a/release/installbuilder/logo-installer-icon.png b/release/installbuilder/logo-installer-icon.png new file mode 100644 index 00000000..c39541bb Binary files /dev/null and b/release/installbuilder/logo-installer-icon.png differ diff --git a/release/installbuilder/logo-installer.png b/release/installbuilder/logo-installer.png new file mode 100644 index 00000000..42de543d Binary files /dev/null and b/release/installbuilder/logo-installer.png differ diff --git a/release/installbuilder/logo.ico b/release/installbuilder/logo.ico new file mode 100644 index 00000000..8e08e8cc Binary files /dev/null and b/release/installbuilder/logo.ico differ diff --git a/release/installbuilder/mitmproxy.xml b/release/installbuilder/mitmproxy.xml new file mode 100644 index 00000000..e4ad00a3 --- /dev/null +++ b/release/installbuilder/mitmproxy.xml @@ -0,0 +1,135 @@ + + mitmproxy + mitmproxy + 1.0 + logo-installer.png + logo-installer-icon.png + + + default + Default Component + 1 + 1 + 1 + + + Program Files + ${installdir} + programfiles + all + + + logo.ico + + + + + Program Files/bin + ${installdir}/bin + binaries + all + + + 1 + */patho* + ../build/binaries/${platform_name}/* + + + + + + + end + ${installdir}/bin + user + + + + + ${installdir}/bin + user + + + + + + mitmproxy ui + 0 + 0 + ${installdir}\bin\mitmweb.exe + + ${installdir}/logo.ico + ${installdir} + + + + mitmdump + 0 + 0 + ${installdir}\bin\mitmdump.exe + + ${installdir}/logo.ico + ${installdir} + + + + + 1 + 1 + 1 + 1 + ../dist + logo.ico + 1 + mitmproxy.org + logo.ico + + + cmd + /c start "mitmproxy ui" "${installdir}\bin\mitmweb.exe" & + Launch mitmproxy ui now + + + windows + + + + + ${installdir}/mitmproxy + & + Launch mitmproxy now + + + 1 + windows + + + + + + + installdir + Installer.Parameter.installdir.description + Installer.Parameter.installdir.explanation + + ${platform_install_prefix}/${product_shortname} + 0 + yes + prefix + yes + 0 + 40 + + + + + + + ui.button(next).text + ${msg(Installer.Button.Install)} + + + + + + diff --git a/release/rtool.py b/release/rtool.py index 4a6d1e16..59899510 100755 --- a/release/rtool.py +++ b/release/rtool.py @@ -13,6 +13,7 @@ import zipfile from os.path import join, abspath, dirname, exists, basename import click +import cryptography.fernet import pysftp # https://virtualenv.pypa.io/en/latest/userguide.html#windows-notes @@ -37,6 +38,12 @@ else: def Archive(name): return tarfile.open(name, "w:gz") +PLATFORM_TAG = { + "Darwin": "osx", + "Windows": "windows", + "Linux": "linux", +}.get(platform.system(), platform.system()) + ROOT_DIR = abspath(join(dirname(__file__), "..")) RELEASE_DIR = join(ROOT_DIR, "release") @@ -47,7 +54,7 @@ PYINSTALLER_SPEC = join(RELEASE_DIR, "specs") # PyInstaller 3.2 does not bundle pydivert's Windivert binaries PYINSTALLER_HOOKS = join(RELEASE_DIR, "hooks") PYINSTALLER_TEMP = join(BUILD_DIR, "pyinstaller") -PYINSTALLER_DIST = join(BUILD_DIR, "binaries") +PYINSTALLER_DIST = join(BUILD_DIR, "binaries", PLATFORM_TAG) VENV_DIR = join(BUILD_DIR, "venv") @@ -91,11 +98,6 @@ def get_snapshot_version() -> str: def archive_name(bdist: str) -> str: - platform_tag = { - "Darwin": "osx", - "Windows": "win32", - "Linux": "linux" - }.get(platform.system(), platform.system()) if platform.system() == "Windows": ext = "zip" else: @@ -103,7 +105,7 @@ def archive_name(bdist: str) -> str: return "{project}-{version}-{platform}.{ext}".format( project=bdist, version=get_version(), - platform=platform_tag, + platform=PLATFORM_TAG, ext=ext ) @@ -114,6 +116,19 @@ def wheel_name() -> str: ) +def installer_name() -> str: + ext = { + "Windows": "exe", + "Darwin": "dmg", + "Linux": "run" + }[platform.system()] + return "mitmproxy-{version}-{platform}-installer.{ext}".format( + version=get_version(), + platform=PLATFORM_TAG, + ext=ext, + ) + + @contextlib.contextmanager def chdir(path: str): old_dir = os.getcwd() @@ -130,6 +145,24 @@ def cli(): pass +@cli.command("encrypt") +@click.argument('infile', type=click.File('rb')) +@click.argument('outfile', type=click.File('wb')) +@click.argument('key', envvar='RTOOL_KEY') +def encrypt(infile, outfile, key): + f = cryptography.fernet.Fernet(key.encode()) + outfile.write(f.encrypt(infile.read())) + + +@cli.command("decrypt") +@click.argument('infile', type=click.File('rb')) +@click.argument('outfile', type=click.File('wb')) +@click.argument('key', envvar='RTOOL_KEY') +def decrypt(infile, outfile, key): + f = cryptography.fernet.Fernet(key.encode()) + outfile.write(f.decrypt(infile.read())) + + @cli.command("contributors") def contributors(): """ @@ -238,7 +271,8 @@ def upload_release(username, password, repository): @click.option("--private-key-password", envvar="SNAPSHOT_PASS", prompt=True, hide_input=True) @click.option("--wheel/--no-wheel", default=False) @click.option("--bdist/--no-bdist", default=False) -def upload_snapshot(host, port, user, private_key, private_key_password, wheel, bdist): +@click.option("--installer/--no-installer", default=False) +def upload_snapshot(host, port, user, private_key, private_key_password, wheel, bdist, installer): """ Upload snapshot to snapshot server """ @@ -256,6 +290,8 @@ def upload_snapshot(host, port, user, private_key, private_key_password, wheel, if bdist: for bdist in sorted(BDISTS.keys()): files.append(archive_name(bdist)) + if installer: + files.append(installer_name()) for f in files: local_path = join(DIST_DIR, f) diff --git a/release/setup.py b/release/setup.py index 1d60e46c..01d0672d 100644 --- a/release/setup.py +++ b/release/setup.py @@ -8,6 +8,7 @@ setup( "click>=6.2, <7.0", "twine>=1.6.5, <1.9", "pysftp==0.2.8", + "cryptography>=1.6, <1.7", ], entry_points={ "console_scripts": [ diff --git a/setup.cfg b/setup.cfg index 305560a6..39148f98 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ max-line-length = 140 max-complexity = 25 ignore = E251,C901,W503 -exclude = mitmproxy/contrib/*,test/mitmproxy/data/* +exclude = mitmproxy/contrib/*,test/mitmproxy/data/*,release/build/* addons = file,open,basestring,xrange,unicode,long,cmp [tool:pytest] diff --git a/tox.ini b/tox.ini index cc06f9c8..673283aa 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ basepython = python3.5 deps = {env:CI_DEPS:} -rrequirements.txt -passenv = CODECOV_TOKEN CI CI_* TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* SNAPSHOT_* OPENSSL_* +passenv = CODECOV_TOKEN CI CI_* TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* SNAPSHOT_* OPENSSL_* RTOOL_* setenv = HOME = {envtmpdir} commands = mitmdump --sysinfo @@ -22,7 +22,7 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html [testenv:lint] commands = mitmdump --sysinfo - flake8 --jobs 8 --count mitmproxy pathod examples test + flake8 --jobs 8 --count mitmproxy pathod examples test release rstcheck README.rst mypy --silent-imports \ mitmproxy/addons \ -- cgit v1.2.3