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
98 Install all dependencies from git and pip
100 install_dependencies_pip()
101 install_dependencies_git()
106 helper to see if a path exists. uses either os.exists or exists depending
107 on if the environment is remote or local
112 return os
.path
.exists(path
)
115 def create_virtualenv(virtualenv
=None, force
=False):
116 """ create a virtualenv for pip installs """
117 require('environment', provided_by
=[dev
, prod
])
118 env
.virtualenv
= virtualenv
if virtualenv
else env
.doc_root
120 with
lcd(env
.doc_root
):
121 if not force
and _exists('%(virtualenv)s/lib' % env
):
122 print 'virtualenv already created'
124 local('virtualenv %(virtualenv)s' % env
)
129 setup environment for git dependencies
131 require('environment', provided_by
=[dev
, prod
])
133 with
lcd(env
.doc_root
):
134 if _exists('dependencies'):
135 print 'dependencies directory exists already'
137 local('mkdir dependencies')
140 def install_dependencies_pip():
142 Install all dependencies available from pip
144 require('environment', provided_by
=[dev
, prod
])
147 # if this is a development install then filter out anything we have a
149 pips_
= PIP_INSTALL
.copy()
150 if env
.environment
== 'development':
151 map(pips_
.pop
, [k
for k
in GIT_INSTALL
if k
in PIP_INSTALL
])
154 print 'No git repos to install'
157 with
lcd(env
.doc_root
):
158 #XXX create temp requirements file text from list of requirements
159 # it will be destroyed after install is complete
160 requirements
= '\n'.join([''.join(p
) for p
in pips_
.items()])
161 with
settings(hide('running')):
162 local("echo '%s' > requirements.txt" % requirements
)
164 local('pip install -E %(virtualenv)s -r requirements.txt' % env
)
165 local('rm requirements.txt')
168 def install_dependencies_git():
169 """ Install all dependencies available from git """
170 require('environment', provided_by
=[dev
, prod
])
172 # if this is a production install then install everything that pip that
174 gits_
= GIT_INSTALL
.copy()
175 if env
.environment
!= 'development':
176 map(gits_
.pop
, (k
for k
in PIP_INSTALL
if k
in GIT_INSTALL
))
179 print 'No git repos to install'
184 for name
, opts
in GIT_INSTALL
.items():
186 # check for required values
187 if 'url' not in opts
:
188 raise Exception('missing required argument "url" for git repo: %s' % name
)
190 # set git head to check out
191 if env
.environment
in opts
:
192 opts
['head'] = opts
[env
.environment
]
193 elif env
.environment
== 'dev' and 'production' in opts
:
194 opts
['head'] = opts
['production']
196 opts
['head'] = 'master'
199 with
lcd('%(doc_root)s/dependencies' % env
):
201 if not _exists('%(doc_root)s/dependencies/%(git_repo)s' % env
):
202 local('git clone %(url)s' % opts
)
204 # create branch if not using master
205 if opts
['head'] != 'master':
208 local('git checkout %(head)s' % opts
)
209 with
settings(hide('warnings','stderr'), warn_only
=True):
212 # configure and create symlink to git repo
213 with
lcd (env
.doc_root
):
214 if 'symlink' in opts
:
215 env
.symlink
= opts
['symlink']
216 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s/%(symlink)s' % env
219 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s' % env
221 with
settings(hide('warnings','stderr'), warn_only
=True):
222 local('ln -sf %(symlink_path)s %(doc_root)s' % env
)
226 """ package a release tarball """
227 tarball
= prompt('tarball name', default
='ganeti-webmgr-tar.gz')
228 files
= ['ganeti_webmgr/%s' % file for file in env
.MANIFEST
]
229 files
= ' '.join(files
)
236 local('tar cfz %(tarball)s %(files)s --exclude=*.pyc' % data
)
237 local('mv %(tarball)s ./ganeti_webmgr/' % data
)