2 from fabric
.api
import env
3 from fabric
.context_managers
import cd
, settings
, hide
, lcd
4 from fabric
.contrib
.files
import exists
5 from fabric
.operations
import local
, require
, prompt
7 # Required dependencies
9 # PIP_INSTALL - install packages from pip: name:version
11 # GIT_INSTALL - install packages from git:
13 # url - git url for checkouts
14 # development - head to checkout for dev. Defaults to master
15 # production - head to checkout for prod. defaults to master.
16 # symlink - directory to symlink into project. uses project
18 # Packages from git are given preference for dev environment. PIP is given
19 # preference for production environments
23 'django-registration' :'',
25 'django-haystack' :'==1.2.1',
29 'django_object_permissions' :'==1.3.1',
35 'url':'git://github.com/kanaka/noVNC.git',
36 'development':'3859e1d35cf',
37 'production':'3859e1d35cf',
39 'django_object_permissions':{
40 'url':'git://git.osuosl.org/gitolite/django/django_object_permissions',
41 'development':'develop',
42 'symlink':'object_permissions',
45 'url':'git://git.osuosl.org/gitolite/django/django_object_log',
46 'development':'develop',
47 'symlink':'object_log'
49 'django_muddle_users':{
50 'url':'git://git.osuosl.org/gitolite/django/django_muddle_users',
51 'development':'develop',
52 'symlink':'muddle_users'
54 'twisted_vncauthproxy':{
55 'url':'git://git.osuosl.org/gitolite/ganeti/twisted_vncauthproxy',
56 'development':'develop',
62 # default environment settings - override these in environment methods if you
63 # wish to have an environment that functions differently
69 """ configure development deployment """
70 env
.environment
= 'development'
74 """ configure a production deployment """
75 env
.environment
= 'production'
78 # Files and directories that will be included in tarball when packaged
106 Install all dependencies from git and pip
108 install_dependencies_pip()
109 install_dependencies_git()
114 helper to see if a path exists. uses either os.exists or exists depending
115 on if the environment is remote or local
120 return os
.path
.exists(path
)
123 def create_virtualenv(virtualenv
=None, force
=False):
124 """ create a virtualenv for pip installs """
125 require('environment', provided_by
=[dev
, prod
])
126 env
.virtualenv
= virtualenv
if virtualenv
else env
.doc_root
128 with
lcd(env
.doc_root
):
129 if not force
and _exists('%(virtualenv)s/lib' % env
):
130 print 'virtualenv already created'
132 local('virtualenv %(virtualenv)s' % env
)
137 setup environment for git dependencies
139 require('environment', provided_by
=[dev
, prod
])
141 with
lcd(env
.doc_root
):
142 if _exists('dependencies'):
143 print 'dependencies directory exists already'
145 local('mkdir dependencies')
148 def install_dependencies_pip():
150 Install all dependencies available from pip
152 require('environment', provided_by
=[dev
, prod
])
155 # if this is a development install then filter out anything we have a
157 pips_
= PIP_INSTALL
.copy()
158 if env
.environment
== 'development':
159 map(pips_
.pop
, [k
for k
in GIT_INSTALL
if k
in PIP_INSTALL
])
162 print 'No git repos to install'
165 with
lcd(env
.doc_root
):
166 #XXX create temp requirements file text from list of requirements
167 # it will be destroyed after install is complete
168 requirements
= '\n'.join([''.join(p
) for p
in pips_
.items()])
169 with
settings(hide('running')):
170 local("echo '%s' > requirements.txt" % requirements
)
172 local('pip install -E %(virtualenv)s -r requirements.txt' % env
)
173 local('rm requirements.txt')
176 def install_dependencies_git():
177 """ Install all dependencies available from git """
178 require('environment', provided_by
=[dev
, prod
])
180 # if this is a production install then install everything that pip that
182 gits_
= GIT_INSTALL
.copy()
183 if env
.environment
!= 'development':
184 map(gits_
.pop
, (k
for k
in PIP_INSTALL
if k
in GIT_INSTALL
))
187 print 'No git repos to install'
192 for name
, opts
in GIT_INSTALL
.items():
194 # check for required values
195 if 'url' not in opts
:
196 raise Exception('missing required argument "url" for git repo: %s' % name
)
198 # set git head to check out
199 if env
.environment
in opts
:
200 opts
['head'] = opts
[env
.environment
]
201 elif env
.environment
== 'dev' and 'production' in opts
:
202 opts
['head'] = opts
['production']
204 opts
['head'] = 'master'
207 with
lcd('%(doc_root)s/dependencies' % env
):
209 if not _exists('%(doc_root)s/dependencies/%(git_repo)s' % env
):
210 local('git clone %(url)s' % opts
)
212 # create branch if not using master
213 if opts
['head'] != 'master':
216 local('git checkout %(head)s' % opts
)
217 with
settings(hide('warnings','stderr'), warn_only
=True):
220 # install using virtualenv if configured to do so
221 if 'virtualenv' in opts
and opts
['virtualenv']:
222 with
lcd(env
.doc_root
):
223 local('pip install -e dependencies/%s' % name
)
226 # else, configure and create symlink to git repo
227 with
lcd (env
.doc_root
):
228 if 'symlink' in opts
:
229 env
.symlink
= opts
['symlink']
230 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s/%(symlink)s' % env
233 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s' % env
235 with
settings(hide('warnings','stderr'), warn_only
=True):
236 local('ln -sf %(symlink_path)s %(doc_root)s' % env
)
240 """ package a release tarball """
241 tarball
= prompt('tarball name', default
='ganeti-webmgr-tar.gz')
242 files
= ['ganeti_webmgr/%s' % file for file in env
.MANIFEST
]
243 files
= ' '.join(files
)
250 local('tar cfz %(tarball)s %(files)s --exclude=*.pyc' % data
)
251 local('mv %(tarball)s ./ganeti_webmgr/' % data
)