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',
27 'django_object_permissions' :'=1.3.1',
33 'url':'git://github.com/kanaka/noVNC.git',
34 'development':'3859e1d35cf',
35 'production':'3859e1d35cf',
37 'django_object_permissions':{
38 'url':'git://git.osuosl.org/gitolite/django/django_object_permissions',
39 'development':'develop',
40 'symlink':'object_permissions',
43 'url':'git://git.osuosl.org/gitolite/django/django_object_log',
44 'development':'develop',
45 'symlink':'object_log'
47 'django_muddle_users':{
48 'url':'git://git.osuosl.org/gitolite/django/django_muddle_users',
49 'development':'develop',
50 'symlink':'muddle_users'
55 # default environment settings - override these in environment methods if you
56 # wish to have an environment that functions differently
62 """ configure development deployment """
63 env
.environment
= 'development'
67 """ configure a production deployment """
68 env
.environment
= 'production'
71 # Files and directories that will be included in tarball when packaged
99 Install all dependencies from git and pip
101 install_dependencies_pip()
102 install_dependencies_git()
107 helper to see if a path exists. uses either os.exists or exists depending
108 on if the environment is remote or local
113 return os
.path
.exists(path
)
116 def create_virtualenv(virtualenv
=None, force
=False):
117 """ create a virtualenv for pip installs """
118 require('environment', provided_by
=[dev
, prod
])
119 env
.virtualenv
= virtualenv
if virtualenv
else env
.doc_root
121 with
lcd(env
.doc_root
):
122 if not force
and _exists('%(virtualenv)s/lib' % env
):
123 print 'virtualenv already created'
125 local('virtualenv %(virtualenv)s' % env
)
130 setup environment for git dependencies
132 require('environment', provided_by
=[dev
, prod
])
134 with
lcd(env
.doc_root
):
135 if _exists('dependencies'):
136 print 'dependencies directory exists already'
138 local('mkdir dependencies')
141 def install_dependencies_pip():
143 Install all dependencies available from pip
145 require('environment', provided_by
=[dev
, prod
])
148 # if this is a development install then filter out anything we have a
150 pips_
= PIP_INSTALL
.copy()
151 if env
.environment
== 'development':
152 map(pips_
.pop
, [k
for k
in GIT_INSTALL
if k
in PIP_INSTALL
])
155 print 'No git repos to install'
158 with
lcd(env
.doc_root
):
159 #XXX create temp requirements file text from list of requirements
160 # it will be destroyed after install is complete
161 requirements
= '\n'.join([''.join(p
) for p
in pips_
.items()])
162 with
settings(hide('running')):
163 local("echo '%s' > requirements.txt" % requirements
)
165 local('pip install -E %(virtualenv)s -r requirements.txt' % env
)
166 local('rm requirements.txt')
169 def install_dependencies_git():
170 """ Install all dependencies available from git """
171 require('environment', provided_by
=[dev
, prod
])
173 # if this is a production install then install everything that pip that
175 gits_
= GIT_INSTALL
.copy()
176 if env
.environment
!= 'development':
177 map(gits_
.pop
, (k
for k
in PIP_INSTALL
if k
in GIT_INSTALL
))
180 print 'No git repos to install'
185 for name
, opts
in GIT_INSTALL
.items():
187 # check for required values
188 if 'url' not in opts
:
189 raise Exception('missing required argument "url" for git repo: %s' % name
)
191 # set git head to check out
192 if env
.environment
in opts
:
193 opts
['head'] = opts
[env
.environment
]
194 elif env
.environment
== 'dev' and 'production' in opts
:
195 opts
['head'] = opts
['production']
197 opts
['head'] = 'master'
200 with
lcd('%(doc_root)s/dependencies' % env
):
202 if not _exists('%(doc_root)s/dependencies/%(git_repo)s' % env
):
203 local('git clone %(url)s' % opts
)
205 # create branch if not using master
206 if opts
['head'] != 'master':
209 local('git checkout %(head)s' % opts
)
210 with
settings(hide('warnings','stderr'), warn_only
=True):
213 # configure and create symlink to git repo
214 with
lcd (env
.doc_root
):
215 if 'symlink' in opts
:
216 env
.symlink
= opts
['symlink']
217 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s/%(symlink)s' % env
220 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s' % env
222 with
settings(hide('warnings','stderr'), warn_only
=True):
223 local('ln -sf %(symlink_path)s %(doc_root)s' % env
)
227 """ package a release tarball """
228 tarball
= prompt('tarball name', default
='ganeti-webmgr-tar.gz')
229 files
= ['ganeti_webmgr/%s' % file for file in env
.MANIFEST
]
230 files
= ' '.join(files
)
237 local('tar cfz %(tarball)s %(files)s --exclude=*.pyc' % data
)
238 local('mv %(tarball)s ./ganeti_webmgr/' % data
)