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