-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create manage_tx.py #13
Open
rffontenelle
wants to merge
1
commit into
main
Choose a base branch
from
add-manage-tx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env python | ||
|
||
import json | ||
import os | ||
import re | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
from transifex.api import transifex_api | ||
|
||
# Version number of a new versioned project to create | ||
new_project_version = '3.11' | ||
|
||
transifex_api.setup(auth=os.getenv('TX_TOKEN')) | ||
|
||
ORG_SLUG = "python-doc" | ||
PROJ_SLUG = "python-newest" | ||
ORGANIZATION = transifex_api.Organization.get(slug=ORG_SLUG) | ||
PROJECT = ORGANIZATION.fetch('projects').get(slug=PROJ_SLUG) | ||
RESOURCES = transifex_api.Resource.filter(project=PROJECT).all() | ||
|
||
|
||
def __allow_translations_status(status): | ||
for resource in RESOURCES: | ||
print(f'{resource.name} ...') | ||
resource.attributes['accept_translations'] = status | ||
resource.save('accept_translations') | ||
|
||
|
||
def lock_resources(): | ||
__allow_translations_status(status=False) | ||
|
||
|
||
def unlock_resources(): | ||
__allow_translations_status(status=True) | ||
|
||
|
||
def fetch_translations(): | ||
"""Fetch translations from Transifex, remove source lines.""" | ||
pull_return_code = os.system(f'tx pull -all --force --skip') | ||
if pull_return_code != 0: | ||
exit(pull_return_code) | ||
|
||
|
||
def create_project(): | ||
""" | ||
Creates a new Transifex project with versioned name based on python-newest | ||
vers_proj_* = version project being created | ||
vers_res_* = resource of version project being created | ||
p.* = python-newest project | ||
r.* = resource of python-newest project | ||
|
||
""" | ||
p = PROJECT | ||
organization = ORGANIZATION | ||
vers_proj_slug = 'python-' + new_project_version.replace('.', '') | ||
vers_proj_name = f'Python {new_project_version}' | ||
print(f'Creating project: {vers_proj_name}') | ||
versioned_project = transifex_api.Project.create( | ||
description=vers_proj_name, | ||
homepage_url=p.attributes.get('homepage_url'), | ||
instructions_url=p.attributes.get('instructions_url'), | ||
license=p.attributes.get('license'), | ||
long_description=p.attributes.get('long_description'), | ||
machine_translation_fillup=p.attributes.get('machine_translation_fillup'), | ||
name=vers_proj_name, | ||
private=p.attributes.get('private'), | ||
repository_url=p.attributes.get('repository_url'), | ||
slug=vers_proj_slug, | ||
tags=p.attributes.get('tags'), | ||
team=p.fetch('team'), | ||
organization=organization, | ||
source_language=p.fetch('source_language'), | ||
translation_memory_fillup=p.attributes.get('translation_memory_fillup'), | ||
) | ||
|
||
print(f'Creating {vers_proj_name}\'s resources:') | ||
for r in RESOURCES: | ||
print(f'r.name ...') | ||
transifex_api.Resource.create( | ||
project=versioned_project, | ||
i18n_format=r.i18n_format, | ||
slug=r.slug, | ||
name=r.name, | ||
priority=r.priority, | ||
accept_translations=True | ||
) | ||
Comment on lines
+77
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this workaround when sphinx-doc/sphinx-intl#90 lands in the source code and gets released. |
||
|
||
|
||
if __name__ == "__main__": | ||
RUNNABLE_SCRIPTS = ('lock_resources', 'unlock_resources', 'fetch_translations', 'create_project') | ||
|
||
parser = ArgumentParser() | ||
parser.add_argument('cmd', nargs=1, choices=RUNNABLE_SCRIPTS) | ||
options = parser.parse_args() | ||
|
||
eval(options.cmd[0])() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I wonder if it wouldn't be easier for usage to accept this value from script argument
it can be hard to achieve with the argument parser we have now though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was my initial desire when I created it (i.e. when bumping python-newest to 3.12), but I didn't want to expend more time on argparse at the time. Any feedback is welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Fire (with version 1 or 4 from hello world docs) should be feasible replacement for argparse that would handle this one extra argument for selected command. Should be more minimal than e.g. Typer or Click which have more verbose API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked Fire, but it looks like it is not compatible with 3.11 (and because a small fix with PR open and not merged yet). I've came across with Typer and Click before. I guess this could be a good time to play with them.