-
Notifications
You must be signed in to change notification settings - Fork 16
/
fabfile.py
161 lines (128 loc) · 3.58 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import datetime
import json
import os
from fabric import api
from fabric.state import env
from termcolor import colored
import app
import models
import settings
import utils
env.user = "talks"
env.project_name = settings.PROJECT_NAME
env.forward_agent = True
env.branch = "master"
env.hosts = []
env.settings = None
cd_string = "cd /home/talks/apps/%(project_name)s; " % env
work_string = cd_string + "workon lt && "
@api.task
def development():
"""
Work on development branch.
"""
env.branch = 'development'
@api.task
def master():
"""
Work on stable branch.
"""
env.branch = 'master'
@api.task
def branch(branch_name):
"""
Work on any specified branch.
"""
env.branch = branch_name
@api.task
def tests():
"""
Run Python unit tests.
"""
api.local('nosetests')
@api.task
def e(environment):
env.settings = environment
env.hosts = settings.ENVIRONMENTS[environment]['hosts']
@api.task
def checkout():
api.run('git clone [email protected]:ireapps/%(project_name)s.git /home/talks/apps/%(project_name)s' % env)
@api.task
def bounce():
env.user = 'root'
api.run("service lt stop")
api.run("service lt start")
@api.task
def pull():
api.run('cd /home/talks/apps/%(project_name)s; git fetch' % env)
api.run('cd /home/talks/apps/%(project_name)s; git pull origin master' % env)
@api.task
def pip_install():
api.run(work_string + "pip install --upgrade -r requirements.txt")
"""
SETUP TASKS
"""
def clear_collection(collection):
c = utils.connect(collection)
c.remove({})
@api.task
def tally():
app.tally()
def load_users():
with open('tests/users.json', 'r') as readfile:
return list(json.loads(readfile.read()))
def load_sessions():
with open('tests/sessions.json', 'r') as readfile:
return list(json.loads(readfile.read()))
def load_votes():
with open('tests/votes.json', 'r') as readfile:
return list(json.loads(readfile.read()))
@api.task
def bake():
utils.bake()
@api.task
def fake_data():
for collection in ['user', 'session', 'vote']:
clear_collection(collection)
for user_dict in load_users():
models.User(user_dict).save()
for session_dict in load_sessions():
models.Session(session_dict).save()
for vote_dict in load_votes():
models.Vote(vote_dict).save()
@api.task
def varnish():
api.run('sudo service varnish restart')
@api.task
def push():
with api.settings(warn_only=True):
api.local('git commit -am "Baking; deploying to production."')
api.local('git push origin master')
@api.task
def deploy():
pull()
pip_install()
bounce()
@api.task
def check_voters():
unique = []
duplicates = []
for u in utils.connect('user').find({}):
if u['fingerprint'] in unique:
duplicates.append(u['fingerprint'])
else:
unique.append(u['fingerprint'])
for d in duplicates:
print(d)
print([(u['name'], u['email'], u['created'], len(u['sessions_voted_for'])) for u in utils.connect('user').find({"fingerprint": d}) if len(u['sessions_voted_for']) > 0])
@api.task
def remove_fakes():
votes = utils.connect('vote').find({})
count = 0
for vote in votes:
user = utils.connect('user').find_one({"_id": vote['user']})
if user['fingerprint'] == "2505346121":
utils.connect('vote').remove({"user": user['_id'], "session": vote['session']})
utils.connect('user').remove({"_id": user['_id']})
count += 1
print("Removed user %s, vote %s, #%s" % (user['name'], vote['_id'], count))