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