Fix bug 1399166: Use X-channel repo as source (#714)

Update the script to create per-project en-US only repositories from
the cross-channel repository. It is already limited to localizable
files only, and it also includes files from the comm-* repositories.

We now also clean up target directory on a failed pull, so that it's
empty for a clone. We also prune all subdirectories in target
repository in case they get removed from source.
This commit is contained in:
Matjaž Horvat 2017-10-05 18:26:36 +02:00 коммит произвёл GitHub
Родитель f12ef80df4
Коммит 8a9b9fd465
1 изменённых файлов: 50 добавлений и 69 удалений

Просмотреть файл

@ -19,41 +19,32 @@ import shutil
import subprocess import subprocess
TARGET_REPOS = { TARGET_REPOS = {
'firefox': { 'firefox': [
'folders': [ 'browser',
'browser', 'browser/branding/official', 'devtools',
'browser/extensions/onboarding', 'dom',
'browser/extensions/pocket', 'netwerk',
'browser/extensions/webcompat-reporter', 'security',
'devtools/client', 'devtools/shared', 'devtools/shim', 'services',
'dom', 'netwerk', 'security/manager', 'toolkit',
'services/sync', 'toolkit', 'webapprt', ],
], 'firefox-for-android': [
'source': 'mozilla', 'mobile',
}, ],
'firefox-for-android': { 'thunderbird': [
'folders': ['mobile', 'mobile/android', 'mobile/android/base'], 'chat',
'source': 'mozilla', 'editor',
}, 'mail',
'thunderbird': { 'other-licenses',
'folders': [ ],
'chat', 'editor/ui', 'mail', 'lightning': [
'other-licenses/branding/thunderbird' 'calendar',
], ],
'source': 'comm', 'seamonkey': [
}, 'suite',
'lightning': { ],
'folders': ['calendar'],
'source': 'comm',
},
'seamonkey': {
'folders': ['suite'],
'source': 'comm',
},
} }
SOURCE_REPOS = set(v["source"] for v in TARGET_REPOS.values())
def write(text): def write(text):
timestamp = datetime.datetime.now().strftime('[%Y-%m-%d %H:%M:%S] ') timestamp = datetime.datetime.now().strftime('[%Y-%m-%d %H:%M:%S] ')
@ -89,6 +80,10 @@ def pull(url, target):
write(text_type(error)) write(text_type(error))
write('Clone instead.') write('Clone instead.')
# Clean up target directory on a failed pull, so that it's empty for a clone
command = ["rm", "-rf", target]
code, output, error = execute(command)
code, output, error = execute(['hg', 'clone', url, target]) code, output, error = execute(['hg', 'clone', url, target])
if code == 0: if code == 0:
write('Repository at ' + url + ' cloned.') write('Repository at ' + url + ' cloned.')
@ -117,45 +112,31 @@ abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath) dname = os.path.dirname(abspath)
os.chdir(dname) os.chdir(dname)
for channel in ['beta', 'central']: # Clone or update source repository
for repo in SOURCE_REPOS: url = 'https://hg.mozilla.org/users/axel_mozilla.com/gecko-strings/'
ending = repo + '-' + channel target = 'source'
pull(url, target)
url_folder = '' for repo in TARGET_REPOS.keys():
if channel == 'central': ending = repo + '-central'
if repo == 'mozilla': url = 'ssh://hg.mozilla.org/users/m_owca.info/' + ending
url_folder = 'l10n/' target = os.path.join('target', ending)
else:
url_folder = 'releases/'
url = 'ssh://hg.mozilla.org/' + url_folder + ending # Clone or update target repository
target = os.path.join('source', ending) pull(url, target)
# Clone or update source repositories # Prune all subdirectories in target repository in case they get removed from source
pull(url, target) for subdir in os.listdir(target):
if not subdir.startswith('.'):
shutil.rmtree(os.path.join(target, subdir))
for repo in TARGET_REPOS.keys(): # Copy folders from source to target
ending = repo + '-' + channel for folder in TARGET_REPOS[repo]:
url = 'ssh://hg.mozilla.org/users/m_owca.info/' + ending origin = os.path.join('source', folder)
target = os.path.join('target', ending) destination = os.path.join('target', ending, folder)
# Clone or update target repositories if os.path.exists(origin):
pull(url, target) shutil.copytree(origin, destination)
# Copy folders from source to target # Commit and push target repositories
folders = TARGET_REPOS[repo]['folders'] push(target)
source = TARGET_REPOS[repo]['source'] + '-' + channel
for folder in folders:
origin = os.path.join('source', source, folder, 'locales/en-US')
destination = os.path.join('target', ending, folder)
if os.path.exists(destination):
shutil.rmtree(destination)
# Needed temporarily because devtools aren't moved in beta yet
if os.path.exists(origin):
shutil.copytree(origin, destination)
# Commit and push target repositories
push(target)