Merge pull request #167 from piyushbansal/master
[e_cidadania.git] / src / fabfile.py
blob2e0901abe57971ce1cc2f9ef1c43c59c889d9b76
1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2010-2012 Cidadania S. Coop. Galega
5 # This file is part of e-cidadania.
7 # e-cidadania is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # e-cidadania is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with e-cidadania. If not, see <http://www.gnu.org/licenses/>.
20 from fabric.api import local, settings, abort, run, cd, env
21 from fabric.contrib.console import confirm
22 from fabric.operations import put
24 # Commands
26 # Testing only: fab test (inside the project dir)
27 # Straight deploy (no testing): fab deploy:TYPE (type can be 'demo' or 'app')
28 # Full deploy (well tested): fab full_deploy:TYPE
30 env.hosts = ['188.40.90.250']
32 def test():
33 """
34 Executes all the tests of the platform and if the tests failed it will prompt
35 the user to continue or not. If the tests were succesful continue.
36 """
37 with settings(warn_only=True):
38 result = local('./manage.py test', capture=True)
39 if result.failed and not confirm("Tests failed. Continue anyway?"):
40 abort("Aborting at user request.")
43 def deploy(type):
44 """
45 Automate the deployment in the e-cidadania VPS. First it checks if the
46 directory exists. If not, creates a new clone. If it exists, makes a pull
47 and updates the code. After that it copies a local version of the production
48 configuration.
50 Type: demo, app
51 """
52 print "WARNING: Remember that this deployment is untested. For full testing\
53 and deployment use 'full_deploy' function\n"
54 src_dir = '/home/oscarcp/deploy/ecidadania-%s/' % type
55 with settings(warn_only=True):
56 if run("test -d %s" % src_dir).failed:
57 run("git clone git://github.com/cidadania/e-cidadania.git %s" % src_dir)
58 with cd(src_dir):
59 run("git pull")
60 put('~/devel/conf/ecidadania/%s/settings/*' % type, 'src/e_cidadania/settings/')
61 with cd('src/'):
62 run('./manage.py syncdb')
63 run('./manage.py collectstatic')
66 def full_deploy(type):
67 """
68 Full deploy will make all the necessary tests to guarantee that the platform
69 cam be updated, and after that, it will deploy the selected version in the
70 server.
71 """
72 test()
73 deploy(type)