Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
62  stitch/fabfile.py
@@ -69,7 +69,7 @@ def get_sites():
69 69
 
70 70
 
71 71
 def get_site_packages():
72  
-    return _virtualenv('python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"')
  72
+    return _virtualenv('python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"', capture=True)
73 73
 
74 74
 
75 75
 def get_site_settings(site):
@@ -98,37 +98,32 @@ def site_on_host():
98 98
         pass
99 99
 
100 100
 
101  
-def generate_conf(template_name, dest, filename, context={}):
  101
+def generate_conf(template_name, filename, context={}):
102 102
     output = StringIO.StringIO()
103 103
     t = jinja_env.get_template(template_name)
104 104
     t.stream(context).dump(output)
105  
-
106  
-    if not exists(dest):
107  
-        run('mkdir -p %s' % dest)
108  
-
109  
-    target = os.path.join(dest, filename)
110  
-    put(output, target)
  105
+    put(output, filename)
111 106
     output.close()
112 107
 
113 108
 
114 109
 def generate_confs():
115 110
     host = get_host_shortname(env.host)
116  
-    apache_dir = os.path.join(_get('apache_dir'), host)
117 111
     site = env.site
118 112
     sitepackages = get_site_packages()
119  
-    wsgi_dir = _get('wsgi_dir')
120 113
 
121 114
     context = {
122 115
         'admin_media': os.path.join(sitepackages, 'django/contrib/admin/media'),
  116
+        'gem_home': _get('settings_overrides').get('GEM_HOME'),
123 117
         'pypath': _get('pythonpath').get(host, []),
124 118
         'site': site,
125 119
         'sitepackages': sitepackages,
126 120
         'staging_domain': _get('staging_domain'),
127 121
         'virtualenv_dir': os.path.join(_get('virtualenv_dir'), site),
128  
-        'wsgi_dir': wsgi_dir
  122
+        'wsgi_conf': env.wsgi_conf,
  123
+        'wsgi_dir': _get('wsgi_dir'),
129 124
     }
130  
-    generate_conf('apache/base.conf', apache_dir, '%s.conf' % site, context)
131  
-    generate_conf('wsgi/base.conf', wsgi_dir, '%s.conf' % site, context)
  125
+    generate_conf('apache/base.conf', env.apache_conf, context)
  126
+    generate_conf('wsgi/base.conf', env.wsgi_conf, context)
132 127
     generate_settings()
133 128
 
134 129
 
@@ -152,17 +147,17 @@ def init_settings_dir(path):
152 147
 
153 148
 def generate_settings():
154 149
     pp = pprint.PrettyPrinter()
155  
-    settings_dir = _get('staging_settings')
156  
-    site_settings = os.path.join(settings_dir, env.site)
157  
-    if not exists(site_settings):
158  
-        run('mkdir -p %s' % site_settings)
159  
-    init_settings_dir(site_settings)
  150
+    settings_dir = env.settings_dir
  151
+    if not exists(settings_dir):
  152
+        run('mkdir -p %s' % settings_dir)
  153
+    init_settings_dir(settings_dir)
160 154
     overrides = [[k, pp.pformat(v)] for k, v in _get('settings_overrides').iteritems()]
161 155
     context = {
162 156
         'original_settings': _get('original_settings'),
163 157
         'settings_overrides': overrides
164 158
     }
165  
-    generate_conf('settings/base.py', site_settings, 'settings.py', context)
  159
+    settings_file = os.path.join(settings_dir, 'settings.py')
  160
+    generate_conf('settings/base.py', settings_file, context)
166 161
 
167 162
 
168 163
 def git_clone():
@@ -201,15 +196,31 @@ def setup_virtualenv():
201 196
             add2virtualenv(env.project_path)
202 197
 
203 198
 
  199
+def setup_directories():
  200
+    apache_dir = _get('apache_dir')
  201
+    settings_dir = os.path.join(_get('staging_settings'), env.site)
  202
+    wsgi_dir = _get('wsgi_dir')
  203
+
  204
+    if not exists(apache_dir):
  205
+        run('mkdir -p %s' % apache_dir)
  206
+    if not exists(settings_dir):
  207
+        run('mkdir -p %s' % settings_dir)
  208
+    if not exists(wsgi_dir):
  209
+        run('mkdir -p %s' % wsgi_dir)
  210
+
  211
+
204 212
 def _get(key):
205  
-    return env.config.get(key, None)
  213
+    try:
  214
+        return env.config[key]
  215
+    except KeyError:
  216
+        raise NotDefinedError()
206 217
 
207 218
 
208  
-def _virtualenv(command):
  219
+def _virtualenv(command, **kwargs):
209 220
     with prefix("source `which virtualenvwrapper.sh`"):
210 221
         with cd(_get('virtualenv_dir')):
211 222
             activate = 'workon %s' % env.site
212  
-            return run(activate + ' && ' + command)
  223
+            return run(activate + ' && ' + command, **kwargs)
213 224
 
214 225
 
215 226
 def add2virtualenv(path):
@@ -237,11 +248,15 @@ def wrapped(*args, **kwargs):
237 248
             env.site = site
238 249
             _load_config()
239 250
             if site_on_host():
  251
+                base_dir = _get('base_dir')
  252
+                env.apache_conf = os.path.join(base_dir, _get('apache_dir'), ('%s.conf' % env.site))
240 253
                 env.project_path = os.path.join(_get('virtualenv_dir'), env.site)
241 254
                 env.repo_path = os.path.join(env.project_path, _get('project_name'))
  255
+                env.settings_dir = os.path.join(base_dir, _get('staging_settings'), env.site)
  256
+                env.wsgi_conf = os.path.join(base_dir, _get('wsgi_dir'), ('%s.conf' % env.site))
242 257
                 fn()
243 258
             else:
244  
-                print env.site + ' is not on this host.'
  259
+                print env.site + ' is not on this host. Skipping...'
245 260
         restart()
246 261
     return wrapped
247 262
 
@@ -255,6 +270,7 @@ def debug(*args, **kwargs):
255 270
 
256 271
 @process_sites
257 272
 def setup(*args, **kwargs):
  273
+    setup_directories()
258 274
     setup_virtualenv()
259 275
     generate_confs()
260 276
     pip_install()
8  stitch/helpers.py
@@ -11,6 +11,10 @@
11 11
 from fabric.operations import sudo as _sudo
12 12
 
13 13
 
  14
+class NotDefinedError(Exception):
  15
+    pass
  16
+
  17
+
14 18
 def update(d, u):
15 19
     """
16 20
     Utility function that takes a dictionary and updates keys with values from
@@ -32,9 +36,9 @@ def cd(path):
32 36
         return _cd(path)
33 37
 
34 38
 
35  
-def run(command, shell=True, pty=True):
  39
+def run(command, capture=False, shell=True, pty=True):
36 40
     if _is_local(env.host):
37  
-        return _local(command % (env), capture=True)
  41
+        return _local(command % (env), capture=capture)
38 42
     else:
39 43
         return _run(command % (env), shell=shell, pty=pty)
40 44
 
2  stitch/templates/apache/base.conf
@@ -10,7 +10,7 @@
10 10
     Allow from all
11 11
   </Directory>
12 12
 
13  
-  WSGIScriptAlias / {{ wsgi_dir }}/{{ site }}.conf
  13
+  WSGIScriptAlias / {{ wsgi_conf }}
14 14
   WSGIProcessGroup {{ site }}
15 15
   WSGIDaemonProcess {{ site }}
16 16
   WSGIApplicationGroup %{GLOBAL}
1  stitch/templates/wsgi/base.conf
@@ -13,6 +13,7 @@ except:
13 13
 	pass
14 14
 
15 15
 os.environ['DJANGO_SETTINGS_MODULE'] = '{{ site }}.settings'
  16
+{% if gem_home %}os.environ['GEM_HOME'] = '{{ gem_home }}'{% endif %}
16 17
 
17 18
 import django.core.handlers.wsgi
18 19
 application = django.core.handlers.wsgi.WSGIHandler()

No commit comments for this range

Something went wrong with that request. Please try again.