Commits

Vladimir Mihailenco committed b8ddbe3 Merge

Merge with django_root

Comments (0)

Files changed (4)

File contents unchanged.

fab_deploy/utils.py

         return inner
     return decorator
 
-def upload_config_template(name, to=None):
+def upload_config_template(name, to=None, check_existence=False):
     if to is None:
         base_dir = env.conf['ENV_DIR'] + "/etc/"
         run('mkdir -p ' + base_dir)
         to = base_dir + name
-    upload_template('./config_templates/' + name, to, env.conf, True)
+    config_template = _config_template_path(name)
+    if check_existence and not os.path.exists(config_template):
+        return
+    upload_template(config_template, to, env.conf, True)
 
 def update_env():
     """
     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'])
 
     defaults = _AttributeDict(
-        HG_BRANCH = 'default',
+        HG_BRANCH='default',
         GIT_BRANCH = 'master',
-        DB_NAME = env.conf['INSTANCE_NAME'],
-        DB_USER = 'root',
-        PROCESSES = 1,
-        THREADS = 15,
-        SERVER_NAME = host,
-        SERVER_ADMIN = 'example@example.com',
-        VCS = 'hg',
+        DB_NAME=env.conf['INSTANCE_NAME'],
+        DB_USER='root',
+        PROCESSES=1,
+        THREADS=15,
+        SERVER_NAME=host,
+        SERVER_ADMIN='example@example.com',
+        VCS='hg',
+
+        PROJECT_DIR='',
+        LOCAL_CONFIG='config.py',
+        REMOTE_CONFIG_TEMPLATE='config.server.py',
+
+        CONFIG_TEMPLATES_DIRS=['config_templates'],
+
+        PIP_REQUIREMENTS_DIR='reqs',
+        PIP_REQUIREMENTS='all.txt',
 
         # these options shouldn't be set by user
-        HOME_DIR = HOME_DIR,
-        ENV_DIR = HOME_DIR + '/envs/' + env.conf['INSTANCE_NAME'],
-        SRC_DIR = HOME_DIR + '/src/' + env.conf['INSTANCE_NAME'],
-        USER = user,
+        HOME_DIR=HOME_DIR,
+        ENV_DIR=HOME_DIR + '/envs/' + env.conf['INSTANCE_NAME'],
+        SRC_DIR=SRC_DIR,
+        USER=user,
     )
     defaults.update(env.conf)
+
     env.conf = defaults
 
     for vcs in ['git', 'hg', 'none']: # expand VCS name to full import path
         if env.conf.VCS == vcs:
-            env.conf.VCS = 'fab_deploy.vcs.'+vcs
+            env.conf.VCS = 'fab_deploy.vcs.' + vcs
 
 
 def virtualenv():
             # virtualenv is active here
 
     """
-    return prefix('source '+env.conf['ENV_DIR']+'/bin/activate')
+    return prefix('source %s/bin/activate' % env.conf['ENV_DIR'])
 
 def inside_virtualenv(func):
     """
             return func(*args, **kwargs)
     return inner
 
+def inside_src(func):
+    @wraps(func)
+    def inner(*args, **kwargs):
+        with cd(env.conf.SRC_DIR):
+            with virtualenv():
+                return func(*args, **kwargs)
+    return inner
+
 def inside_project(func):
     """
     Decorator. Use it to perform actions inside project dir with
     """
     @wraps(func)
     def inner(*args, **kwargs):
-        with cd(env.conf['SRC_DIR']):
+        with cd(_remote_project_path()):
             with virtualenv():
                 return func(*args, **kwargs)
     return inner
 def _data_path(fname):
     """Return the path to a data file of ours."""
     return os.path.join(os.path.split(__file__)[0], fname)
+
+def _project_path(name=''):
+    if name.startswith('/'):
+        return name
+    return os.path.join(env.conf.PROJECT_DIR, name)
+
+def _remote_project_path(name=''):
+    if name.startswith('/'):
+        return name
+    return os.path.join(env.conf.SRC_DIR, _project_path(name))
+
+def _pip_req_path(name):
+    if name.startswith('/'):
+        return name
+    if not name.endswith('.txt'): # BC
+        name += '.txt'
+    return os.path.join(env.conf.PIP_REQUIREMENTS_DIR, name)
+
+def _config_template_path(name):
+    if name.startswith('/'):
+        return name
+
+    for dir in env.conf.CONFIG_TEMPLATES_DIRS:
+        path = os.path.join(dir, name)
+        if os.path.exists(path):
+            return path

fab_deploy/vcs/none.py

 from datetime import datetime
 from fabric.api import *
 
+from fab_deploy import utils
+
+
 BRANCH_OPTION = None
 
 def _exclude_string():
-    excludes = ['config.py', '*.pyc', '*.pyo']
+    excludes = [utils._project_path(env.conf.LOCAL_CONFIG), '*.pyc', '*.pyo']
     exclude_string = " ".join(['--exclude "%s"' % pattern for pattern in excludes])
     if os.path.exists('.excludes'):
         exclude_string =  "-X .excludes " + exclude_string

fab_deploy/virtualenv.py

 from __future__ import with_statement
 from fabric.api import run, env, cd
 from fab_deploy.apache import touch
-from fab_deploy.utils import inside_project
+from fab_deploy.utils import inside_src
+from fab_deploy import utils
 
-@inside_project
+@inside_src
 def pip(commands=''):
     """ Runs pip command """
-    run('pip '+ commands)
+    run('pip ' + commands)
 
-@inside_project
+@inside_src
 def pip_install(what='active', options='', restart=True):
     """ Installs pip requirements listed in ``reqs/<file>.txt`` file. """
-    run('pip install %s -r reqs/%s.txt' % (options, what))
+    what = utils._pip_req_path(what)
+    run('pip install %s -r %s' % (options, what))
     if restart:
         touch()
 
-@inside_project
+@inside_src
 def pip_update(what='active', options='', restart=True):
     """ Updates pip requirements listed in ``reqs/<file>.txt`` file. """
-    run('pip install %s -U -r reqs/%s.txt' % (options, what))
+    what = utils._pip_req_path(what)
+    run('pip install %s -U -r %s' % (options, what))
     if restart:
         touch()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.