Skip to content

Commit

Permalink
push translations
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jul 7, 2019
1 parent f635dc2 commit 612e31e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 20 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ These scripts are written for and tested on GitHub, Travis-CI and Transifex.

## Base functionality

- Automatically push plugin releases to the QGIS plugin repository
- Automatically upload plugin releases to GitHub releases
- Create releases and write the changelog for releases on the GitHub web interface
- Push translation source strings to transifex on commits to master
- Pull the latest translations from transifex on release

## Advanced functionality

- Create a custom repository for QGIS plugins:
https://raw.githubusercontent.com/QGEP/qgepplugin/master/plugins.xml
- Deploy plugin releases on QGIS official plugin repository
- Publish plugin in Github releases, option to deploy a custom repository
- Easily integrated in Travis-CI
- Completely handle translations with Transifex: create the project and the languages, pull and push translations



- DEBUG, in plugin main file you can have a global variable as `DEBUG = True`, which will be changed to `False` when releasing the plugin.

Expand Down
57 changes: 51 additions & 6 deletions qgispluginci/release.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/python3

import os
import sys
import git
import tarfile
import zipfile
from tempfile import mkstemp
from glob import glob
from github import Github, GithubException
import xmlrpc.client
import re

from qgispluginci.parameters import Parameters
from qgispluginci.translation import Translation
Expand All @@ -17,7 +20,9 @@
def release(parameters: Parameters,
release_version: str,
github_token: str = None,
transifex_token: str = None):
transifex_token: str = None,
osgeo_username: str = None,
osgeo_password: str = None):

# set version in metadata
replace_in_file('{}/metadata.txt'.format(parameters.src_dir),
Expand All @@ -38,7 +43,10 @@ def release(parameters: Parameters,
release_version=release_version)
create_archive(parameters, output=output, add_translations=transifex_token is not None)
if github_token:
upload_archive_to_github(parameters, archive=output, release_tag=release_version, github_token=github_token)
upload_asset_to_github_release(parameters, archive=output, release_tag=release_version, github_token=github_token)
if osgeo_username is not None:
assert osgeo_password is not None
upload_plugin_to_osgeo(username=osgeo_username, password=osgeo_password, archive=output)


def create_archive(parameters: Parameters,
Expand Down Expand Up @@ -102,10 +110,10 @@ def create_archive(parameters: Parameters,
print('-------')


def upload_archive_to_github(parameters: Parameters,
archive: str,
release_tag: str,
github_token: str):
def upload_asset_to_github_release(parameters: Parameters,
archive: str,
release_tag: str,
github_token: str):

slug = '{}/{}'.format(parameters.organization_slug, parameters.project_slug)
repo = Github(github_token).get_repo(slug)
Expand All @@ -125,4 +133,41 @@ def upload_archive_to_github(parameters: Parameters,
raise GithubReleaseCouldNotUploadAsset('Could not upload asset for release {}.'.format(release_tag))


def upload_plugin_to_osgeo(username: str, password: str, archive: str):
"""
Upload the plugin to QGIS repository
Parameters
----------
username
The username
password
The password
archive
The plugin archive file path to be uploaded
"""
address = "https://{username}:{password}@plugins.qgis.org:443/plugins/RPC2/".format(
username=username,
password=password)

server = xmlrpc.client.ServerProxy(address, verbose=False)

try:
with open(archive, 'rb') as handle:
plugin_id, version_id = server.plugin.upload(
xmlrpc.client.Binary(handle.read()))
print("Plugin ID: %s" % plugin_id)
print("Version ID: %s" % version_id)
except xmlrpc.client.ProtocolError as err:
print("A protocol error occurred")
print("URL: %s" % re.sub(r':[^/].*@', ':******@', err.url))
print("HTTP/HTTPS headers: %s" % err.headers)
print("Error code: %d" % err.errcode)
print("Error message: %s" % err.errmsg)
sys.exit(1)
except xmlrpc.client.Fault as err:
print("A fault occurred")
print("Fault code: %d" % err.faultCode)
print("Fault string: %s" % err.faultString)
sys.exit(1)

5 changes: 4 additions & 1 deletion qgispluginci/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def pull(self):
self._t.get_translation(self.parameters.project_slug, resource['slug'], lang, ts_file)

def push(self):
pass
resource = self.__get_resource()
self._t.update_source_translation(project_slug=self.parameters.project_slug,
resource_slug=resource['slug'],
path_to_file=self.ts_file)

def __get_resource(self) -> dict:
resources = self._t.list_resources(self.parameters.project_slug)
Expand Down
9 changes: 6 additions & 3 deletions scripts/qgis-plugin-ci
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ if __name__ == "__main__":
'If specified, the archive will be pushed to an already '
'existing release.')


# pull-translation
pull_tr_parser = subparsers.add_parser('pull-translation', help='release the plugin')
pull_tr_parser = subparsers.add_parser('pull-translation', help='pull translations from Transifex')
pull_tr_parser.add_argument('transifex_token', help='The Transifex API token')

# push-translation
push_tr_parser = subparsers.add_parser('push-translation', help='release the plugin')
push_tr_parser = subparsers.add_parser('push-translation', help='update strings and push translations')
push_tr_parser.add_argument('transifex_token', help='The Transifex API token')

args = parser.parse_args()
Expand Down Expand Up @@ -63,7 +64,9 @@ if __name__ == "__main__":
if not success:
exit_val = 1
elif args.command == 'push-translation':
success = Translation(parameters, args.transifex_token).push()
t = Translation(parameters, args.transifex_token)
t.update_strings()
t.push()
if not success:
exit_val = 1

Expand Down
21 changes: 21 additions & 0 deletions templates/plugins.xml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<plugins>
<pyqgis_plugin name="__PLUGIN_NAME__" version="__RELEASE_VERSION__">
<description><![CDATA[__DESCRIPTION__]]></description>
<version>__RELEASE_VERSION__</version>
<qgis_minimum_version>__QGIS_MIN_VERSION__</qgis_minimum_version>
<homepage>http://github.com/__ORG__/__REPO__</homepage>
<file_name>__PLUGINZIP__</file_name>
<icon>__ICON__</icon>
<author_name>__AUTHOR__</author_name>
<download_url>https://github.com/__ORG__/__REPO__/releases/download/__TAG_VERSION__/__PLUGINZIP__</download_url>
<uploaded_by>__OSGEO_USERNAME__</uploaded_by>
<create_date>__CREATE_DATE__</create_date>
<update_date>__RELEASE_DATE__</update_date>
<experimental>__EXPERIMENTAL__</experimental>
<deprecated>__DEPRECATED__</deprecated>
<tracker>https://github.com/__ORG__/__REPO__/issues</tracker>
<repository>https://github.com/__ORG__/__REPO__</repository>
<tags>__TAGS__</tags>
</pyqgis_plugin>
</plugins>
4 changes: 4 additions & 0 deletions test/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def test_pull(self):
self.t.pull()
self.t.compile_strings()

def test_push(self):
self.t.update_strings()
self.t.push()


if __name__ == '__main__':
unittest.main()

0 comments on commit 612e31e

Please sign in to comment.