1
1
#!/usr/bin/env python
2
2
"""Treescript android-l10n import and sync support.
3
3
"""
4
- import asyncio
5
4
import logging
6
5
import os
7
6
import shutil
8
7
import tempfile
9
- from compare_locales import parser , paths
8
+ from compare_locales import paths
10
9
11
- from scriptworker_client .aio import retry_async
12
10
from scriptworker_client .utils import run_command
13
11
14
12
from treescript .exceptions import CheckoutError
15
13
from treescript .gecko import mercurial as vcs
16
- from treescript .util .task import CLOSED_TREE_MSG , DONTBUILD_MSG , get_dontbuild , get_ignore_closed_tree , get_android_l10n_import_info , get_android_l10n_sync_info , get_short_source_repo
14
+ from treescript .util .task import (
15
+ CLOSED_TREE_MSG ,
16
+ DONTBUILD_MSG ,
17
+ get_dontbuild ,
18
+ get_ignore_closed_tree ,
19
+ get_android_l10n_import_info ,
20
+ get_android_l10n_sync_info ,
21
+ get_short_source_repo ,
22
+ )
17
23
from treescript .util .treestatus import check_treestatus
18
24
19
25
log = logging .getLogger (__name__ )
@@ -161,15 +167,13 @@ async def android_l10n_import(config, task, repo_path):
161
167
162
168
description = "Import translations from android-l10n"
163
169
task_info = get_android_l10n_import_info (task )
164
- from_repo_path = tempfile .mkdtemp ()
165
- try :
170
+ with tempfile .TemporaryDirectory () as tmp :
171
+ from_repo_path = os . path . join ( tmp , "android-l10n-import" )
166
172
from_repo_url = task_info ["from_repo_url" ]
167
173
cmd = ["git" , "clone" , from_repo_url , from_repo_path ]
168
174
await run_command (cmd , exception = CheckoutError )
169
175
search_path = None
170
176
changes = await android_l10n_action (config , task , task_info , repo_path , from_repo_path , description , search_path , None , "dest_path" )
171
- finally :
172
- shutil .rmtree (from_repo_path , ignore_errors = True )
173
177
174
178
return changes
175
179
@@ -196,13 +200,11 @@ async def android_l10n_sync(config, task, repo_path):
196
200
197
201
description = "Merge android-l10n translations from mozilla-central"
198
202
task_info = get_android_l10n_sync_info (task )
199
- from_repo_path = tempfile .mkdtemp ()
200
- try :
203
+ with tempfile .TemporaryDirectory () as tmp :
204
+ from_repo_path = os . path . join ( tmp , "android-l10n-sync" )
201
205
from_repo_url = task_info ["from_repo_url" ]
202
206
await vcs .checkout_repo (config , task , from_repo_url , from_repo_path )
203
207
search_path = from_repo_path
204
208
changes = await android_l10n_action (config , task , task_info , repo_path , from_repo_path , description , search_path , from_repo_path , "toml_path" )
205
- finally :
206
- shutil .rmtree (from_repo_path , ignore_errors = True )
207
209
208
210
return changes
0 commit comments