Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shadinaif committed Sep 14, 2023
1 parent 25434ff commit c4a5ae7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sync-translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
old_slug: xblock-done
old_project_slug: xblocks

- new_slug: drag-and-drop-v2
- new_slug: xblock-drag-and-drop-v2
old_slug: drag-and-drop-v2
old_project_slug: xblocks

Expand Down
8 changes: 8 additions & 0 deletions requirements/sync.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/sync.txt requirements/sync.in
#
pyyaml==6.0.1
# via -r requirements/sync.in
35 changes: 27 additions & 8 deletions scripts/sync_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import yaml

from transifex.api import transifex_api
from transifex.api.jsonapi import exceptions

NEW_PROJECT_SLUG = 'openedx-translations'
ORGANIZATION_SLUG = 'open-edx'
Expand Down Expand Up @@ -61,15 +62,21 @@ def get_resources_pair(self, new_slug, old_slug, old_project_slug):
new_project = projects.get(slug=NEW_PROJECT_SLUG)

new_resource_id = f'o:{ORGANIZATION_SLUG}:p:{new_project.slug}:r:{new_slug}'
new_resource = self.tx_api.Resource.get(id=new_resource_id)
print(f'new resource id: {new_resource_id}')
try:
new_resource = self.tx_api.Resource.get(id=new_resource_id)
except exceptions.JsonApiException_404_not_found:
print(f'Error: New resource not found: {new_resource_id}')
sys.exit(1)

old_resource_id = f'o:{ORGANIZATION_SLUG}:p:{old_project_slug}:r:{old_slug}'
print(f'old resource id: {old_resource_id}')
try:
old_resource = self.tx_api.Resource.get(id=old_resource_id)
except exceptions.JsonApiException_404_not_found:
print(f'Error: Old resource not found: {old_resource_id}')
sys.exit(1)

print(new_resource, new_resource.name, new_resource.id)

pair_id = f'o:{ORGANIZATION_SLUG}:p:{old_project_slug}:r:{old_slug}'
old_resource = self.tx_api.Resource.get(id=pair_id)
print(old_resource, old_resource.name)

print(f'Syncing {new_resource.name} from {old_resource.name}...')
return {
'old_resource': old_resource,
'new_resource': new_resource,
Expand Down Expand Up @@ -130,19 +137,31 @@ def sync_pair_into_new_resource(self, new_slug, old_slug, old_project_slug):
languages = self.get_languages()
resource_pair = self.get_resources_pair(new_slug, old_slug, old_project_slug)

print(f'Syncing {resource_pair["new_resource"].name} from {resource_pair["old_resource"].name}...')
print(f'Syncing: {languages}')
print(f' - from: {self.get_resource_url(resource_pair["old_resource"], old_project_slug)}')
print(f' - to: {self.get_resource_url(resource_pair["new_resource"], NEW_PROJECT_SLUG)}')

for lang_code in languages:
self.sync_translations(language_code=lang_code, **resource_pair)

print('-' * 80, '\n')

def run_from_workflow_yaml_file(self, workflow_configs):
"""
Run the script from a GitHub Actions migrate-from-transifex-old-project.yml workflow file.
"""
pairs_list = workflow_configs['jobs']['migrate-translations']['strategy']['matrix']['batch']

print('Verifying existence of resource pairs...')
for pair in pairs_list:
self.get_resources_pair(
new_slug=pair['new_slug'],
old_slug=pair['old_slug'],
old_project_slug=pair['old_project_slug'],
)
print('\n', '-' * 80, '\n')

for pair in pairs_list:
self.sync_pair_into_new_resource(
new_slug=pair['new_slug'],
Expand Down

0 comments on commit c4a5ae7

Please sign in to comment.