Merge branch 'develop'
[ganeti_webmgr.git] / fabfile.py
blob75ef2508d2bad9cf5840f34c9d443864ae470ff2
1 import os
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
17 # name if blank
18 # Packages from git are given preference for dev environment. PIP is given
19 # preference for production environments
21 PIP_INSTALL = {
22 'django' :'>=1.3',
23 'django-registration' :'',
24 'south' :'',
25 'django-haystack' :'==1.2.1',
26 'whoosh' :'>=1.8.1',
27 'pycurl' :'',
28 'pyopenssl' :'',
29 'django_object_permissions' :'==1.4.1',
30 'django_object_log' :'==0.6',
31 'twisted' :'>=11.0.0'
34 GIT_INSTALL = {
35 'noVNC':{
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',
45 'django_object_log':{
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',
58 'virtualenv':True
63 # default environment settings - override these in environment methods if you
64 # wish to have an environment that functions differently
65 env.doc_root = '.'
66 env.remote = False
69 def dev():
70 """ configure development deployment """
71 env.environment = 'development'
74 def prod():
75 """ configure a production deployment """
76 env.environment = 'production'
79 # Files and directories that will be included in tarball when packaged
80 env.MANIFEST = [
81 "django_test_tools",
82 "deprecated",
83 "ganeti_web",
84 #"i18n",
85 "locale",
86 "media",
87 "templates",
88 "twisted",
89 "util",
90 "__init__.py",
91 "AUTHORS",
92 "CHANGELOG",
93 "COPYING",
94 "fabfile.py",
95 "LICENSE",
96 "manage.py",
97 "README",
98 "search_sites.py",
99 "settings.py.dist",
100 "UPGRADING",
101 "urls.py"
105 def deploy():
107 Install all dependencies from git and pip
109 install_dependencies_pip()
110 install_dependencies_git()
113 def _exists(path):
115 helper to see if a path exists. uses either os.exists or exists depending
116 on if the environment is remote or local
118 if env.remote:
119 return exists(path)
120 else:
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'
132 else:
133 local('virtualenv %(virtualenv)s' % env)
136 def create_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'
145 else:
146 local('mkdir dependencies')
149 def install_dependencies_pip():
151 Install all dependencies available from pip
153 require('environment', provided_by=[dev, prod])
154 create_virtualenv()
156 # if this is a development install then filter out anything we have a
157 # git repo for.
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])
162 if not pips_:
163 print 'No git repos to install'
164 return
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
182 # can be installed
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))
187 if not gits_:
188 print 'No git repos to install'
189 return
191 create_env()
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']
204 else:
205 opts['head'] = 'master'
207 # clone repo
208 with lcd('%(doc_root)s/dependencies' % env):
209 env.git_repo = name
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':
215 with lcd(name):
216 local('git fetch')
217 local('git checkout %(head)s' % opts)
218 with settings(hide('warnings','stderr'), warn_only=True):
219 local('git pull')
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)
226 else:
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
232 else:
233 env.symlink = name
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)
240 def tarball():
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)
246 with lcd('..'):
247 data = dict(
248 tarball=tarball,
249 files=files
251 local('tar cfz %(tarball)s %(files)s --exclude=*.pyc' % data)
252 local('mv %(tarball)s ./ganeti_webmgr/' % data)