-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathappengine.py
More file actions
133 lines (101 loc) · 3.78 KB
/
Copy pathappengine.py
File metadata and controls
133 lines (101 loc) · 3.78 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import shutil
import shlex
import subprocess
from google.appengine.tools import appcfg
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.urlresolvers import get_callable
from ... import PROJECT_DIR
PRE_UPDATE_HOOK = getattr(
settings, 'APPENGINE_PRE_UPDATE', 'appengine_hooks.pre_update'
)
POST_UPDATE_HOOK = getattr(
settings, 'APPENGINE_POST_UPDATE', 'appengine_hooks.post_update'
)
APPENGINE_VIRTUALENV = getattr(
settings, 'APPENGINE_VIRTUALENV', '.appengine'
)
APPENGINE_REQUIREMENTS_FILE = getattr(
settings, 'APPENGINE_REQUIREMENTS_FILE', 'requirements.txt'
)
requirements_file = os.path.join(
PROJECT_DIR, APPENGINE_REQUIREMENTS_FILE
)
# requirements file defaults to django root or same as settings dir
# you can override this in your settings file by setting:
if hasattr(settings, 'APPENGINE_REQUIREMENTS_FILE'):
requirements_file = getattr(settings, 'APPENGINE_REQUIREMENTS_FILE')
virtualenv = os.path.join(PROJECT_DIR, APPENGINE_VIRTUALENV)
virtualenv_cache = os.path.join(virtualenv, 'cache')
virtualenv_appengine_libs = os.path.join(virtualenv, 'appengine_libs')
rocket_engine_path = os.path.abspath(
os.path.join(__file__, '../../../')
)
appengine_libs = os.path.join(PROJECT_DIR, 'appengine_libs')
appengine_rocket_engine = os.path.join(PROJECT_DIR, 'rocket_engine')
pip_command = os.path.join(virtualenv, 'bin', 'pip')
python_command = os.path.join(virtualenv, 'bin', 'python')
class Command(BaseCommand):
"""Wrapper for appcfg.py with pre-update and post-update hooks"""
help = 'Calls appcfg.py for the current project.'
args = '[any options that normally would be applied to appcfg.py]'
def install_requirements(self):
if not os.path.exists(virtualenv):
subprocess.Popen(
shlex.split('virtualenv %s --distribute' % virtualenv),
).wait()
if not os.path.exists(virtualenv_appengine_libs):
os.mkdir(virtualenv_appengine_libs)
shutil.copytree(
rocket_engine_path,
os.path.join(PROJECT_DIR, 'rocket_engine')
)
# this seems to break iin following scenarios
# 1. If you have commented a requirement out in requirements.txt
# 2. If you use a package on github (could be due to slow connection issues)
if os.path.exists(requirements_file):
subprocess.Popen(
shlex.split(
"%s %s install --requirement=%s --download-cache=%s --target=%s"
% (python_command, pip_command, requirements_file,
virtualenv_cache, virtualenv_appengine_libs)
),
).wait()
shutil.move(
virtualenv_appengine_libs,
PROJECT_DIR
)
def prepare_upload(self):
self.install_requirements()
def clean_upload(self):
dirs_do_delete = [
appengine_rocket_engine,
appengine_libs,
virtualenv_appengine_libs
]
for path in dirs_do_delete:
try:
shutil.rmtree(path)
except OSError:
pass
def update(self, argv):
self.clean_upload()
try:
self.prepare_upload()
try:
get_callable(PRE_UPDATE_HOOK)()
except (AttributeError, ImportError):
pass
appcfg.main(argv[1:] + [PROJECT_DIR])
try:
get_callable(POST_UPDATE_HOOK)()
except (AttributeError, ImportError):
pass
finally:
self.clean_upload()
def run_from_argv(self, argv):
if len(argv) > 2 and argv[2] == 'update':
self.update(argv)
else:
appcfg.main(argv[1:] + [PROJECT_DIR])