Skip to content

Instantly share code, notes, and snippets.

@OwenChia
Last active November 15, 2015 14:22
Show Gist options
  • Save OwenChia/dd0f170fe3031c26d3f0 to your computer and use it in GitHub Desktop.
Save OwenChia/dd0f170fe3031c26d3f0 to your computer and use it in GitHub Desktop.
Create a bootstrap script for Beehive
import textwrap
import virtualenv
CUSTOM = """
def extend_parser(parser):
parser.add_option(
'--use-proxy',
dest='proxy',
action='store_true',
help='Use aliyun proxy for pip.'
)
def after_install(options, home_dir):
beebeeto_framework_git = 'https://github.com/n0tr00t/Beebeeto-framework.git'
beehive_git = 'https://github.com/n0tr00t/Beehive.git'
pip_proxy_address = 'http://mirrors.aliyun.com/pypi/simple/'
pip_proxy_host = 'mirrors.aliyun.com'
bin = 'Scripts' if is_win else 'bin'
call_subprocess(
"git clone {:s} {:s}".format(
beebeeto_framework_git,
join(home_dir, 'src', 'Beebeeto-framework')
).split()
)
call_subprocess(
"git clone {:s} {:s}".format(
beehive_git,
join(home_dir, 'src', 'Beehive')
).split()
)
with open(join(home_dir, 'src', 'Beehive', 'requirements.txt')) as req:
requirements = req.read().split()
if is_win:
requirements.remove('gevent')
else:
requirements.append('readline')
for each in requirements:
if options.proxy:
call_subprocess(
"{:s} install {:s} -i {:s} --trusted-host {:s}".format(
join(home_dir, bin, 'pip'),
each,
pip_proxy_address,
pip_proxy_host
).split()
)
else:
call_subprocess(
"{:s} install {:s}".format(
join(home_dir, bin, 'pip'),
each
).split()
)
"""
output = virtualenv.create_bootstrap_script(
textwrap.dedent(CUSTOM)
)
with open('bootstrap.py', 'w') as bootstrap:
bootstrap.write(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment