Commits

Mikhail Korobov  committed ea19a93

env.conf.PROJECT_DIR is introduced to aid writing config templates

  • Participants
  • Parent commits a7835b7

Comments (0)

Files changed (7)

File fab_deploy/config_templates/apache.config

     </Directory>
 
     ErrorLog /var/log/apache2/{{ INSTANCE_NAME }}-error.log
-    ErrorDocument 500 {{ SRC_DIR }}/templates/500.html
+    ErrorDocument 500 {{ PROJECT_DIR }}/templates/500.html
 
     # Possible values include: debug, info, notice, warn, error, crit, alert, emerg
     LogLevel error

File fab_deploy/config_templates/django_wsgi.py

 add_to_path([
      os.path.normpath('{{ ENV_DIR }}/lib/python2.5/site-packages'),
      os.path.normpath('{{ ENV_DIR }}/lib/python2.6/site-packages'),
-     os.path.normpath('{{ SRC_DIR }}' + '/..'),
-     '{{ SRC_DIR }}'
+     os.path.normpath('{{ PROJECT_DIR }}' + '/..'),
+     '{{ PROJECT_DIR }}',
 ])
 
 os.environ['DJANGO_SETTINGS_MODULE'] = '{{ INSTANCE_NAME }}.settings'

File fab_deploy/config_templates/nginx.config

 
     # change /static to your static folder name
     location /static {
-        root {{ SRC_DIR }};
+        root {{ PROJECT_DIR }};
         autoindex off;
         expires 1M;
     }
 
     # alternative django admin media path
 #    location /static/admin {
-#        root {{ SRC_DIR }};
+#        root {{ PROJECT_DIR }};
 #        autoindex off;
 #        expires 10m;
 #    }

File fab_deploy/utils.py

     user, host, port = network.normalize(env.hosts[0])
 
     env.conf = getattr(env, 'conf', {})
+    env.conf.setdefault('INSTANCE_NAME', user)
+    env.conf.setdefault('PROJECT_PATH', '')
 
     HOME_DIR = '/home/%s' % user
-    if 'INSTANCE_NAME' not in env.conf:
-        env.conf['INSTANCE_NAME'] = user
-    SRC_DIR = '%s/src/%s' % (HOME_DIR, env.conf['INSTANCE_NAME'])
+    SRC_DIR = posixpath.join(HOME_DIR, 'src', env.conf['INSTANCE_NAME'])
+    PROJECT_DIR = posixpath.join(SRC_DIR, env.conf['PROJECT_PATH']).rstrip('/')
 
     defaults = state._AttributeDict(
         HG_BRANCH='default',
         PROJECT_PATH='',
         LOCAL_CONFIG='config.py',
         REMOTE_CONFIG_TEMPLATE='config.server.py',
-
         CONFIG_TEMPLATES_PATHS=['config_templates'],
 
         PIP_REQUIREMENTS_PATH='reqs',
 
         # these options shouldn't be set by user
         HOME_DIR=HOME_DIR,
-        ENV_DIR=HOME_DIR + '/envs/' + env.conf['INSTANCE_NAME'],
+        ENV_DIR=posixpath.join(HOME_DIR, 'envs', env.conf['INSTANCE_NAME']),
         SRC_DIR=SRC_DIR,
+        PROJECT_DIR = PROJECT_DIR,
         USER=user,
     )
     defaults.update(env.conf)
             # virtualenv is active here
 
     """
-    return prefix('source %s/bin/activate' % env.conf['ENV_DIR'])
+    return prefix('source %s/bin/activate' % env.conf.ENV_DIR)
 
 def inside_virtualenv(func):
     """
     """
     @wraps(func)
     def inner(*args, **kwargs):
-        with cd(_remote_project_path()):
+        with cd(env.conf.PROJECT_DIR):
             with virtualenv():
                 return func(*args, **kwargs)
     return inner

File fab_deploy_tests/test_project/config_templates/apache.config

     </Directory>
 
     ErrorLog /var/log/apache2/{{ INSTANCE_NAME }}-error.log
-    ErrorDocument 500 {{ SRC_DIR }}/templates/500.html
+    ErrorDocument 500 {{ PROJECT_DIR }}/templates/500.html
 
     # Possible values include: debug, info, notice, warn, error, crit, alert, emerg
     LogLevel error

File fab_deploy_tests/test_project/config_templates/django_wsgi.py

 add_to_path([
      os.path.normpath('{{ ENV_DIR }}/lib/python2.5/site-packages'),
      os.path.normpath('{{ ENV_DIR }}/lib/python2.6/site-packages'),
-     os.path.normpath('{{ SRC_DIR }}' + '/..'),
-     '{{ SRC_DIR }}'
+     os.path.normpath('{{ PROJECT_DIR }}' + '/..'),
+     '{{ PROJECT_DIR }}',
 ])
 
 os.environ['DJANGO_SETTINGS_MODULE'] = '{{ INSTANCE_NAME }}.settings'

File fab_deploy_tests/test_project/config_templates/nginx.config

     charset utf-8;
     client_max_body_size 8m;
 
-    gzip_types text/plain text/xml text/css application/javascript application/x-javascript;
+    gzip_types text/plain text/xml text/css application/javascript application/x-javascript application/json;
 
     location / {
         proxy_pass http://localhost:{{ APACHE_PORT }};
 
     # change /static to your static folder name
     location /static {
-        root {{ SRC_DIR }};
+        root {{ PROJECT_DIR }};
         autoindex off;
         expires 1M;
     }
 
     # alternative django admin media path
 #    location /static/admin {
-#        root {{ SRC_DIR }};
+#        root {{ PROJECT_DIR }};
 #        autoindex off;
 #        expires 10m;
 #    }