-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSConstruct
104 lines (85 loc) · 3.36 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os.path
from functools import partial
from lxml import etree
from lom2mlr.vdex.make_vdex import make_vdex
builders = {}
LANGS = ('eng', 'fra', 'rus')
def apply_stylesheet(sheet, params, target, source, env):
assert len(source) == 1, source
assert len(target) == 1, target
source = etree.parse(source[0].get_path())
result = sheet(source, **params)
with open(target[0].get_path(), 'w') as f:
f.write(etree.tounicode(result, pretty_print=True).encode('utf-8'))
trans_to_lang_sheet = etree.XSLT(etree.parse(
os.path.join('lom2mlr', 'translations', 'make_translation_tolang.xsl')))
trans_from_lang_sheet = etree.XSLT(etree.parse(
os.path.join('lom2mlr', 'translations', 'make_translation_fromlang.xsl')))
vdex_to_lang_sheet = etree.XSLT(etree.parse(
os.path.join('lom2mlr', 'vdex', 'make_translation_tolang.xsl')))
vdex_from_lang_sheet = etree.XSLT(etree.parse(
os.path.join('lom2mlr', 'vdex', 'make_translation_fromlang.xsl')))
skos_sheet = etree.XSLT(etree.parse(
os.path.join('lom2mlr', 'vdex', 'vdex2skos.xsl')))
correspondances_sheet = etree.XSLT(etree.parse(
os.path.join('lom2mlr', 'correspondances.xsl')))
trans_lang_builders = dict(
("Trans_" + lang,
Builder(action = partial(apply_stylesheet, trans_to_lang_sheet, {'lang': "'%s'" % (lang, )}),
suffix = '_%s.xsl' % (lang,),
src_suffix = '.xml'))
for lang in LANGS
)
builders.update(trans_lang_builders)
builders['Trans_mlr'] = Builder(
action = partial(apply_stylesheet, trans_from_lang_sheet, {}),
suffix = '_mlr.xsl',
src_suffix = '.xml')
vdex_lang_builders = dict(
("Vdex_" + lang,
Builder(action = partial(apply_stylesheet, vdex_to_lang_sheet, {'lang': "'%s'" % (lang, )}),
suffix = '_%s.xsl' % (lang,),
src_suffix = '.vdex'))
for lang in LANGS
)
builders.update(vdex_lang_builders)
builders['Vdex_mlr'] = Builder(
action = partial(apply_stylesheet, vdex_from_lang_sheet, {}),
suffix = '_mlr.xsl',
src_suffix = '.vdex')
builders['Vdex_skos'] = Builder(
action = partial(apply_stylesheet, skos_sheet, {}),
suffix = '.skos',
src_suffix = '.vdex')
builders['Correspondances'] = Builder(
action = partial(apply_stylesheet, correspondances_sheet, {}),
suffix = '_xsl.xsl',
src_suffix = '_type.xml')
def process_vdex(env, sources):
"""Process vdex"""
l = []
for source in sources:
l.extend([getattr(env, 'Vdex_' + lang )(source) for lang in LANGS])
l.append(env.Vdex_mlr(source))
l.append(env.Vdex_skos(source))
return l
def process_trans(env, source):
"""Process vdex"""
l = [getattr(env, 'Trans_' + lang )(source) for lang in LANGS]
l.append(env.Trans_mlr(source))
return l
def make_vdex_scons(target, source, env):
assert len(source) == 1, source
make_vdex(source[0].get_path())
builders['Txt_Vdex'] = Builder(action = make_vdex_scons,
suffix = '.vdex',
src_suffix = '.txt')
env = Environment(BUILDERS=builders)
env.AddMethod(process_vdex, "Process_vdex")
env.AddMethod(process_trans, "Process_trans")
env.Process_trans('lom2mlr/translations/translation.xml')
vdex_targets = []
for vdex in Glob('lom2mlr/vdex/*.txt'):
vdex_targets.extend(env.Txt_Vdex(vdex))
env.Process_vdex(vdex_targets)
env.Correspondances('lom2mlr/correspondances_type.xml')