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