19
19
#
20
20
###############################################################################
21
21
22
+ from ConfigParser import ConfigParser
22
23
import getpass
23
24
import os
24
25
import shutil
28
29
import xmlrpclib
29
30
import zipfile
30
31
31
- from jinja2 import Environment , FileSystemLoader
32
- from paver .easy import (call_task , cmdopts , error , info , needs , options , path ,
32
+ from paver .easy import (call_task , cmdopts , error , info , options , path ,
33
33
pushd , sh , task , Bunch )
34
34
35
35
PLUGIN_NAME = 'MetaSearch'
36
36
BASEDIR = os .path .abspath (os .path .dirname (__file__ ))
37
37
USERDIR = os .path .expanduser ('~' )
38
38
39
+ with open ('metadata.txt' ) as mf :
40
+ cp = ConfigParser ()
41
+ cp .readfp (mf )
42
+ VERSION = cp .get ('general' , 'version' )
43
+
39
44
options (
40
45
base = Bunch (
41
46
home = BASEDIR ,
42
- docs = path (BASEDIR ) / 'docs' ,
43
- plugin = path ('%s/plugin/MetaSearch' % BASEDIR ),
47
+ plugin = path (BASEDIR ),
44
48
ui = path (BASEDIR ) / 'plugin' / PLUGIN_NAME / 'ui' ,
45
49
install = path ('%s/.qgis2/python/plugins/MetaSearch' % USERDIR ),
46
50
ext_libs = path ('plugin/MetaSearch/ext-libs' ),
47
51
tmp = path (path ('%s/MetaSearch-dist' % USERDIR )),
48
- version = open ( ' VERSION.txt' ). read (). strip ()
52
+ version = VERSION
49
53
),
50
54
upload = Bunch (
51
55
host = 'plugins.qgis.org' ,
55
59
)
56
60
57
61
58
- @task
59
- def setup ():
60
- """setup plugin dependencies"""
61
-
62
- if not os .path .exists (options .base .ext_libs ):
63
- sh ('pip install -r requirements.txt --target=%s' %
64
- options .base .ext_libs )
65
-
66
-
67
62
@task
68
63
def clean ():
69
64
"""clean environment"""
@@ -77,133 +72,13 @@ def clean():
77
72
shutil .rmtree (options .base .tmp )
78
73
if os .path .exists (options .base .ext_libs ):
79
74
shutil .rmtree (options .base .ext_libs )
80
- with pushd (options .base .docs ):
81
- sh ('%s clean' % sphinx_make ())
82
75
for ui_file in os .listdir (options .base .ui ):
83
76
if ui_file .endswith ('.py' ) and ui_file != '__init__.py' :
84
77
os .remove (options .base .plugin / 'ui' / ui_file )
85
78
os .remove (path (options .base .home ) / '%s.pro' % PLUGIN_NAME )
86
79
sh ('git clean -dxf' )
87
80
88
81
89
- @task
90
- def build_ui_files ():
91
- """build ui files"""
92
-
93
- # compile .ui files into Python
94
- for ui_file in os .listdir (options .base .ui ):
95
- if ui_file .endswith ('.ui' ):
96
- ui_file_basename = os .path .splitext (ui_file )[0 ]
97
- sh ('pyuic4 -o %s/ui/%s.py %s/ui/%s.ui' % (options .base .plugin ,
98
- ui_file_basename , options .base .plugin , ui_file_basename ))
99
-
100
-
101
- @task
102
- def build_pro_file ():
103
- """create .pro file"""
104
-
105
- get_translations ()
106
-
107
- pyfiles = []
108
- uifiles = []
109
- trfiles = []
110
-
111
- for root , dirs , files in os .walk (options .base .plugin / 'dialogs' ):
112
- for pfile in files :
113
- if pfile .endswith ('.py' ):
114
- filepath = os .path .join (root , pfile )
115
- relpath = os .path .relpath (filepath , BASEDIR )
116
- pyfiles .append (relpath )
117
- pyfiles .append (options .base .plugin / 'plugin.py' )
118
-
119
- for root , dirs , files in os .walk (options .base .plugin / 'ui' ):
120
- for pfile in files :
121
- if pfile .endswith ('.ui' ):
122
- filepath = os .path .join (root , pfile )
123
- relpath = os .path .relpath (filepath , BASEDIR )
124
- uifiles .append (relpath )
125
-
126
- locale_dir = options .base .plugin / 'locale'
127
- for loc_dir in os .listdir (locale_dir ):
128
- filepath = os .path .join (locale_dir , loc_dir , 'LC_MESSAGES' , 'ui.ts' )
129
- relpath = os .path .relpath (filepath , BASEDIR )
130
- trfiles .append (relpath )
131
-
132
- with open ('%s.pro' % PLUGIN_NAME , 'w' ) as pro_file :
133
- pro_file .write ('SOURCES=%s\n ' % ' ' .join (pyfiles ))
134
- pro_file .write ('FORMS=%s\n ' % ' ' .join (uifiles ))
135
- pro_file .write ('TRANSLATIONS=%s\n ' % ' ' .join (trfiles ))
136
-
137
-
138
- @task
139
- @needs (['build_pro_file' ])
140
- def extract_messages ():
141
- """generate .pot/.ts files from sources"""
142
-
143
- # generate UI .ts file
144
- sh ('pylupdate4 -noobsolete MetaSearch.pro' )
145
-
146
- # generate .po file from plugin templates
147
- env = Environment (extensions = ['jinja2.ext.i18n' ],
148
- loader = FileSystemLoader (options .base .plugin ))
149
-
150
- msg_strings = []
151
- for tfile in ['service_metadata.html' , 'record_metadata_dc.html' ]:
152
- html_file = options .base .plugin / 'resources/templates' / tfile
153
- for msg in env .extract_translations (open (html_file ).read ()):
154
- if msg [2 ] not in msg_strings :
155
- msg_strings .append (msg [2 ])
156
-
157
- po_file = options .base .plugin / 'locale/en/LC_MESSAGES/templates.po'
158
- with open (po_file , 'w' ) as po_file_obj :
159
- po_file_obj .write (
160
- '\n msgid ""\n '
161
- 'msgstr ""\n '
162
- '"Project-Id-Version: MetaSearch 0.1-dev\\ n"\n '
163
- '"Report-Msgid-Bugs-To: \\ n"\n '
164
- '"POT-Creation-Date: 2014-02-25 12:58-0500\\ n"\n '
165
- '"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\ n"\n '
166
- '"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\ n"\n '
167
- '"Language-Team: LANGUAGE <LL@li.org>\\ n"\n '
168
- '"MIME-Version: 1.0\\ n"\n '
169
- '"Content-Type: text/plain; charset=UTF-8\\ n"\n '
170
- '"Content-Transfer-Encoding: 8bit\\ n"\n \n ' )
171
- for msg in msg_strings :
172
- po_file_obj .write ('msgid "%s"\n msgstr ""\n \n ' % msg )
173
-
174
- # generate docs .po files
175
- with pushd (options .base .docs ):
176
- sh ('make gettext' )
177
- locales_arg = ''
178
- for lang in os .listdir ('locale' ):
179
- locales_arg = '%s -l %s' % (locales_arg , lang )
180
- sh ('sphinx-intl update -p _build/locale %s' % locales_arg )
181
-
182
-
183
- @task
184
- @needs ('build_pro_file' )
185
- def compile_messages ():
186
- """generate .qm/.po files"""
187
-
188
- # generate UI .qm file
189
- sh ('lrelease MetaSearch.pro' )
190
-
191
- # generate all .mo files
192
- locales = options .base .plugin / 'locale'
193
-
194
- for locale_dir in os .listdir (locales ):
195
- with pushd (locales / locale_dir ):
196
- for filename in os .listdir ('LC_MESSAGES' ):
197
- if filename .endswith ('.po' ):
198
- with pushd ('LC_MESSAGES' ):
199
- sh ('msgfmt %s -o %s' %
200
- (filename , filename .replace ('.po' , '.mo' )))
201
-
202
- # generate docs .mo files
203
- with pushd (options .base .docs ):
204
- sh ('sphinx-intl build' )
205
-
206
-
207
82
@task
208
83
def install ():
209
84
"""install plugin into user QGIS environment"""
@@ -225,66 +100,17 @@ def install():
225
100
226
101
227
102
@task
228
- def refresh_docs ():
229
- """Build sphinx docs from scratch"""
230
-
231
- get_translations ()
232
- make = sphinx_make ()
233
- with pushd (options .base .docs ):
234
- sh ('%s clean' % make )
235
- sh ('sphinx-intl build' )
236
- for lang in os .listdir (options .base .docs / 'locale' ):
237
- builddir = '%s/_build/%s' % (options .base .docs , lang )
238
- sh ('%s -e SPHINXOPTS="-D language=\' %s\' " -e BUILDDIR="%s" html' %
239
- (make , lang , builddir ))
240
-
241
-
242
- @task
243
- @needs ('refresh_docs' )
244
- def publish_docs ():
245
- """this script publish Sphinx outputs to github pages"""
246
-
247
- tempdir = options .base .tmp / 'tempdocs'
248
-
249
- sh ('git clone git@github.com:geopython/MetaSearch.git %s' %
250
- tempdir )
251
- with pushd (tempdir ):
252
- sh ('git checkout gh-pages' )
253
- # copy English to root
254
- sh ('cp -rp %s/docs/_build/en/html/* .' % options .base .home )
255
- # copy all other languages to their own dir
256
- for lang in os .listdir (options .base .docs / '_build' ):
257
- if lang != 'en' :
258
- # point all resources to english
259
- for res in ['_static' , '_sources' , '_images' ]:
260
- sh ('rm -fr %s/docs/_build/%s/html/%s' %
261
- (options .base .home , lang , res ))
262
- # update .html files to point to English
263
- for dfile in os .listdir (options .base .docs /
264
- '_build/%s/html' % lang ):
265
- if dfile .endswith ('.html' ):
266
- lfile = options .base .docs / '_build/%s/html/%s' % \
267
- (lang , dfile )
268
- source = open (lfile ).read ()
269
- for res in ['_static' , '_sources' , '_images' ]:
270
- source = source .replace (res , '../%s' % res )
271
- with open (lfile , 'w' ) as fhl :
272
- fhl .write (source )
273
- sh ('mkdir -p %s' % lang )
274
- sh ('cp -rp %s/docs/_build/%s/html/* %s' %
275
- (options .base .home , lang , lang ))
276
- sh ('git add .' )
277
- sh ('git commit -am "update live docs [ci skip]"' )
278
- sh ('git push origin gh-pages' )
279
-
280
- tempdir .rmtree ()
281
-
282
-
283
- @task
284
- @needs ('setup' , 'extract_messages' , 'compile_messages' )
285
103
def package ():
286
104
"""create zip file of plugin"""
287
105
106
+ skip_files = [
107
+ 'AUTHORS.txt' ,
108
+ 'CMakeLists.txt' ,
109
+ 'requirements.txt' ,
110
+ 'requirements-dev.txt' ,
111
+ 'pavement.txt'
112
+ ]
113
+
288
114
package_file = get_package_filename ()
289
115
290
116
if not os .path .exists (options .base .tmp ):
@@ -294,11 +120,10 @@ def package():
294
120
with zipfile .ZipFile (package_file , 'w' , zipfile .ZIP_DEFLATED ) as zipf :
295
121
for root , dirs , files in os .walk (options .base .plugin ):
296
122
for file_add in files :
297
- if file_add .endswith ('.pyc' ):
123
+ if file_add .endswith ('.pyc' ) or file_add in skip_files :
298
124
continue
299
125
filepath = os .path .join (root , file_add )
300
- relpath = os .path .relpath (filepath ,
301
- os .path .join (BASEDIR , 'plugin' ))
126
+ relpath = os .path .relpath (filepath )
302
127
zipf .write (filepath , relpath )
303
128
return package_file # return name of created zipfile
304
129
@@ -352,7 +177,7 @@ def upload():
352
177
def test_default_csw_connections ():
353
178
"""test that the default CSW connections work"""
354
179
355
- relpath = 'resources/connections -default.xml'
180
+ relpath = 'resources%sconnections -default.xml' % os . sep
356
181
csw_connections_xml = options .base .plugin / relpath
357
182
358
183
csws = etree .parse (csw_connections_xml )
@@ -375,23 +200,9 @@ def test_default_csw_connections():
375
200
raise ValueError ('root element should be csw:Capabilities' )
376
201
377
202
378
- def sphinx_make ():
379
- """return what command Sphinx is using for make"""
380
-
381
- if os .name == 'nt' :
382
- return 'make.bat'
383
- return 'make'
384
-
385
-
386
203
def get_package_filename ():
387
204
"""return filepath of plugin zipfile"""
388
205
389
206
filename = '%s-%s.zip' % (PLUGIN_NAME , options .base .version )
390
207
package_file = '%s/%s' % (options .base .tmp , filename )
391
208
return package_file
392
-
393
-
394
- def get_translations ():
395
- """get Transifex translations"""
396
-
397
- sh ('tx pull -a' )
0 commit comments