This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
install_deps
executable file
·108 lines (86 loc) · 3.86 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
"""
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
"""
import os
import subprocess
import shutil
import stat
import platform
from StringIO import StringIO
from zipfile import ZipFile
# Does not with python27
# http://stackoverflow.com/questions/31601238/python-2-7-10-error-from-urllib-request-import-urlopen-no-module-named-request
# from urllib import urlopen
from urllib2 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.33"
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()