Skip to content
Browse files

update release packaging to be built from QGIS core

  • Loading branch information
tomkralidis committed Feb 24, 2015
1 parent af2bac9 commit 4792a92053e420d00414c66a5c91800d96507bae
Showing with 20 additions and 209 deletions.
  1. +20 −209 python/plugins/MetaSearch/
@@ -19,6 +19,7 @@

from ConfigParser import ConfigParser
import getpass
import os
import shutil
@@ -28,24 +29,27 @@
import xmlrpclib
import zipfile

from jinja2 import Environment, FileSystemLoader
from paver.easy import (call_task, cmdopts, error, info, needs, options, path,
from paver.easy import (call_task, cmdopts, error, info, options, path,
pushd, sh, task, Bunch)

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

with open('metadata.txt') as mf:
cp = ConfigParser()
VERSION = cp.get('general', 'version')

docs=path(BASEDIR) / 'docs',
plugin=path('%s/plugin/MetaSearch' % BASEDIR),
ui=path(BASEDIR) / 'plugin' / PLUGIN_NAME / 'ui',
install=path('%s/.qgis2/python/plugins/MetaSearch' % USERDIR),
tmp=path(path('%s/MetaSearch-dist' % USERDIR)),
@@ -55,15 +59,6 @@

def setup():
"""setup plugin dependencies"""

if not os.path.exists(options.base.ext_libs):
sh('pip install -r requirements.txt --target=%s' %

def clean():
"""clean environment"""
@@ -77,133 +72,13 @@ def clean():
if os.path.exists(options.base.ext_libs):
with pushd(
sh('%s clean' % sphinx_make())
for ui_file in os.listdir(options.base.ui):
if ui_file.endswith('.py') and ui_file != '':
os.remove(options.base.plugin / 'ui' / ui_file)
os.remove(path(options.base.home) / '' % PLUGIN_NAME)
sh('git clean -dxf')

def build_ui_files():
"""build ui files"""

# compile .ui files into Python
for ui_file in os.listdir(options.base.ui):
if ui_file.endswith('.ui'):
ui_file_basename = os.path.splitext(ui_file)[0]
sh('pyuic4 -o %s/ui/ %s/ui/%s.ui' % (options.base.plugin,
ui_file_basename, options.base.plugin, ui_file_basename))

def build_pro_file():
"""create .pro file"""


pyfiles = []
uifiles = []
trfiles = []

for root, dirs, files in os.walk(options.base.plugin / 'dialogs'):
for pfile in files:
if pfile.endswith('.py'):
filepath = os.path.join(root, pfile)
relpath = os.path.relpath(filepath, BASEDIR)
pyfiles.append(options.base.plugin / '')

for root, dirs, files in os.walk(options.base.plugin / 'ui'):
for pfile in files:
if pfile.endswith('.ui'):
filepath = os.path.join(root, pfile)
relpath = os.path.relpath(filepath, BASEDIR)

locale_dir = options.base.plugin / 'locale'
for loc_dir in os.listdir(locale_dir):
filepath = os.path.join(locale_dir, loc_dir, 'LC_MESSAGES', 'ui.ts')
relpath = os.path.relpath(filepath, BASEDIR)

with open('' % PLUGIN_NAME, 'w') as pro_file:
pro_file.write('SOURCES=%s\n' % ' '.join(pyfiles))
pro_file.write('FORMS=%s\n' % ' '.join(uifiles))
pro_file.write('TRANSLATIONS=%s\n' % ' '.join(trfiles))

def extract_messages():
"""generate .pot/.ts files from sources"""

# generate UI .ts file
sh('pylupdate4 -noobsolete')

# generate .po file from plugin templates
env = Environment(extensions=['jinja2.ext.i18n'],

msg_strings = []
for tfile in ['service_metadata.html', 'record_metadata_dc.html']:
html_file = options.base.plugin / 'resources/templates' / tfile
for msg in env.extract_translations(open(html_file).read()):
if msg[2] not in msg_strings:

po_file = options.base.plugin / 'locale/en/LC_MESSAGES/templates.po'
with open(po_file, 'w') as po_file_obj:
'\nmsgid ""\n'
'msgstr ""\n'
'"Project-Id-Version: MetaSearch 0.1-dev\\n"\n'
'"Report-Msgid-Bugs-To: \\n"\n'
'"POT-Creation-Date: 2014-02-25 12:58-0500\\n"\n'
'"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"\n'
'"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"\n'
'"Language-Team: LANGUAGE <>\\n"\n'
'"MIME-Version: 1.0\\n"\n'
'"Content-Type: text/plain; charset=UTF-8\\n"\n'
'"Content-Transfer-Encoding: 8bit\\n"\n\n')
for msg in msg_strings:
po_file_obj.write('msgid "%s"\nmsgstr ""\n\n' % msg)

# generate docs .po files
with pushd(
sh('make gettext')
locales_arg = ''
for lang in os.listdir('locale'):
locales_arg = '%s -l %s' % (locales_arg, lang)
sh('sphinx-intl update -p _build/locale %s' % locales_arg)

def compile_messages():
"""generate .qm/.po files"""

# generate UI .qm file

# generate all .mo files
locales = options.base.plugin / 'locale'

for locale_dir in os.listdir(locales):
with pushd(locales / locale_dir):
for filename in os.listdir('LC_MESSAGES'):
if filename.endswith('.po'):
with pushd('LC_MESSAGES'):
sh('msgfmt %s -o %s' %
(filename, filename.replace('.po', '.mo')))

# generate docs .mo files
with pushd(
sh('sphinx-intl build')

def install():
"""install plugin into user QGIS environment"""
@@ -225,66 +100,17 @@ def install():

def refresh_docs():
"""Build sphinx docs from scratch"""

make = sphinx_make()
with pushd(
sh('%s clean' % make)
sh('sphinx-intl build')
for lang in os.listdir( / 'locale'):
builddir = '%s/_build/%s' % (, lang)
sh('%s -e SPHINXOPTS="-D language=\'%s\'" -e BUILDDIR="%s" html' %
(make, lang, builddir))

def publish_docs():
"""this script publish Sphinx outputs to github pages"""

tempdir = options.base.tmp / 'tempdocs'

sh('git clone %s' %
with pushd(tempdir):
sh('git checkout gh-pages')
# copy English to root
sh('cp -rp %s/docs/_build/en/html/* .' % options.base.home)
# copy all other languages to their own dir
for lang in os.listdir( / '_build'):
if lang != 'en':
# point all resources to english
for res in ['_static', '_sources', '_images']:
sh('rm -fr %s/docs/_build/%s/html/%s' %
(options.base.home, lang, res))
# update .html files to point to English
for dfile in os.listdir( /
'_build/%s/html' % lang):
if dfile.endswith('.html'):
lfile = / '_build/%s/html/%s' % \
(lang, dfile)
source = open(lfile).read()
for res in ['_static', '_sources', '_images']:
source = source.replace(res, '../%s' % res)
with open(lfile, 'w') as fhl:
sh('mkdir -p %s' % lang)
sh('cp -rp %s/docs/_build/%s/html/* %s' %
(options.base.home, lang, lang))
sh('git add .')
sh('git commit -am "update live docs [ci skip]"')
sh('git push origin gh-pages')


@needs('setup', 'extract_messages', 'compile_messages')
def package():
"""create zip file of plugin"""

skip_files = [

package_file = get_package_filename()

if not os.path.exists(options.base.tmp):
@@ -294,11 +120,10 @@ def package():
with zipfile.ZipFile(package_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(options.base.plugin):
for file_add in files:
if file_add.endswith('.pyc'):
if file_add.endswith('.pyc') or file_add in skip_files:
filepath = os.path.join(root, file_add)
relpath = os.path.relpath(filepath,
os.path.join(BASEDIR, 'plugin'))
relpath = os.path.relpath(filepath)
zipf.write(filepath, relpath)
return package_file # return name of created zipfile

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

relpath = 'resources/connections-default.xml'
relpath = 'resources%sconnections-default.xml' % os.sep
csw_connections_xml = options.base.plugin / relpath

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

def sphinx_make():
"""return what command Sphinx is using for make"""

if == 'nt':
return 'make.bat'
return 'make'

def get_package_filename():
"""return filepath of plugin zipfile"""

filename = '' % (PLUGIN_NAME, options.base.version)
package_file = '%s/%s' % (options.base.tmp, filename)
return package_file

def get_translations():
"""get Transifex translations"""

sh('tx pull -a')

0 comments on commit 4792a92

Please sign in to comment.
You can’t perform that action at this time.