Skip to content

Commit 4792a92

Browse files
committed
update release packaging to be built from QGIS core
1 parent af2bac9 commit 4792a92

File tree

1 file changed

+20
-209
lines changed

1 file changed

+20
-209
lines changed

python/plugins/MetaSearch/pavement.py

+20-209
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#
2020
###############################################################################
2121

22+
from ConfigParser import ConfigParser
2223
import getpass
2324
import os
2425
import shutil
@@ -28,24 +29,27 @@
2829
import xmlrpclib
2930
import zipfile
3031

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,
3333
pushd, sh, task, Bunch)
3434

3535
PLUGIN_NAME = 'MetaSearch'
3636
BASEDIR = os.path.abspath(os.path.dirname(__file__))
3737
USERDIR = os.path.expanduser('~')
3838

39+
with open('metadata.txt') as mf:
40+
cp = ConfigParser()
41+
cp.readfp(mf)
42+
VERSION = cp.get('general', 'version')
43+
3944
options(
4045
base=Bunch(
4146
home=BASEDIR,
42-
docs=path(BASEDIR) / 'docs',
43-
plugin=path('%s/plugin/MetaSearch' % BASEDIR),
47+
plugin=path(BASEDIR),
4448
ui=path(BASEDIR) / 'plugin' / PLUGIN_NAME / 'ui',
4549
install=path('%s/.qgis2/python/plugins/MetaSearch' % USERDIR),
4650
ext_libs=path('plugin/MetaSearch/ext-libs'),
4751
tmp=path(path('%s/MetaSearch-dist' % USERDIR)),
48-
version=open('VERSION.txt').read().strip()
52+
version=VERSION
4953
),
5054
upload=Bunch(
5155
host='plugins.qgis.org',
@@ -55,15 +59,6 @@
5559
)
5660

5761

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-
6762
@task
6863
def clean():
6964
"""clean environment"""
@@ -77,133 +72,13 @@ def clean():
7772
shutil.rmtree(options.base.tmp)
7873
if os.path.exists(options.base.ext_libs):
7974
shutil.rmtree(options.base.ext_libs)
80-
with pushd(options.base.docs):
81-
sh('%s clean' % sphinx_make())
8275
for ui_file in os.listdir(options.base.ui):
8376
if ui_file.endswith('.py') and ui_file != '__init__.py':
8477
os.remove(options.base.plugin / 'ui' / ui_file)
8578
os.remove(path(options.base.home) / '%s.pro' % PLUGIN_NAME)
8679
sh('git clean -dxf')
8780

8881

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-
'\nmsgid ""\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"\nmsgstr ""\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-
20782
@task
20883
def install():
20984
"""install plugin into user QGIS environment"""
@@ -225,66 +100,17 @@ def install():
225100

226101

227102
@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')
285103
def package():
286104
"""create zip file of plugin"""
287105

106+
skip_files = [
107+
'AUTHORS.txt',
108+
'CMakeLists.txt',
109+
'requirements.txt',
110+
'requirements-dev.txt',
111+
'pavement.txt'
112+
]
113+
288114
package_file = get_package_filename()
289115

290116
if not os.path.exists(options.base.tmp):
@@ -294,11 +120,10 @@ def package():
294120
with zipfile.ZipFile(package_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
295121
for root, dirs, files in os.walk(options.base.plugin):
296122
for file_add in files:
297-
if file_add.endswith('.pyc'):
123+
if file_add.endswith('.pyc') or file_add in skip_files:
298124
continue
299125
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)
302127
zipf.write(filepath, relpath)
303128
return package_file # return name of created zipfile
304129

@@ -352,7 +177,7 @@ def upload():
352177
def test_default_csw_connections():
353178
"""test that the default CSW connections work"""
354179

355-
relpath = 'resources/connections-default.xml'
180+
relpath = 'resources%sconnections-default.xml' % os.sep
356181
csw_connections_xml = options.base.plugin / relpath
357182

358183
csws = etree.parse(csw_connections_xml)
@@ -375,23 +200,9 @@ def test_default_csw_connections():
375200
raise ValueError('root element should be csw:Capabilities')
376201

377202

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-
386203
def get_package_filename():
387204
"""return filepath of plugin zipfile"""
388205

389206
filename = '%s-%s.zip' % (PLUGIN_NAME, options.base.version)
390207
package_file = '%s/%s' % (options.base.tmp, filename)
391208
return package_file
392-
393-
394-
def get_translations():
395-
"""get Transifex translations"""
396-
397-
sh('tx pull -a')

0 commit comments

Comments
 (0)