Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and why-not-try-calmer committed Feb 21, 2023
1 parent 856a49d commit 45136d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion qgispluginci/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys
import logging
import sys

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
21 changes: 11 additions & 10 deletions qgispluginci/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ def __init__(
"""
self.parameters = parameters
self._t = Transifex(
self.tx_client = Transifex(
api_token=transifex_token,
organization_name=parameters.transifex_organization,
i18n_type="QT",
)
assert self._t.ping()
assert self.tx_client.ping()
plugin_path = self.parameters.plugin_path
tx = self.parameters.transifex_resource
lang = self.parameters.translation_source_language
self.ts_file = f"{plugin_path}/i18n/{tx}_{lang}.ts"

if self._t.project_exists(parameters.transifex_project):
if self.tx_client.project_exists(parameters.transifex_project):
logger.debug(
f"Project {self.parameters.transifex_organization}/"
f"{self.parameters.transifex_project} exists on Transifex"
Expand All @@ -58,19 +58,20 @@ def __init__(
f"{self.parameters.transifex_organization}/"
f"{self.parameters.transifex_project}"
)
self._t.create_project(
self.tx_client.create_project(
project_slug=self.parameters.transifex_project,
private=False,
repository_url=self.parameters.repository_url,
source_language_code=parameters.translation_source_language,
)
assert self.tx_client.project_exists(self.parameters.transifex_project)
self.update_strings()
logger.debug(
f"Creating resource in {self.parameters.transifex_organization}/"
f"{self.parameters.transifex_project}/"
f"{self.parameters.transifex_resource} with {self.ts_file}"
)
self._t.create_resource(
self.tx_client.create_resource(
project_slug=self.parameters.transifex_project,
path_to_file=self.ts_file,
resource_slug=self.parameters.transifex_resource,
Expand Down Expand Up @@ -160,7 +161,7 @@ def pull(self):
Pull TS files from Transifex
"""
resource = self.__get_resource()
existing_langs = self._t.list_languages(
existing_langs = self.tx_client.list_languages(
project_slug=self.parameters.transifex_project,
resource_slug=resource["slug"],
)
Expand All @@ -172,7 +173,7 @@ def pull(self):
for lang in self.parameters.translation_languages:
if lang not in existing_langs:
logger.debug(f"Creating missing language: {lang}")
self._t.create_language(
self.tx_client.create_language(
project_slug=self.parameters.transifex_project,
language_code=lang,
coordinators=[self.parameters.transifex_coordinator],
Expand All @@ -181,7 +182,7 @@ def pull(self):
for lang in existing_langs:
ts_file = f"{self.parameters.plugin_path}/i18n/{self.parameters.transifex_resource}_{lang}.ts"
logger.debug(f"Downloading translation file: {ts_file}")
self._t.get_translation(
self.tx_client.get_translation(
project_slug=self.parameters.transifex_project,
resource_slug=resource["slug"],
language_code=lang,
Expand All @@ -194,15 +195,15 @@ def push(self):
f"Pushing resource: {self.parameters.transifex_resource} "
f"with file {self.ts_file}"
)
result = self._t.update_source_translation(
result = self.tx_client.update_source_translation(
project_slug=self.parameters.transifex_project,
resource_slug=resource["slug"],
path_to_file=self.ts_file,
)
logger.info(f"Translation resource updated: {result}")

def __get_resource(self) -> dict:
resources = self._t.list_resources(self.parameters.transifex_project)
resources = self.tx_client.list_resources(self.parameters.transifex_project)
if len(resources) == 0:
logger.error(
f"Project '{self.parameters.transifex_project}' has no resource on Transifex",
Expand Down
5 changes: 3 additions & 2 deletions test/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Logging
logger = logging.getLogger(__name__)


class TestTranslation(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand All @@ -35,12 +36,12 @@ def setUp(self):

def tearDown(self):
try:
self.t._t.delete_project(self.parameters.project_slug)
self.t.tx_client.delete_project(self.parameters.project_slug)
except PyTransifexException as error:
logger.debug(error)
"""
try:
self.t._t.delete_team(f"{self.parameters.project_slug}-team")
self.t.tx_client.delete_team(f"{self.parameters.project_slug}-team")
except PyTransifexException as error:
logger.debug(error)
"""
Expand Down

0 comments on commit 45136d3

Please sign in to comment.