-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_deps
86 lines (66 loc) · 3.05 KB
/
install_deps
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
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
import os
import subprocess
import shutil
import stat
import platform
from StringIO import StringIO
from zipfile import ZipFile
from urllib import urlopen
REQUIREMENTS = [ "pip", "git" ]
FILES_IGNORED_FOR_DELETION = [ "google_appengine" ]
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
REQUIREMENTS_FILE = os.path.join(PROJECT_DIR, "requirements.txt")
TARGET_DIR = os.path.join(PROJECT_DIR, "sitepackages")
APPENGINE_TARGET_DIR = os.path.join(TARGET_DIR, "google_appengine")
APPENGINE_SDK_VERSION = "1.9.19"
APPENGINE_SDK_FILENAME = "google_appengine_%s.zip" % APPENGINE_SDK_VERSION
# Google move versions from 'featured' to 'deprecated' when they bring
# out new releases
FEATURED_SDK_REPO = "https://storage.googleapis.com/appengine-sdks/featured/"
DEPRECATED_SDK_REPO = "https://storage.googleapis.com/appengine-sdks/deprecated/%s/" % APPENGINE_SDK_VERSION.replace('.', '')
if __name__ == "__main__":
#Make sure the user has everything they need
where = 'which'
if platform.system() == 'Windows':
where = 'where'
for command in REQUIREMENTS:
try:
subprocess.check_output([where, command])
except subprocess.CalledProcessError:
raise RuntimeError("You must install the '%s' command" % command)
if not os.path.exists(TARGET_DIR):
print('Creating `sitepackages` directory for dependencies...')
os.makedirs(TARGET_DIR)
if not os.path.exists(APPENGINE_TARGET_DIR):
print('Downloading the AppEngine SDK...')
#First try and get it from the 'featured' folder
sdk_file = urlopen(FEATURED_SDK_REPO + APPENGINE_SDK_FILENAME)
if sdk_file.getcode() == 404:
#Failing that, 'deprecated'
sdk_file = urlopen(DEPRECATED_SDK_REPO + APPENGINE_SDK_FILENAME)
#Handle other errors
if sdk_file.getcode() >= 299:
raise Exception('App Engine SDK could not be found. {} returned code {}.'.format(sdk_file.geturl(), sdk_file.getcode()))
zipfile = ZipFile(StringIO(sdk_file.read()))
zipfile.extractall(TARGET_DIR)
#Make sure the dev_appserver and appcfg are executable
for module in ("dev_appserver.py", "appcfg.py"):
app = os.path.join(APPENGINE_TARGET_DIR, module)
st = os.stat(app)
os.chmod(app, st.st_mode | stat.S_IEXEC)
else:
print('Not updating SDK as it exists. Remove {} and re-run to get the latest SDK'.format(APPENGINE_TARGET_DIR))
#Remove all folders and files, we leave symlinks as they will be pointing
#to submodules
filenames = (filename for filename in os.listdir(TARGET_DIR) if filename not in FILES_IGNORED_FOR_DELETION)
for filename in filenames:
path = os.path.join(TARGET_DIR, filename)
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path)
elif os.path.isfile(path):
os.remove(path)
print("Running pip...")
args = ["pip", "install", "-r", REQUIREMENTS_FILE, "-t", TARGET_DIR, "-I"]
p = subprocess.Popen(args)
p.wait()