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.4.1',
30 'django_object_log' :'==0.6',
36 'url':'git://github.com/kanaka/noVNC.git',
37 'development':'3859e1d35cf',
38 'production':'3859e1d35cf',
40 'django_object_permissions':{
41 'url':'git://git.osuosl.org/gitolite/django/django_object_permissions',
42 'development':'develop',
43 'symlink':'object_permissions',
46 'url':'git://git.osuosl.org/gitolite/django/django_object_log',
47 'development':'develop',
48 'symlink':'object_log'
50 'django_muddle_users':{
51 'url':'git://git.osuosl.org/gitolite/django/django_muddle_users',
52 'development':'develop',
53 'symlink':'muddle_users'
55 'twisted_vncauthproxy':{
56 'url':'git://git.osuosl.org/gitolite/ganeti/twisted_vncauthproxy',
57 'development':'develop',
63 # default environment settings - override these in environment methods if you
64 # wish to have an environment that functions differently
70 """ configure development deployment """
71 env
.environment
= 'development'
75 """ configure a production deployment """
76 env
.environment
= 'production'
79 # Files and directories that will be included in tarball when packaged
107 Install all dependencies from git and pip
109 install_dependencies_pip()
110 install_dependencies_git()
115 helper to see if a path exists. uses either os.exists or exists depending
116 on if the environment is remote or local
121 return os
.path
.exists(path
)
124 def create_virtualenv(virtualenv
=None, force
=False):
125 """ create a virtualenv for pip installs """
126 require('environment', provided_by
=[dev
, prod
])
127 env
.virtualenv
= virtualenv
if virtualenv
else env
.doc_root
129 with
lcd(env
.doc_root
):
130 if not force
and _exists('%(virtualenv)s/lib' % env
):
131 print 'virtualenv already created'
133 local('virtualenv %(virtualenv)s' % env
)
138 setup environment for git dependencies
140 require('environment', provided_by
=[dev
, prod
])
142 with
lcd(env
.doc_root
):
143 if _exists('dependencies'):
144 print 'dependencies directory exists already'
146 local('mkdir dependencies')
149 def install_dependencies_pip():
151 Install all dependencies available from pip
153 require('environment', provided_by
=[dev
, prod
])
156 # if this is a development install then filter out anything we have a
158 pips_
= PIP_INSTALL
.copy()
159 if env
.environment
== 'development':
160 map(pips_
.pop
, [k
for k
in GIT_INSTALL
if k
in PIP_INSTALL
])
163 print 'No git repos to install'
166 with
lcd(env
.doc_root
):
167 #XXX create temp requirements file text from list of requirements
168 # it will be destroyed after install is complete
169 requirements
= '\n'.join([''.join(p
) for p
in pips_
.items()])
170 with
settings(hide('running')):
171 local("echo '%s' > requirements.txt" % requirements
)
173 local('pip install -E %(virtualenv)s -r requirements.txt' % env
)
174 local('rm requirements.txt')
177 def install_dependencies_git():
178 """ Install all dependencies available from git """
179 require('environment', provided_by
=[dev
, prod
])
181 # if this is a production install then install everything that pip that
183 gits_
= GIT_INSTALL
.copy()
184 if env
.environment
!= 'development':
185 map(gits_
.pop
, (k
for k
in PIP_INSTALL
if k
in GIT_INSTALL
))
188 print 'No git repos to install'
193 for name
, opts
in GIT_INSTALL
.items():
195 # check for required values
196 if 'url' not in opts
:
197 raise Exception('missing required argument "url" for git repo: %s' % name
)
199 # set git head to check out
200 if env
.environment
in opts
:
201 opts
['head'] = opts
[env
.environment
]
202 elif env
.environment
== 'dev' and 'production' in opts
:
203 opts
['head'] = opts
['production']
205 opts
['head'] = 'master'
208 with
lcd('%(doc_root)s/dependencies' % env
):
210 if not _exists('%(doc_root)s/dependencies/%(git_repo)s' % env
):
211 local('git clone %(url)s' % opts
)
213 # create branch if not using master
214 if opts
['head'] != 'master':
217 local('git checkout %(head)s' % opts
)
218 with
settings(hide('warnings','stderr'), warn_only
=True):
221 # install using virtualenv if configured to do so
222 if 'virtualenv' in opts
and opts
['virtualenv']:
223 with
lcd(env
.doc_root
):
224 local('pip install -E %(virtualenv)s -e dependencies/%(git_repo)s' % env
)
227 # else, configure and create symlink to git repo
228 with
lcd (env
.doc_root
):
229 if 'symlink' in opts
:
230 env
.symlink
= opts
['symlink']
231 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s/%(symlink)s' % env
234 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s' % env
236 with
settings(hide('warnings','stderr'), warn_only
=True):
237 local('ln -sf %(symlink_path)s %(doc_root)s' % env
)
241 """ package a release tarball """
242 tarball
= prompt('tarball name', default
='ganeti-webmgr-tar.gz')
243 files
= ['ganeti_webmgr/%s' % file for file in env
.MANIFEST
]
244 files
= ' '.join(files
)
251 local('tar cfz %(tarball)s %(files)s --exclude=*.pyc' % data
)
252 local('mv %(tarball)s ./ganeti_webmgr/' % data
)