mitmproxy/release/rtool.py

95 lines
2.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2015-11-29 01:46:08 +00:00
import contextlib
import os
2018-02-25 17:02:39 +00:00
import sys
import platform
import runpy
import shlex
2015-11-29 01:46:08 +00:00
import subprocess
from os.path import join, abspath, dirname
import cryptography.fernet
2015-11-29 01:46:08 +00:00
import click
2016-12-11 22:07:47 +00:00
2016-07-30 02:07:48 +00:00
ROOT_DIR = abspath(join(dirname(__file__), ".."))
RELEASE_DIR = join(ROOT_DIR, "release")
DIST_DIR = join(RELEASE_DIR, "dist")
VERSION_FILE = join(ROOT_DIR, "mitmproxy", "version.py")
2015-11-29 01:46:08 +00:00
2015-12-03 16:55:42 +00:00
def git(args: str) -> str:
with chdir(ROOT_DIR):
return subprocess.check_output(["git"] + shlex.split(args)).decode()
2017-12-26 20:53:16 +00:00
def get_version(dev: bool = False, build: bool = False) -> str:
2017-12-27 20:46:52 +00:00
x = runpy.run_path(VERSION_FILE)
return x["get_version"](dev, build, True)
2017-12-26 20:53:16 +00:00
def wheel_name() -> str:
return "mitmproxy-{version}-py3-none-any.whl".format(
2017-12-26 20:53:16 +00:00
version=get_version(True),
2015-11-29 18:05:58 +00:00
)
2015-11-29 01:46:08 +00:00
2015-12-03 16:55:42 +00:00
2015-11-29 01:46:08 +00:00
@contextlib.contextmanager
def chdir(path: str):
2015-11-29 01:46:08 +00:00
old_dir = os.getcwd()
os.chdir(path)
yield
os.chdir(old_dir)
@click.group(chain=True)
def cli():
2015-11-29 01:46:08 +00:00
"""
mitmproxy build tool
"""
pass
2015-11-29 01:46:08 +00:00
2015-12-03 16:55:42 +00:00
2015-11-29 01:46:08 +00:00
@cli.command("contributors")
def contributors():
"""
Update CONTRIBUTORS.md
"""
2016-02-15 23:22:38 +00:00
with chdir(ROOT_DIR):
print("Updating CONTRIBUTORS...")
contributors_data = git("shortlog -n -s")
with open("CONTRIBUTORS", "wb") as f:
f.write(contributors_data.encode())
2015-11-29 01:46:08 +00:00
2015-12-03 16:55:42 +00:00
2018-02-25 16:49:54 +00:00
@cli.command("homebrew-pr")
def homebrew_pr():
"""
Create a new Homebrew PR
"""
2018-02-25 17:02:39 +00:00
if platform.system() != "Darwin":
print("You need to run this on macOS to create a new Homebrew PR. Sorry.")
sys.exit(1)
2018-02-25 16:49:54 +00:00
print("Creating a new PR with Homebrew...")
subprocess.check_call([
"brew",
"bump-formula-pr",
"--url", "https://github.com/mitmproxy/mitmproxy/archive/v{}.tar.gz".format(get_version()),
2018-02-25 16:49:54 +00:00
"mitmproxy",
])
@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()))
2015-11-29 01:46:08 +00:00
if __name__ == "__main__":
cli()