Source code

Revision control

Other Tools

1
from __future__ import absolute_import↩
2
from __future__ import print_function↩
3
from lib.xul import collect_messages↩
4
from lib.dtd import get_dtds↩
5
from lib.utils import read_file, write_file↩
6
from lib.migration import build_migration↩
7
from lib.fluent import build_ftl↩
8
import json↩
9
import argparse↩
10
import sys↩
11
# import re↩
12
13
# To run this, you'll need to have lxml installed:↩
14
# `pip install lxml`↩
15
16
# default migration directions↩
17
data = {↩
18
'migration': 'python/l10n/fluent_migrations',↩
19
'description': 'Migrate l10n strings',↩
20
'prefix': ''
21
}↩
22
23
24
def parse_inputs():↩
25
sys_args = sys.argv[1:]↩
26
27
parser = argparse.ArgumentParser()↩
28
parser.add_argument('bug_id', type=str,↩
29
help='Id number for bug tracking')↩
30
parser.add_argument('xul', type=str,↩
31
help='POSIX path from mozilla-central to the XML to be updated')↩
32
parser.add_argument('ftl', type=str,↩
33
help='Case sensitive POSIX path from mozilla-central to desired ftl file')↩
34
parser.add_argument('mozilla_central', type=str,↩
35
help='Case sensitive absolute POSIX path to current mozilla-central repo')↩
36
parser.add_argument('dtd', type=str,↩
37
help='comma delimited list of case sensitive POSIX dtd file paths')↩
38
parser.add_argument('description', type=str,↩
39
help='string enclosed in quotes')↩
40
parser.add_argument('--dry-run', action='store_true',↩
41
help='Tell if running dry run or not')↩
42
parser.add_argument('--prefix', type=str,↩
43
help='a keyword string to be added to all l10n ids')↩
44
45
parsed_args = parser.parse_args(sys_args)↩
46
47
data['description'] = parsed_args.description↩
48
data['bug_id'] = parsed_args.bug_id↩
49
data['xul'] = parsed_args.xul↩
50
data['ftl'] = parsed_args.ftl↩
51
data['mozilla-central'] = parsed_args.mozilla_central↩
52
data['dtd'] = parsed_args.dtd.split(',')↩
53
data['dry-run'] = parsed_args.dry_run↩
54
data['prefix'] = parsed_args.prefix↩
55
data['recipe'] = "bug_{}_{}.py".format(data['bug_id'],↩
56
data['xul'].split('/')[-1].split('.')[0])↩
57
58
main()↩
59
60
61
def main():↩
62
dry_run = data['dry-run']↩
63
dtds = get_dtds(data['dtd'], data['mozilla-central'])↩
64
65
print('======== DTDs ========')↩
66
print(json.dumps(dtds, sort_keys=True, indent=2))↩
67
68
s = read_file(data['xul'], data['mozilla-central'])↩
69
70
print('======== INPUT ========')↩
71
print(s)↩
72
73
print('======== OUTPUT ========')↩
74
(new_xul, messages) = collect_messages(s, data['prefix'])↩
75
print(new_xul)↩
76
if not dry_run:↩
77
write_file(data['xul'], new_xul, data['mozilla-central'])↩
78
79
print('======== L10N ========')↩
80
81
print(json.dumps(messages, sort_keys=True, indent=2))↩
82
83
migration = build_migration(messages, dtds, data)↩
84
85
print('======== MIGRATION ========')↩
86
print(migration)↩
87
recipe_path = "{}/{}".format(data['migration'], data['recipe'])↩
88
if not dry_run:↩
89
write_file(recipe_path, migration, data['mozilla-central'])↩
90
91
ftl = build_ftl(messages, dtds, data)↩
92
93
print('======== Fluent ========')↩
94
print(ftl.encode("utf-8"))↩
95
if not dry_run:↩
96
write_file(data['ftl'], ftl.encode("utf-8"), data['mozilla-central'], append=True)↩
97
98
99
if __name__ == '__main__':↩
100
parse_inputs()↩