diff --git a/qgispluginci/translation.py b/qgispluginci/translation.py index 1df7616e..2a6b0bfa 100644 --- a/qgispluginci/translation.py +++ b/qgispluginci/translation.py @@ -3,6 +3,7 @@ import subprocess from pathlib import Path from pytransifex import Transifex +from pytransifex.exceptions import PyTransifexException from qgispluginci.parameters import Parameters from qgispluginci.exceptions import TranslationFailed, TransifexNoResource, TransifexManyResources from qgispluginci.utils import touch_file @@ -37,14 +38,24 @@ def __init__(self, parameters: Parameters, elif create_project: print('project does not exists on Transifex, creating one as {o}/{p}'.format(o=self.parameters.transifex_organization, p=self.parameters.transifex_project)) - self._t.create_project(slug=self.parameters.transifex_project, - repository_url=self.parameters.repository_url, - source_language_code=parameters.translation_source_language) + + # one might get '{"errors":[{"code":"conflict","title":"Conflict error","status":"409","detail":"Team with this Organization and Name already exists."}]}' + # when the "create_project" phase is ok, but failed on "create_resource" + try: + self._t.create_project(slug=self.parameters.transifex_project, + repository_url=self.parameters.repository_url, + source_language_code=parameters.translation_source_language) + except PyTransifexException as error: + if error.response.json()['errors'][0]['status'] != '409': + raise error + self.update_strings() print('creating resource in {o}/{p}/{r} with {f}'.format(o=self.parameters.transifex_organization, p=self.parameters.transifex_project, r=self.parameters.transifex_resource, f=self.ts_file)) + + print('PRINTTTT', self.parameters.transifex_project, self.ts_file, self.parameters.transifex_resource) self._t.create_resource(project_slug=self.parameters.transifex_project, path_to_file=self.ts_file, resource_slug=self.parameters.transifex_resource) @@ -60,7 +71,7 @@ def update_strings(self): source_files = [] for ext in ('py', 'ui'): for file in glob.glob('{dir}/**/*.{ext}'.format(dir=self.parameters.plugin_path, ext=ext), recursive=True): - source_files.append(file) + source_files.append(str(Path(file).relative_to('./qgis_plugin_ci_testing'))) touch_file(self.ts_file) @@ -69,11 +80,17 @@ def update_strings(self): with open(project_file, 'w') as f: assert f.write('CODECFORTR = UTF-8\n') assert f.write('SOURCES = {}\n'.format(' '.join(source_files))) - assert f.write('TRANSLATIONS = {}\n'.format(self.ts_file)) + assert f.write('TRANSLATIONS = {}\n'.format(Path(self.ts_file).relative_to('./qgis_plugin_ci_testing'))) f.flush() + f.close() cmd = [self.parameters.pylupdate5_path, '-noobsolete', str(project_file)] + print('running: ', cmd) + print('contents: ', open(project_file, "r").read()) + print(Path(self.ts_file).exists()) + print('contents: ', open(self.ts_file, "r").read()) + output = subprocess.run(cmd, capture_output=True, text=True) project_file.unlink() @@ -82,6 +99,8 @@ def update_strings(self): raise TranslationFailed(output.stderr) else: print('Successfully run pylupdate5: {}'.format(output.stdout)) + print(Path(self.ts_file).exists()) + print('contents: ', open(self.ts_file, "r").read()) def compile_strings(self): """