1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/env python
from __future__ import print_function
import os
import shutil
import glob
import time
import subprocess
import sys
def subprocess_with_print(command):
print(command)
return subprocess.call(command, shell=True)
def get_venv_python(venv_path):
python_linux = os.path.join(venv_path, 'bin/python')
python_windows = os.path.join(venv_path, 'Scripts\\python.exe')
if os.path.isfile(python_linux):
return python_linux
if os.path.isfile(python_windows):
return python_windows
raise ValueError((
'Error, could not find python executable in venv path {0}: is it a valid venv ?'
.format(venv_path)))
def main(venv_name, venv_args, args):
for path in glob.glob('*.egg-info'):
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
if os.path.isdir(venv_name):
os.rename(venv_name, '{0}.{1}.bak'.format(venv_name, int(time.time())))
exit_code = 0
exit_code = subprocess_with_print(' '.join([
sys.executable, '-m', 'virtualenv', '--no-site-packages', '--setuptools',
venv_name, venv_args])) or exit_code
python_executable = get_venv_python(venv_name)
exit_code = subprocess_with_print(' '.join([
python_executable, os.path.normpath('./letsencrypt-auto-source/pieces/pipstrap.py')]))
command = [python_executable, os.path.normpath('./tools/pip_install.py')] or exit_code
command.extend(args)
exit_code = subprocess_with_print(' '.join(command)) or exit_code
if os.path.isdir(os.path.join(venv_name, 'bin')):
# Linux/OSX specific
print('-------------------------------------------------------------------')
print('Please run the following command to activate developer environment:')
print('source {0}/bin/activate'.format(venv_name))
print('-------------------------------------------------------------------')
elif os.path.isdir(os.path.join(venv_name, 'Scripts')):
# Windows specific
print('---------------------------------------------------------------------------')
print('Please run one of the following commands to activate developer environment:')
print('{0}\\bin\\activate.bat (for Batch)'.format(venv_name))
print('.\\{0}\\Scripts\\Activate.ps1 (for Powershell)'.format(venv_name))
print('---------------------------------------------------------------------------')
else:
raise ValueError('Error, directory {0} is not a valid venv.'.format(venv_name))
return exit_code
if __name__ == '__main__':
sys.exit(main(os.environ.get('VENV_NAME', 'venv'),
os.environ.get('VENV_ARGS', ''),
sys.argv[1:]))
|