forked from geopython/GeoHealthCheck
/
pavement.py
172 lines (137 loc) · 5.28 KB
/
pavement.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
162
163
164
165
166
167
168
169
170
171
172
# =================================================================
#
# Authors: Tom Kralidis <tomkralidis@gmail.com>
#
# Copyright (c) 2014 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================
import os
import shutil
import tempfile
from StringIO import StringIO
from urllib2 import urlopen
import zipfile
from paver.easy import (Bunch, info, needs, options, path, pushd, sh, task)
BASEDIR = os.path.abspath(os.path.dirname(__file__))
options(
base=Bunch(
home=path(BASEDIR),
docs=path('%s/docs' % BASEDIR),
instance=path('%s/instance' % BASEDIR),
static_lib=path('%s/GeoHealthCheck/static/lib' % BASEDIR),
tmp=path(tempfile.mkdtemp())
),
)
@task
def setup():
"""setup plugin dependencies"""
config_file = options.base.home / 'GeoHealthCheck/config.py'
# setup dirs
if not os.path.exists(options.base.static_lib):
options.base.static_lib.mkdir()
if not os.path.exists(options.base.instance):
options.base.instance.mkdir()
data_dir = options.base.instance / 'data'
data_dir.mkdir()
data_dir.chmod(0777)
# setup config
config_file.copy(options.base.instance)
# setup deps
sh('pip install -r requirements.txt')
# split URL to keep pep8 happy
skin = '/'.join(['https://github.com',
'IronSummitMedia/startbootstrap-sb-admin-2',
'archive/v1.0.3.zip'])
skin_dirs = ['dist', 'bower_components']
need_to_fetch = False
for skin_dir in skin_dirs:
skin_dir_path = os.sep.join(
['startbootstrap-sb-admin-2-1.0.3', skin_dir])
if not os.path.exists(skin_dir_path):
need_to_fetch = True
if need_to_fetch:
zipstr = StringIO(urlopen(skin).read())
zipfile_obj = zipfile.ZipFile(zipstr)
zipfile_obj.extractall(options.base.static_lib)
for zf_mem in skin_dirs:
src_loc = path(options.base.static_lib /
'startbootstrap-sb-admin-2-1.0.3' / zf_mem)
dest_loc = path(options.base.static_lib / zf_mem)
if not os.path.exists(dest_loc):
src_loc.move(dest_loc)
else:
info('directory already exists. Skipping')
shutil.rmtree(path(options.base.static_lib /
'startbootstrap-sb-admin-2-1.0.3'))
# message user
info('GeoHealthCheck is now built. Edit settings in %s' % config_file)
info('before deploying the application. Alternatively, you can start a')
info('development instance with "python GeoHealthCheck/app.py"')
@task
def create_secret_key():
"""create secret key for SECRET_KEY in instance/config.py"""
info('Secret key: \'%s\'' % os.urandom(24))
info('Copy/paste this key to set the SECRET_KEY')
info('value in instance/config.py')
@task
def create():
"""create database objects and superuser account"""
sh('python GeoHealthCheck/models.py create')
@task
def create_wsgi():
"""create WSGI wrapper"""
with open('%s%sGeoHealthCheck.wsgi' % (BASEDIR, os.sep), 'w') as ff:
ff.write('import sys\n')
ff.write('sys.path.insert(0, \'%s\')\n' % BASEDIR)
ff.write('from GeoHealthCheck.app import APP as application')
@task
def refresh_docs():
"""Build sphinx docs from scratch"""
make = sphinx_make()
with pushd(options.base.docs):
sh('%s clean' % make)
sh('%s html' % make)
@task
@needs('refresh_docs')
def publish_docs():
"""publish documentation to http://geopython.github.io/GeoHealthCheck"""
with pushd(options.base.tmp):
sh('git clone git@github.com:geopython/GeoHealthCheck.git')
with pushd('GeoHealthCheck'):
sh('git checkout gh-pages')
sh('cp -rp %s/docs/_build/html/* .' % options.base.home)
sh('git add .')
sh('git commit -am "update live docs [ci skip]"')
sh('git push origin gh-pages')
shutil.rmtree(options.base.tmp)
@task
def clean():
"""clean environment"""
if os.path.exists(options.base.static_lib):
shutil.rmtree(options.base.static_lib)
def sphinx_make():
"""return what command Sphinx is using for make"""
if os.name == 'nt':
return 'make.bat'
return 'make'