forked from planetfederal/qgis-suite-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
184 lines (161 loc) · 5.69 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
173
174
175
176
177
178
179
180
181
182
183
184
from cStringIO import StringIO
import ConfigParser
from datetime import date, datetime
import fnmatch
import os
from paver.easy import *
# this pulls in the sphinx target
from paver.doctools import html
import xmlrpclib
import zipfile
options(
plugin = Bunch(
name = 'opengeo',
ext_libs = path('src/opengeo/ext-libs'),
ext_src = path('src/opengeo/ext-src'),
source_dir = path('src/opengeo'),
package_dir = path('.'),
excludes = [
'metadata.txt',
'test-output',
'test',
'coverage*.*',
'nose*.*',
'*.pyc'
]
),
# Default Server Params (can be overridden)
plugin_server = Bunch(
server = 'qgis.boundlessgeo.com',
port = 80,
protocol = 'http',
end_point = '/RPC2/'
),
sphinx = Bunch(
docroot = 'doc',
sourcedir = 'source',
builddir = 'build'
)
)
@task
@cmdopts([
('clean', 'c', 'clean out dependencies first'),
])
def setup(options):
'''install dependencies'''
clean = getattr(options, 'clean', False)
ext_libs = options.plugin.ext_libs
ext_src = options.plugin.ext_src
if clean:
ext_libs.rmtree()
ext_libs.makedirs()
runtime, test = read_requirements()
os.environ['PYTHONPATH']=ext_libs.abspath()
for req in runtime + test:
if req.startswith('-e'):
# use pip to just process the URL and fetch it in to place
sh('pip install --no-install --src=%s %s' % (ext_src, req))
# now change the req to be the location installed to
# and easy_install will do the rest
urlspec, req = req.split('#egg=')
sh('easy_install -a -d %(ext_libs)s %(dep)s' % {
'ext_libs' : ext_libs.abspath(),
'dep' : req
})
def read_requirements():
'''return a list of runtime and list of test requirements'''
lines = open('requirements.txt').readlines()
lines = [ l for l in [ l.strip() for l in lines] if l ]
divider = '# test requirements'
try:
idx = lines.index(divider)
except ValueError:
raise BuildFailure('expected to find "%s" in requirements.txt' % divider)
not_comments = lambda s,e: [ l for l in lines[s:e] if l[0] != '#']
return not_comments(0, idx), not_comments(idx+1, None)
@task
def install(options):
'''install plugin to qgis'''
plugin_name = options.plugin.name
src = path(__file__).dirname() / 'src' / plugin_name
dst = path('~').expanduser() / '.qgis2' / 'python' / 'plugins' / plugin_name
src = src.abspath()
dst = dst.abspath()
if not hasattr(os, 'symlink'):
dst.rmtree()
src.copytree(dst)
elif not dst.exists():
src.symlink(dst)
@task
def package(options):
'''create package for plugin'''
package_file = options.plugin.package_dir / ('%s.zip' % options.plugin.name)
with zipfile.ZipFile(package_file, "w", zipfile.ZIP_DEFLATED) as zip:
make_zip(zip, options)
return package_file
def make_zip(zip, options):
metadata_file = options.plugin.source_dir / "metadata.txt"
cfg = ConfigParser.SafeConfigParser()
cfg.optionxform = str
cfg.read(metadata_file)
base_version = cfg.get('general', 'version')
cfg.set("general", "version", "%s-%s" % (base_version, datetime.now().strftime("%Y%m%d")))
buf = StringIO()
cfg.write(buf)
zip.writestr("opengeo/metadata.txt", buf.getvalue())
excludes = set(options.plugin.excludes)
src_dir = options.plugin.source_dir
exclude = lambda p: any([fnmatch.fnmatch(p, e) for e in excludes])
def filter_excludes(files):
if not files: return []
# to prevent descending into dirs, modify the list in place
for f in files:
if exclude(f):
debug('excluding %s' % f)
files.remove(f)
return files
for root, dirs, files in os.walk(src_dir):
for f in filter_excludes(files):
relpath = os.path.relpath(root, 'src')
zip.write(path(root) / f, path(relpath) / f)
filter_excludes(dirs)
@task
@cmdopts([
('user=', 'u', 'upload user'),
('passwd=', 'p', 'upload password'),
('server=', 's', 'alternate server'),
('end_point=', 'e', 'alternate endpoint'),
('port=', 't', 'alternate port'),
])
def upload(options):
'''upload the package to the server'''
package_file = package(options)
user, passwd = getattr(options, 'user', None), getattr(options, 'passwd', None)
if not user or not passwd:
raise BuildFailure('provide user and passwd options to upload task')
# create URL for XML-RPC calls
s = options.plugin_server
server, end_point, port = getattr(options, 'server', None), getattr(options, 'end_point', None), getattr(options, 'port', None)
if server == None:
server = s.server
if end_point == None:
end_point = s.end_point
if port == None:
port = s.port
uri = "%s://%s:%s@%s:%s%s" % (s.protocol, options['user'], options['passwd'], server, port, end_point)
info('uploading to %s', uri)
server = xmlrpclib.ServerProxy(uri, verbose=False)
try:
pluginId, versionId = server.plugin.upload(xmlrpclib.Binary(package_file.bytes()))
info("Plugin ID: %s", pluginId)
info("Version ID: %s", versionId)
package_file.unlink()
except xmlrpclib.Fault, err:
error("A fault occurred")
error("Fault code: %d", err.faultCode)
error("Fault string: %s", err.faultString)
except xmlrpclib.ProtocolError, err:
error("Protocol error")
error("%s : %s", err.errcode, err.errmsg)
if err.errcode == 403:
error("Invalid name and password?")