]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/create-weblinks-itexi.py
Doc: [web] create-weblinks-itexi.py: warn instead of barf when key is missing.
[lilypond.git] / scripts / build / create-weblinks-itexi.py
1 #!@PYTHON@
2 # -*- coding: utf-8 -*-
3 # create-version-itexi.py
4
5 """ when being called on lilypond.org, pass it the location of the
6 top source dir on the command-line. """
7
8 import sys
9 import os
10 import glob
11
12 # these links are relative from /website/ on lilypond.org
13 depth = "../"
14
15 ### translation data -- shouldn't be here; see issue
16 ### http://code.google.com/p/lilypond/issues/detail?id=1050
17
18 langs = ['', 'de', 'es', 'fr', 'hu', 'it', 'ja', 'nl']
19
20 # Get/update node translations
21 '''
22 for i in de es fr hu it ja nl; do
23     echo "'"$i"': {"
24     (echo '--' ; grep -nH -B1 translationof Documentation/$i/web/* ) \
25         | pytt '^--\n.*@(?:unnum|sub)[^ ]* (.*)\n.*@translationof (.*)\n' "'\2': '\1',\n" \
26         | grep -E 'Source|Learning|Glossary|Essay|Notation|Usage|Snippets|Web|Changes|Extending|Internals|Contributor'
27     echo "},"
28 done
29 '''
30
31 translations = {
32     'es': {
33         'Source': 'Código fuente',
34
35         'Learning': 'Aprendizaje',
36         'Music glossary': 'Glosario',
37         'Essay': 'Ensayo',
38         'Notation': 'Notación',
39         'Usage': 'Utilización',
40         'Snippets': 'Fragmentos',
41         'Web': 'Web',
42         'Changes': 'Cambios',
43         'Extending': 'Extensión',
44         'Internals': 'Funcionamiento interno',
45         'Contributor': 'Guía del colaborador',
46
47 # keep the spaces!
48         ' (split HTML)': ' (HTML seccionado)',
49         ' (big HTML)': ' (HTML monolítico)',
50
51         'Regression tests for ': 'Pruebas de regresión para ',
52         'PDF of regtests for ': 'Pruebas en PDF para ',
53         'MusicXML Regression tests for ': 'Pruebas de regresión de MusicXML para ',
54         'PDF of MusicXML regtests for ': 'Pruebas de MusicXML en PDF para ',
55
56         'Doc tarball for ': 'Tarball de la documentación para ',
57         ' (did not exist in 2.12)': ' (no existía en la versión 2.12)',
58      },
59     'fr': {
60         'Source': 'Sources',
61
62         'Learning': 'Initiation',
63         'Music glossary': 'Glossaire',
64         'Essay': 'Essai',
65         'Notation': 'Notation',
66         'Usage': 'Utilisation',
67         'Snippets': 'Morceaux choisis',
68         'Web': 'Web',
69         'Changes': 'Nouveautés',
70         'Extending': 'Extension',
71         'Internals': 'Propriétés internes',
72         'Contributor': 'Guide du contributeur',
73
74 # keep the spaces!
75         ' (split HTML)': ' (HTML multipages)',
76         ' (big HTML)': ' (HTML en page unique)',
77
78         'Regression tests for ': 'Tests de régression pour ',
79         'PDF of regtests for ': 'PDF des tests de régression pour ',
80         'MusicXML Regression tests for ': 'Tests de régression de MusicXML pour ',
81         'PDF of MusicXML regtests for ': 'PDF des tests de régression de MusicXML pour ',
82
83         'Doc tarball for ': 'Archive de la documentation pour ',
84         ' (did not exist in 2.12)': ' (non disponible pour la version 2.12)',
85         },
86     'nl': {
87         'Source': 'Broncode',
88
89         'Learning': 'Beginnen',
90         'Music glossary': 'Terminologie',
91         'Essay': 'Essay',
92         'Notation': 'Notatie',
93         'Usage': 'Gebruik',
94         'Snippets': 'Snippers',
95         'Web': 'Web',
96         'Changes': 'Veranderingen',
97         'Extending': 'Uitbreidingen',
98         'Internals': 'Internals',
99         'Contributor': 'Contributor',
100
101 # keep the spaces!
102         ' (split HTML)': ' (opgesplitste HTML)',
103         ' (big HTML)': ' (grote pagina HTML)',
104
105         'Regression tests for ': 'Regressietesten voor ',
106         'PDF of regtests for ': 'PDF van regressietesten voor ',
107         'MusicXML Regression tests for ': 'MusicXML regressietesten voor ',
108         'PDF of MusicXML regtests for ': 'MusicXML regressietesten voor ',
109
110         'Doc tarball for ': 'Tarball met documentation voor ',
111         ' (did not exist in 2.12)': ' (bestond nog niet in 2.12)',
112      },
113     'de': {
114         'Source': 'Quellen',
115         'Learning': 'Einführung',
116         'Music glossary': 'Glossar',
117         'Essay': 'Aufsatz',
118         'Notation': 'Notation',
119         'Usage': 'Benutzung',
120         'Snippets': 'Schnipsel',
121         'Web': 'Web',
122         'Changes': 'Änderungen',
123
124         #TODO
125         'Extending': 0,
126         'Internals': 'Interna',
127         'Contributor': 0,
128
129         ' (split HTML)': 0,
130         ' (big HTML)': 0,
131
132         'Regression tests for ': 0,
133         'PDF of regtests for ': 0,
134         'MusicXML Regression tests for ': 0,
135         'PDF of MusicXML regtests for ': 0,
136
137         'Doc tarball for ': 0,
138         ' (did not exist in 2.12)': 0,
139         },
140     'hu': {
141         'Source': 'Forrás',
142         'Learning': 'Tankönyv',
143         'Music glossary': 'Fogalomtár',
144         'Essay': 'Esszé',
145         'Notation': 'Kottaírás',
146         'Usage': 'Használat',
147         'Snippets': 'Kódrészletek',
148         'Web': 'Web',
149         'Changes': 'Változások',
150
151         #TODO
152         'Extending': 0,
153         'Internals': 'Belső működés',
154         'Contributor': 0,
155
156         ' (split HTML)': 0,
157         ' (big HTML)': 0,
158
159         'Regression tests for ': 0,
160         'PDF of regtests for ': 0,
161         'MusicXML Regression tests for ': 0,
162         'PDF of MusicXML regtests for ': 0,
163
164         'Doc tarball for ': 0,
165         ' (did not exist in 2.12)': 0,
166         },
167     'ja': {
168         'Source': 'ソース',
169         'Learning': '学習',
170         'Music glossary': '用語集',
171         'Essay': 'エッセー',
172         'Notation': '記譜法',
173         'Usage': '使用方法',
174         'Snippets': 'コード断片集',
175         'Web': 'Web',
176         'Changes': '変更点',
177
178         #TODO
179         'Extending': 0,
180         'Internals': '内部リファレンス',
181         'Contributor': 0,
182
183         ' (split HTML)': 0,
184         ' (big HTML)': 0,
185
186         'Regression tests for ': 0,
187         'PDF of regtests for ': 0,
188         'MusicXML Regression tests for ': 0,
189         'PDF of MusicXML regtests for ': 0,
190
191         'Doc tarball for ': 0,
192         ' (did not exist in 2.12)': 0,
193
194         },
195     }
196
197
198
199
200 ### actual program
201
202
203 VERSION_STABLE = ""
204 VERSION_DEVEL = ""
205
206 try:
207     topDir = sys.argv[1]
208 except:
209     myDir = os.path.dirname(sys.argv[0])
210     # use two abspaths to work around some windows python bug
211     topDir = os.path.join(os.path.abspath(myDir)+os.sep+'..'+os.sep+'..'+os.sep)
212     topDir = os.path.abspath( topDir )
213
214
215 # TODO: this might be useful for other scripts; can we make it available?
216 manuals = map(lambda x: os.path.splitext(x)[0],
217               map(os.path.basename,
218                   glob.glob(os.path.join(topDir,'Documentation', '*.te??'))))
219 #manuals = map(lambda x: 'glossary' if x=='music-glossary' else x, manuals)
220 manuals.append('internals')
221
222
223 version_file_path = os.path.join(topDir, "VERSION")
224
225 version_contents = open(version_file_path).readlines()
226 major = 0
227 minor = 0
228 patch = 0
229 for line in version_contents:
230     if (line.startswith('MAJOR_VERSION')):
231         major = line[14:-1]
232     if (line.startswith('MINOR_VERSION')):
233         minor = line[14:-1]
234     if (line.startswith('PATCH_LEVEL')):
235         patch = line[12:-1]
236     if (line.startswith('VERSION_STABLE')):
237         VERSION_STABLE = line[15:-1]
238     if (line.startswith('VERSION_DEVEL')):
239         VERSION_DEVEL = line[14:-1]
240
241 VERSION = str(major)+'.'+str(minor)+'.'+str(patch)
242
243 def _ (string, lang):
244     return translations.get (lang.split ('_')[0], {}).get (string, string)
245
246 getTrans = _
247 # let's not barf, but print a warning when something's missing
248 def getTrans(text, lang):
249     trans = _ (text, lang)
250     if not trans:
251         trans = text
252         sys.stderr.write ('create-weblinks-itexi: warning: [%(lang)s]: translation missing for: %(text)s\n' % locals ())
253     return trans
254
255 def macroLang(name, lang):
256     if (lang != ''):
257         return name + '-' + lang
258     return name
259
260 def make_macro(name, string):
261     print "@macro", name
262     print string
263     print "@end macro"
264     print ""
265
266 def make_download(name, osA, osB, version, revision, text):
267     string = "@uref{http://download.linuxaudio.org/lilypond/binaries/"
268     string += osA + "lilypond-"
269     string += version + "-" + revision
270     string += "." + osB + ",\n"
271     string += text
272     string += ": LilyPond "
273     string += version + "-" + revision
274     string += "}"
275     make_macro(name, string)
276
277 def make_download_source(name, vstring, version, lang):
278     string = "@uref{http://download.linuxaudio.org/lilypond/sources/"
279     string += vstring + "/"
280     string += "lilypond-" + version + ".tar.gz"
281     string += ", "
282     string += getTrans("Source", lang)
283     string += ": lilypond-" + version + ".tar.gz"
284     string += "}"
285     make_macro(macroLang(name,lang), string)
286
287 def make_all_downloads(macroName, version):
288     make_download("download"+macroName+"LinuxNormal", "linux-x86/",
289         "linux-x86.sh",    version, "1", "Linux x86")
290     make_download("download"+macroName+"LinuxBig", "linux-64/",
291         "linux-64.sh", version, "1", "Linux 64")
292     make_download("download"+macroName+"LinuxPPC", "linux-ppc/",
293         "linux-ppc.sh", version, "1", "Linux PPC")
294
295     make_download("download"+macroName+"FreeBSDNormal", "freebsd-x86/",
296         "freebsd-x86.sh", version, "1", "FreeBSD i386")
297     make_download("download"+macroName+"FreeBSDBig", "freebsd-64/",
298         "freebsd-64.sh", version, "1", "FreeBSD amd64")
299
300     make_download("download"+macroName+"DarwinNormal", "darwin-x86/",
301         "darwin-x86.tar.bz2", version, "1", "MacOS X x86")
302     make_download("download"+macroName+"DarwinPPC", "darwin-ppc/",
303         "darwin-ppc.tar.bz2", version, "1", "MacOS X PPC")
304
305     make_download("download"+macroName+"Windows", "mingw/",
306         "mingw.exe", version, "1", "Windows")
307
308 def make_ver_link(macroname, url, linktext):
309     string = "@uref{"
310     string += url
311     string += ","
312     string += linktext
313     string += "}"
314     make_macro(macroname, string)
315
316 # TODO: this kind of thing should really be in a central place for
317 # lilypond python build scripts
318 def translateNameToUrl(manual, version):
319     ver_split = version.split('.')
320     ver_minor = ver_split[0] + '.' + ver_split[1]
321     url = depth + "doc/v" + ver_minor + "/Documentation/"
322
323     if (ver_minor == '2.13'):
324         return url+manual
325     if (ver_minor == '2.12'):
326         if (manual=='learning'):
327             return url+'user/lilypond-learning'
328         elif (manual=='internals'):
329             return url+'user/lilypond-internals'
330         elif (manual=='notation'):
331             return url+'user/lilypond'
332         elif (manual=='usage'):
333             return url+'user/lilypond-program'
334         elif (manual=='snippets'):
335             return url+'../input/lsr/lilypond-snippets'
336         elif (manual=='changes'):
337             return url+'topdocs/NEWS.html'
338         elif (manual=='music-glossary'):
339             return url+'user/music-glossary'
340         elif (manual=='essay'):
341             return url+'user/lilypond-learning/Background.html'
342         elif (manual=='extending'):
343             return url+'user/lilypond/Interfaces-for-programmers.html'
344         else:
345             return ''
346
347
348 def make_manual_links(name, version, lang):
349     """Here is where all the macros manualStableLearningSplit,
350     manualStableLearningBig, manualStableLearningSplitNoName, etc. are
351     created on the fly.  Hopefully this documentation string will help
352     others a bit while grepping for those.
353     """
354     for m in manuals:
355         manual = m
356         # TODO: this is a stupid way of doing it
357         if (m=='music-glossary'):
358             mshort = 'Glossary'
359         else:
360             mshort = m.capitalize()
361         if (manual=='music-glossary'):
362             manual = 'Music glossary'
363         url = translateNameToUrl(m, version)
364
365         if (url == ''):
366             # can't have a comma here due to texinfo
367             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
368                 "http://lilypond.org",
369                 mshort+getTrans(" (did not exist in 2.12)",lang))
370             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
371                 "http://lilypond.org",
372                 mshort+getTrans(" (did not exist in 2.12)",lang))
373             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
374                 "http://lilypond.org",
375                 mshort+getTrans(" (did not exist in 2.12)",lang))
376             make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
377                 "http://lilypond.org",
378                 mshort+getTrans(" (did not exist in 2.12)",lang))
379             continue
380         make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
381                   url + '.pdf',
382                   getTrans(manual.capitalize(),lang) + '.pdf')
383         make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
384                   url + '/index.html',
385                   getTrans(manual.capitalize(),lang) +
386                   getTrans(' (split HTML)',lang))
387         make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
388                   url + '-big-page.html',
389                   getTrans(manual.capitalize(),lang) +
390                   getTrans(' (big HTML)',lang))
391         # this is stupid and I shouldn't have bothered trying
392         # to support the 2.12 docs and it will be deleted once
393         # 2.14 is out and the website won't be visible to users
394         # until 2.14 is out.  -gp
395         if (url.endswith('.html')):
396             newurl = url
397         else:
398             newurl = url + '/index.html'
399         make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
400                   newurl,
401                   getTrans(manual.capitalize(),lang))
402
403 def make_regtest_links(name, version, lang):
404     ver_split = version.split('.')
405     ver_minor = ver_split[0] + '.' + ver_split[1]
406     url = depth + "doc/v" + ver_minor + "/input/regression/"
407
408     make_ver_link(macroLang("regtest"+name, lang),
409         url+"collated-files.html",
410         getTrans("Regression tests for ", lang)+version)
411     make_ver_link(macroLang("regtest"+name+"Pdf", lang),
412         url+"collated-files.pdf",
413         getTrans("PDF of regtests for ", lang)+version)
414     make_ver_link(macroLang("regtest"+name+"Xml", lang),
415         url+"musicxml/collated-files.html",
416         getTrans("MusicXML Regression tests for ", lang)+version)
417     make_ver_link(macroLang("regtest"+name+"XmlPdf", lang),
418          url+"musicxml/collated-files.html",
419         getTrans("PDF of MusicXML regtests for ", lang)+version)
420
421 def make_doctarball_links(name, version, lang):
422     url = depth + "download/binaries/documentation/lilypond-"
423     # ugly FIXME, but proper build number support isn't Critical.
424     url += version + "-1"
425     url += ".documentation.tar.bz2"
426     make_ver_link(macroLang("doctarball"+name, lang),
427         url, getTrans("Doc tarball for ", lang)+version)
428
429 print "@c ************************ Download binaries ************"
430 make_all_downloads("Stable", VERSION_STABLE)
431 make_all_downloads("Devel", VERSION_DEVEL)
432
433 print "@c ************************ Download source ************"
434 # FIXME: icky hard-coding!  -gp
435 for lang in langs:
436     print "@c *********", lang, "***"
437     make_download_source("downloadStableSource","v2.12",VERSION_STABLE,lang)
438     make_download_source("downloadDevelSource","v2.13",VERSION_DEVEL,lang)
439
440 print "@c ************************ Manual links ************"
441 for lang in langs:
442     print "@c *********", lang, "***"
443     make_manual_links("Stable", VERSION_STABLE,lang)
444     make_manual_links("Devel", VERSION_DEVEL,lang)
445
446     make_doctarball_links("Stable", VERSION_STABLE,lang)
447     make_doctarball_links("Devel", VERSION_DEVEL,lang)
448
449 print "@c ************************ Regtest links ************"
450 for lang in langs:
451     print "@c *********", lang, "***"
452     make_regtest_links("Stable", VERSION_STABLE,lang)
453     make_regtest_links("Devel", VERSION_DEVEL,lang)
454
455