~bloodearnest/charms/trusty/apache2/vhost_template_vars

« back to all changes in this revision

Viewing changes to fabtasks/environment.py

  • Committer: Diogo Baeder de Paula Pinto
  • Date: 2013-02-19 14:18:19 UTC
  • mto: (27.2.16 apache2)
  • mto: This revision was merged to the branch mainline in revision 46.
  • Revision ID: diogobaeder@canonical.com-20130219141819-mak63rvbddn50jqz
Removing Fabric and virtualenv stuff, back to Makefile

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
import os
4
 
import sys
5
 
 
6
 
from fabric.api import env, local
7
 
from fabric.context_managers import lcd
8
 
 
9
 
from .constants import VIRTUALENV
10
 
 
11
 
 
12
 
def bootstrap(download_cache_path=None):
13
 
    """Bootstrap the development environment."""
14
 
    setup_virtualenv()
15
 
    install_dependencies(download_cache_path)
16
 
 
17
 
 
18
 
def clean():
19
 
    """Clean up compiled and backup files."""
20
 
    local("find . -name '*.~*' -delete")
21
 
    local("find . -name '*.pyc' -delete")
22
 
 
23
 
 
24
 
def setup_virtualenv():
25
 
    """Create the virtualenv."""
26
 
    created = False
27
 
    virtual_env = os.environ.get('VIRTUAL_ENV', None)
28
 
    if virtual_env is None:
29
 
        if not os.path.exists(VIRTUALENV):
30
 
            _create_virtualenv()
31
 
            created = True
32
 
        virtual_env = VIRTUALENV
33
 
    env.virtualenv = os.path.abspath(virtual_env)
34
 
    _activate_virtualenv()
35
 
    return created
36
 
 
37
 
 
38
 
def install_dependencies(download_cache_path=None):
39
 
    """Install all dependencies into the virtualenv."""
40
 
    if download_cache_path:
41
 
        cwd = os.getcwd()
42
 
        with lcd(download_cache_path):
43
 
            virtualenv_local(
44
 
                'make install PACKAGES="-r %s/requirements.txt"' %
45
 
                cwd, capture=False)
46
 
    else:
47
 
        virtualenv_local('pip install -r requirements.txt', capture=False)
48
 
 
49
 
 
50
 
def virtualenv_local(command, capture=True):
51
 
    """Run a command inside the virtualenv."""
52
 
    prefix = ''
53
 
    virtual_env = env.get('virtualenv', None)
54
 
    if virtual_env:
55
 
        prefix = ". %s/bin/activate && " % virtual_env
56
 
    command = prefix + command
57
 
    return local(command, capture=capture)
58
 
 
59
 
 
60
 
def _activate_virtualenv():
61
 
    """Activate the virtualenv."""
62
 
    activate_this = os.path.abspath(
63
 
        "%s/bin/activate_this.py" % env.virtualenv)
64
 
    execfile(activate_this, dict(__file__=activate_this))
65
 
 
66
 
 
67
 
def _create_virtualenv(clear=False):
68
 
    """Create the virtualenv."""
69
 
    if not os.path.exists(VIRTUALENV) or clear:
70
 
        virtualenv_bin_path = local('which virtualenv', capture=True)
71
 
        virtualenv_version = local("%s %s --version" % (
72
 
            sys.executable, virtualenv_bin_path), capture=True)
73
 
        args = '--distribute --clear'
74
 
        if virtualenv_version < '1.7':
75
 
            args += ' --no-site-packages'
76
 
        local("%s %s %s %s" % (sys.executable,
77
 
                               virtualenv_bin_path, args, VIRTUALENV),
78
 
              capture=False)