-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
74 lines (60 loc) · 2.03 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os, sys
import pymongo
from simplejson import loads
from fabric.api import *
from libs.persistence import get_database
REPOSITORY = 'https://github.com/PirosB3/PeopleCooks'
# Local
PATH = os.path.dirname(os.path.abspath(__file__))
command = lambda c: os.path.join(PATH, c)
def _get_db():
sys.path.append(PATH)
from settings import MONGO_URL
c = pymongo.Connection(MONGO_URL)
return c[get_database(MONGO_URL)]
def test():
local('python %s' % command('tests.py'))
def populate_fixtures():
db = _get_db()
db.recipes.remove()
db.ingredients.remove()
fixtures = os.path.join(PATH, 'fixtures.json')
f = loads(open(fixtures).read())
for key, value in f.iteritems():
db[key].insert(value)
print "Database values inserted"
# End local
# Environments
def staging():
env.hosts = ['piros@10.211.55.6:22']
env.path = '/var/www/'
env.user = 'www-data'
env.virtualenv = 'com.peoplecooks.dev'
env.branch = 'staging'
def production():
env.hosts = ['piros@192.168.1.100']
env.path = '/var/www/'
env.user = 'www-data'
env.virtualenv = 'com.peoplecooks.www'
env.branch = 'production'
virtualenv_dir = lambda: os.path.join(env.path, env.virtualenv)
project_dir = lambda: os.path.join(virtualenv_dir(), 'peoplecooks')
source_virtualenv = lambda: 'source %s' % os.path.join(virtualenv_dir(), 'bin/activate')
# End Environments
def pull():
with cd(project_dir()):
run('git pull origin %s' % env.branch)
with prefix(source_virtualenv()):
run('pip install -r %s' % os.path.join(project_dir(), 'requirements.txt'))
def reload():
run('service mongo restart')
run('supervisorctl restart')
def bootstrap():
sudo("aptitude -y install git-core python-dev python-setuptools build-essential mongodb supervisor")
with cd(env.path):
run('virtualenv %s' % env.virtualenv)
with cd(virtualenv_dir()):
run('git clone %s peoplecooks' % REPOSITORY)
with cd(project_dir()):
run('git checkout remotes/origin/%s' % env.branch)
pull()