forked from nutechsoftware/alarmdecoder-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
137 lines (99 loc) · 3.3 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
# -*- coding: utf-8 -*-
# http://docs.fabfile.org/en/1.5/tutorial.html
import os
from fabric.api import *
from flask.ext.script import Manager
import git
import git.exc
from ad2web import create_app
from ad2web.extensions import db
from ad2web.utils import INSTANCE_FOLDER_PATH
from ad2web.settings import Setting
from ad2web.certificate import Certificate
from ad2web.certificate.constants import ACTIVE, CA, SERVER, INTERNAL, CLIENT
from ad2web.decoder import Decoder
from ad2web.ser2sock import ser2sock
from ad2web.updater import Updater
project = "ad2web"
# the user to use for the remote commands
env.user = ''
# the servers where the commands are executed
env.hosts = ['']
def reset():
"""
Reset local debug env.
"""
local("rm -rf {0}".format(INSTANCE_FOLDER_PATH))
local("mkdir {0}".format(INSTANCE_FOLDER_PATH))
local("python manage.py initdb")
def setup():
"""
Setup virtual env.
"""
local("virtualenv env")
activate_this = "env/bin/activate_this.py"
execfile(activate_this, dict(__file__=activate_this))
local("python setup.py install")
reset()
def d(skip_reset=False):
"""
Debug.
"""
if not skip_reset:
reset()
local("python manage.py run")
def certs():
reset()
app, appsocket = create_app()
manager = Manager(app)
with app.app_context():
config_path = Setting(name='ser2sock_config_path', value='/etc/ser2sock')
db.session.add(config_path)
db.session.commit()
ca = Certificate(name='AlarmDecoder CA', status=ACTIVE, type=CA)
ca.generate(ca.name)
server = Certificate(name='AlarmDecoder Server', status=ACTIVE, type=SERVER)
server.generate(server.name, parent=ca)
internal = Certificate(name='AlarmDecoder Internal', status=ACTIVE, type=INTERNAL)
internal.generate(internal.name, parent=ca)
test_1 = Certificate(name='Test #1', status=ACTIVE, type=CLIENT)
test_1.generate(test_1.name, parent=ca)
test_2 = Certificate(name='Test #2', status=ACTIVE, type=CLIENT)
test_2.generate(test_2.name, parent=ca)
db.session.add(ca)
db.session.add(server)
db.session.add(internal)
db.session.add(test_1)
db.session.add(test_2)
db.session.commit()
path = os.path.join(os.path.sep, 'etc', 'ser2sock', 'certs')
ca.export(path)
server.export(path)
internal.export(path)
test_1.export(path)
test_2.export(path)
Certificate.save_certificate_index()
Certificate.save_revocation_list()
ser2sock.hup()
def revoke_cert(name):
print 'Revoking: ', name
decoder = Decoder(None, None)
app, appsocket = create_app()
manager = Manager(app)
with app.app_context():
cert = Certificate.query.filter_by(name=name).first()
if cert is not None:
cert.revoke()
Certificate.save_certificate_index()
Certificate.save_revocation_list()
ser2sock.hup()
db.session.add(cert)
db.session.commit()
print name, 'successfully revoked.'
else:
print name, 'not found.'
def babel():
"""
Babel compile.
"""
local("python setup.py compile_catalog --directory `find -name translations` --locale zh -f")