Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c46e9f

Browse files
author
Maciej Olko
committed
fetch command: don't stop downloading when there’s an error
1 parent 98db0aa commit 9c46e9f

1 file changed

Lines changed: 40 additions & 30 deletions

File tree

manage_translation.py

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ def fetch():
2727
Fetch translations from Transifex, remove source lines.
2828
"""
2929
if call("tx --version", shell=True) != 0:
30-
sys.stderr.write("The Transifex client app is required (pip install transifex-client).\n")
30+
sys.stderr.write(
31+
"The Transifex client app is required (pip install transifex-client).\n"
32+
)
3133
exit(1)
3234
lang = LANGUAGE
33-
pull_returncode = call(f'tx pull -l {lang} --minimum-perc=1 --force', shell=True)
35+
pull_returncode = call(
36+
f'tx pull -l {lang} --minimum-perc=1 --force --skip', shell=True
37+
)
3438
if pull_returncode != 0:
3539
exit(pull_returncode)
3640
for root, _, po_files in os.walk('.'):
@@ -41,9 +45,7 @@ def fetch():
4145
call(f'msgcat --no-location -o {po_path} {po_path}', shell=True)
4246

4347

44-
RESOURCE_NAME_MAP = {
45-
'glossary_': 'glossary'
46-
}
48+
RESOURCE_NAME_MAP = {'glossary_': 'glossary'}
4749
PROJECT_SLUG = 'python-39'
4850

4951

@@ -53,10 +55,12 @@ def recreate_tx_config():
5355
"""
5456
resources = _get_resources()
5557
with open('.tx/config', 'w') as config:
56-
config.writelines((
57-
'[main]\n',
58-
'host = https://www.transifex.com\n',
59-
))
58+
config.writelines(
59+
(
60+
'[main]\n',
61+
'host = https://www.transifex.com\n',
62+
)
63+
)
6064
for resource in resources:
6165
slug = resource['slug']
6266
name = RESOURCE_NAME_MAP.get(slug, slug)
@@ -66,25 +70,30 @@ def recreate_tx_config():
6670
directory, file_name = name.split('--')
6771
if match(r'\d+_\d+', file_name):
6872
file_name = file_name.replace('_', '.')
69-
config.writelines((
70-
'\n',
71-
f'[{PROJECT_SLUG}.{slug}]\n',
72-
f'trans.{LANGUAGE} = {directory}/{file_name}.po\n',
73-
'type = PO\n',
74-
'source_lang = en\n',
75-
))
73+
config.writelines(
74+
(
75+
'\n',
76+
f'[{PROJECT_SLUG}.{slug}]\n',
77+
f'trans.{LANGUAGE} = {directory}/{file_name}.po\n',
78+
'type = PO\n',
79+
'source_lang = en\n',
80+
)
81+
)
7682
else:
77-
config.writelines((
78-
'\n',
79-
f'[{PROJECT_SLUG}.{slug}]\n',
80-
f'trans.{LANGUAGE} = {name}.po\n',
81-
'type = PO\n',
82-
'source_lang = en\n',
83-
))
83+
config.writelines(
84+
(
85+
'\n',
86+
f'[{PROJECT_SLUG}.{slug}]\n',
87+
f'trans.{LANGUAGE} = {name}.po\n',
88+
'type = PO\n',
89+
'source_lang = en\n',
90+
)
91+
)
8492

8593

8694
def _get_resources():
8795
from requests import get
96+
8897
resources = []
8998
offset = 0
9099
if os.path.exists('.tx/api-key'):
@@ -96,7 +105,8 @@ def _get_resources():
96105
response = get(
97106
f'https://api.transifex.com/organizations/python-doc/projects/{PROJECT_SLUG}/resources/',
98107
params={'language_code': LANGUAGE, 'offset': offset},
99-
auth=('api', transifex_api_key))
108+
auth=('api', transifex_api_key),
109+
)
100110
response.raise_for_status()
101111
response_list = response.json()
102112
resources.extend(response_list)
@@ -112,18 +122,18 @@ def _get_number_of_translators():
112122
capture_output=True,
113123
text=True,
114124
)
115-
translators = [
116-
match('(.*) <.*>', t).group(1) for t in process.stdout.splitlines()
117-
]
125+
translators = [match('(.*) <.*>', t).group(1) for t in process.stdout.splitlines()]
118126
unique_translators = Counter(translators).keys()
119127
return len(unique_translators)
120128

121129

122130
def recreate_readme():
123131
def language_switcher(entry):
124-
return (entry['name'].startswith('bugs') or
125-
entry['name'].startswith('tutorial') or
126-
entry['name'].startswith('library--functions'))
132+
return (
133+
entry['name'].startswith('bugs')
134+
or entry['name'].startswith('tutorial')
135+
or entry['name'].startswith('library--functions')
136+
)
127137

128138
def average(averages, weights):
129139
return sum([a * w for a, w in zip(averages, weights)]) / sum(weights)

0 commit comments

Comments
 (0)