Revision 5832c79d

b/fabfile.py
1
# Copyright 2011 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33
#
34

  
35
import os
36
import sys
37

  
38
from fabric.api import *
39
from fabric.colors import *
40

  
41
env.project_root = "./"
42
env.develop = False
43
env.autoremove = True
44
env.packages = ['snf-common', 'snf-app', 'snf-ganeti-tools', 'snf-webproject']
45
env.capture = False
46
env.colors = True
47

  
48
# coloured logging
49
notice = lambda x: sys.stdout.write(yellow(x) + "\n")
50
info = lambda x: sys.stdout.write(green(x) + "\n")
51
error = lambda x: sys.stdout.write(red(x) + "\n")
52

  
53

  
54
def dev():
55
    env.develop = True
56

  
57
# wrap local to respect global capturing setting from env.capture
58
oldlocal = local
59
def local(cmd, capture=False):
60
    return oldlocal(cmd, capture=env.capture)
61

  
62

  
63
def package_root(p):
64
    return os.path.join(env.project_root, p)
65

  
66

  
67
def remove_pkg(p):
68
    notice("uninstalling package: %s" % p)
69
    with lcd(package_root(p)):
70
        with settings(warn_only=True):
71
            local("pip uninstall %s -y" % p, env.capture)
72

  
73

  
74
def build_pkg(p):
75
    info ("building package: %s" % p)
76
    with lcd(package_root(p)):
77
        with settings(warn_only=True):
78
            local("rm -r dist build")
79
        local("python setup.py sdist")
80

  
81

  
82
def install_pkg(p):
83
    info("installing package: %s" % p)
84
    with lcd(package_root(p)):
85
        if env.develop:
86
            local("python setup.py develop")
87
        else:
88
            local("python setup.py install")
89

  
90

  
91
def buildall():
92
    for p in env.packages:
93
        build_pkg(p)
94
    collectdists()
95

  
96

  
97
def collectdists():
98
    if os.path.exists("./packages"):
99
        notice("removing 'packages' directory")
100
        local("rm -r packages");
101

  
102
    local("mkdir packages");
103
    for p in env.packages:
104
        local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
105

  
106

  
107
def removeall():
108
    for p in env.packages:
109
        remove_pkg(p)
110

  
111

  
112
def remove(*packages):
113
    for p in packages:
114
        remove_pkg("snf-%s" % p)
115

  
116

  
117
def install(*packages):
118
    for p in packages:
119
        install_pkg("snf-%s" % p)
120

  

Also available in: Unified diff