5 from fabric
.api
import env
, abort
6 from fabric
.context_managers
import settings
, hide
, lcd
7 from fabric
.contrib
.console
import confirm
8 from fabric
.contrib
.files
import exists
9 from fabric
.operations
import local
, require
, prompt
11 # Required dependencies
13 # PIP_INSTALL - install packages from pip: name:version
15 # GIT_INSTALL - install packages from git:
17 # url - git url for checkouts
18 # development - head to checkout for dev. Defaults to master
19 # production - head to checkout for prod. defaults to master.
20 # symlink - directory to symlink into project. uses project
22 # Packages from git are given preference for dev environment. PIP is given
23 # preference for production environments
25 PIP_INSTALL
= dict((r
.project_name
, str(r
)) for r
in
26 pkg_resources
.parse_requirements(open("requirements.txt").read()))
30 'url':'git://github.com/kanaka/noVNC.git',
32 'development':'3859e1d35cf',
33 'production':'3859e1d35cf',
35 'django_object_permissions':{
36 'url':'git://git.osuosl.org/gitolite/django/django_object_permissions',
37 'development':'develop',
40 'url':'git://git.osuosl.org/gitolite/django/django_object_log',
41 'development':'develop',
43 'django_muddle_users':{
44 'url':'git://git.osuosl.org/gitolite/django/django_muddle_users',
45 'development':'develop',
48 'url':'git://git.osuosl.org/gitolite/django/muddle',
49 'development':'develop',
51 'twisted_vncauthproxy':{
52 'url':'git://git.osuosl.org/gitolite/ganeti/twisted_vncauthproxy',
53 'development':'develop',
58 # default environment settings - override these in environment methods if you
59 # wish to have an environment that functions differently
66 Configure development deployment.
69 env
.environment
= 'development'
74 Configure production deployment.
77 env
.environment
= 'production'
80 # List of stuff to include in the tarball, recursive.
107 Install all dependencies from git and pip.
110 install_dependencies_pip()
111 install_dependencies_git()
115 In a development environment, remove all installed packages and symlinks.
117 require('environment', provided_by
=[dev
, prod
])
119 if env
.environment
!= 'development':
120 abort('Must be in a development environment.')
122 with
lcd('%(doc_root)s' % env
):
123 gitcmd
= 'git clean -%sdx -e \!settings.py'
124 print('Files to be removed:')
126 if confirm('Are you certain you would like to remove these files?'):
129 abort('Aborting clean.')
134 In a development environment, update all develop branches.
136 require('environment', provided_by
=[dev
, prod
])
138 if env
.environment
!= 'development':
139 raise Exception('must be in a development environment in order to'
140 'update develop branches.')
142 with
lcd('%(doc_root)s/dependencies' % env
):
143 for git_dir
, opts
in GIT_INSTALL
.items():
144 env
.git_repo
= git_dir
145 if (_exists('%(doc_root)s/dependencies/%(git_repo)s' % env
) and
146 'development' in opts
and 'checkout' not in opts
):
148 print 'Updating git repo: %(git_repo)s' % env
149 local('git pull --ff')
154 A helper function to determine whether a path exists.
156 This function does the right thing in both remote and local environments.
162 return os
.path
.exists(path
)
165 def create_virtualenv(virtualenv
=None, force
=False):
167 Create a virtualenv for pip installations.
169 By default, the environment will be placed in the document root. Pass a
170 path to override the location.
172 If ``force`` is False, then the environment will not be recreated if it
176 require('environment', provided_by
=[dev
, prod
])
177 env
.virtualenv
= virtualenv
if virtualenv
else env
.doc_root
179 with
lcd(env
.doc_root
):
180 if not force
and _exists('%(virtualenv)s/lib' % env
):
181 print 'virtualenv already created'
183 # XXX does this actually create a new environment if one already
185 local('virtualenv %(virtualenv)s --distribute' % env
)
187 # now lets make sure the virtual env has the the newest pip
188 local('%(virtualenv)s/bin/pip install --upgrade pip' % env
)
193 Setup environment for git dependencies.
196 require('environment', provided_by
=[dev
, prod
])
198 with
lcd(env
.doc_root
):
199 if _exists('dependencies'):
200 print 'dependencies directory exists already'
202 local('mkdir dependencies')
205 def install_dependencies_pip():
207 Install all dependencies available from pip.
210 require('environment', provided_by
=[dev
, prod
])
213 with
lcd(env
.doc_root
):
214 # Run the installation with pip, passing in our requirements.txt.
215 local('%(virtualenv)s/bin/pip install -r requirements.txt' % env
)
218 def install_dependencies_git():
220 Install all dependencies available from git.
223 require('environment', provided_by
=[dev
, prod
])
225 if env
.environment
!= 'development':
226 # If we can satisfy all of our dependencies from pip alone, then don't
227 # bother running the git installation.
228 if all(p
in PIP_INSTALL
for p
in GIT_INSTALL
):
229 print 'No git repos to install'
234 for name
, opts
in GIT_INSTALL
.items():
236 # check for required values
237 if 'url' not in opts
:
238 raise Exception('missing required argument "url" for git repo: %s' % name
)
240 # set git head to check out
241 if env
.environment
in opts
:
242 opts
['head'] = opts
[env
.environment
]
243 elif env
.environment
== 'development' and 'production' in opts
:
244 opts
['head'] = opts
['production']
246 opts
['head'] = 'master'
249 with
lcd('%(doc_root)s/dependencies' % env
):
251 if not _exists('%(doc_root)s/dependencies/%(git_repo)s' % env
):
252 local('git clone %(url)s' % opts
)
254 # create branch if not using master
255 if opts
['head'] != 'master':
259 # If we're supposed to affix ourselves to a certain
260 # commit, then do so. Otherwise, attempt to create a
261 # tracked branch and update it.
262 if opts
.get("checkout", "") == "commit":
263 local("git checkout %(head)s" % opts
)
265 with
settings(hide('warnings','stderr'),
267 local('git checkout -t origin/%(head)s' % opts
)
270 # install to virtualenv using setup.py if it exists. Some repos might
271 # not have it and will need to be symlinked into the project
272 if _exists('%(doc_root)s/dependencies/%(git_repo)s/setup.py' % env
):
273 with
lcd(env
.doc_root
):
274 local('%(virtualenv)s/bin/pip install -e dependencies/%(git_repo)s' % env
)
277 # else, configure and create symlink to git repo
278 with
lcd (env
.doc_root
):
279 if 'symlink' in opts
:
280 env
.symlink
= opts
['symlink']
281 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s/%(symlink)s' % env
284 env
.symlink_path
= '%(doc_root)s/dependencies/%(git_repo)s' % env
286 with
settings(hide('warnings','stderr'), warn_only
=True):
287 local('ln -sf %(symlink_path)s %(doc_root)s' % env
)
293 Package a release tarball.
296 tarball
= prompt('tarball name', default
='ganeti-webmgr.tar.gz')
297 files
= ['ganeti_webmgr/%s' % file for file in env
.MANIFEST
]
298 files
= ' '.join(files
)
305 local('tar zcf %(tarball)s %(files)s --exclude=*.pyc' % data
)
306 local('mv %(tarball)s ./ganeti_webmgr/' % data
)