-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfabfile.py
More file actions
202 lines (158 loc) · 6.29 KB
/
Copy pathfabfile.py
File metadata and controls
202 lines (158 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import os
from fabric.api import env
from fabric.context_managers import cd, settings, hide, lcd
from fabric.contrib.files import exists
from fabric.operations import local, require, prompt
# Required dependencies
#
# PIP_INSTALL - install packages from pip: name:version
#
# GIT_INSTALL - install packages from git:
#
# url - git url for checkouts
# development - head to checkout for dev. Defaults to master
# production - head to checkout for prod. defaults to master.
# symlink - directory to symlink into project. uses project
# name if blank
# Packages from git are given preference for dev environment. PIP is given
# preference for production environments
PIP_INSTALL = {
'django' :'>=1.3',
'django-registration' :'',
'south' :'',
'biopython' :'',
}
GIT_INSTALL = {}
# default environment settings - override these in environment methods if you
# wish to have an environment that functions differently
env.doc_root = '.'
env.remote = False
def dev():
""" configure development deployment """
env.environment = 'development'
def prod():
""" configure a production deployment """
env.environment = 'production'
# Files and directories that will be included in tarball when packaged
env.MANIFEST = [
"pgd"
]
def deploy():
"""
Install all dependencies from git and pip
"""
install_dependencies_pip()
install_dependencies_git()
def _exists(path):
"""
helper to see if a path exists. uses either os.exists or exists depending
on if the environment is remote or local
"""
if env.remote:
return exists(path)
else:
return os.path.exists(path)
def create_virtualenv(virtualenv=None, force=False):
""" create a virtualenv for pip installs """
require('environment', provided_by=[dev, prod])
env.virtualenv = virtualenv if virtualenv else env.doc_root
with lcd(env.doc_root):
if not force and _exists('%(virtualenv)s/lib' % env):
print 'virtualenv already created'
else:
local('virtualenv %(virtualenv)s' % env)
def create_env():
"""
setup environment for git dependencies
"""
require('environment', provided_by=[dev, prod])
with lcd(env.doc_root):
if _exists('dependencies'):
print 'dependencies directory exists already'
else:
local('mkdir dependencies')
def install_dependencies_pip():
"""
Install all dependencies available from pip
"""
require('environment', provided_by=[dev, prod])
create_virtualenv()
# if this is a development install then filter out anything we have a
# git repo for.
pips_ = PIP_INSTALL.copy()
if env.environment == 'development':
map(pips_.pop, [k for k in GIT_INSTALL if k in PIP_INSTALL])
if not pips_:
print 'No git repos to install'
return
with lcd(env.doc_root):
#XXX create temp requirements file text from list of requirements
# it will be destroyed after install is complete
requirements = '\n'.join([''.join(p) for p in pips_.items()])
with settings(hide('running')):
local("echo '%s' > requirements.txt" % requirements)
local('pip install -E %(virtualenv)s -r requirements.txt' % env)
local('rm requirements.txt')
def install_dependencies_git():
""" Install all dependencies available from git """
require('environment', provided_by=[dev, prod])
# if this is a production install then install everything that pip that
# can be installed
gits_ = GIT_INSTALL.copy()
if env.environment != 'development':
map(gits_.pop, (k for k in PIP_INSTALL if k in GIT_INSTALL))
if not gits_:
print 'No git repos to install'
return
create_env()
for name, opts in GIT_INSTALL.items():
# check for required values
if 'url' not in opts:
raise Exception('missing required argument "url" for git repo: %s' % name)
# set git head to check out
if env.environment in opts:
opts['head'] = opts[env.environment]
elif env.environment == 'dev' and 'production' in opts:
opts['head'] = opts['production']
else:
opts['head'] = 'master'
# clone repo
with lcd('%(doc_root)s/dependencies' % env):
env.git_repo = name
if not _exists('%(doc_root)s/dependencies/%(git_repo)s' % env):
local('git clone %(url)s' % opts)
# create branch if not using master
if opts['head'] != 'master':
with lcd(name):
local('git fetch')
local('git checkout %(head)s' % opts)
with settings(hide('warnings','stderr'), warn_only=True):
local('git pull')
# install to virtualenv using setup.py if it exists. Some repos might
# not have it and will need to be symlinked into the project
if _exists('%(doc_root)s/dependencies/%(git_repo)s/setup.py' % env):
with lcd(env.doc_root):
local('pip install -E %(virtualenv)s -e dependencies/%(git_repo)s' % env)
else:
# else, configure and create symlink to git repo
with lcd (env.doc_root):
if 'symlink' in opts:
env.symlink = opts['symlink']
env.symlink_path = '%(doc_root)s/dependencies/%(git_repo)s/%(symlink)s' % env
else:
env.symlink = name
env.symlink_path = '%(doc_root)s/dependencies/%(git_repo)s' % env
with settings(hide('warnings','stderr'), warn_only=True):
local('ln -sf %(symlink_path)s %(doc_root)s' % env)
def tarball():
""" package a release tarball """
tarball = prompt('tarball name', default='ganeti-webmgr-tar.gz')
files = ['ganeti_webmgr/%s' % file for file in env.MANIFEST]
files = ' '.join(files)
with lcd('..'):
data = dict(
tarball=tarball,
files=files
)
local('tar cfz %(tarball)s %(files)s --exclude=*.pyc' % data)
local('mv %(tarball)s ./ganeti_webmgr/' % data)