]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/create-weblinks-itexi.py
Web: enable Japanese website.
[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     'de': {
33         'Source': 'Quellen',
34         'Learning': 'Einführung',
35         'Music glossary': 'Glossar',
36         'Essay': 'Aufsatz',
37         'Notation': 'Notation',
38         'Usage': 'Benutzung',
39         'Snippets': 'Schnipsel',
40         'Web': 'Web',
41         'Changes': 'Änderungen',
42
43         'Extending': 'Erweitern',
44         'Internals': 'Interna',
45         'Contributor': 'Beitragen',
46
47         ' (split HTML)': ' (geteiltes HTML)',
48         ' (big HTML)': ' (großes HTML)',
49
50         'Regression tests for ': 'Regressionstests für ',
51         'PDF of regtests for ': 'PDF der Regressionstests für ',
52         'MusicXML Regression tests for ': 'MusicXML Regressionstests für ',
53         'PDF of MusicXML regtests for ': 'PDF der MusicXML Regressionstests für ',
54
55         'Doc tarball for ': 'Dokumentation tar-gepackt für ',
56         ' (did not exist in 2.12)': ' (nicht existent in 2.12)',
57         },
58     'es': {
59         'Source': 'Código fuente',
60
61         'Learning': 'Aprendizaje',
62         'Music glossary': 'Glosario',
63         'Essay': 'Ensayo',
64         'Notation': 'Notación',
65         'Usage': 'Utilización',
66         'Snippets': 'Fragmentos',
67         'Web': 'Web',
68         'Changes': 'Cambios',
69         'Extending': 'Extensión',
70         'Internals': 'Funcionamiento interno',
71         'Contributor': 'Guía del colaborador',
72
73 # keep the spaces!
74         ' (split HTML)': ' (HTML seccionado)',
75         ' (big HTML)': ' (HTML monolítico)',
76
77         'Regression tests for ': 'Pruebas de regresión para ',
78         'PDF of regtests for ': 'Pruebas en PDF para ',
79         'MusicXML Regression tests for ': 'Pruebas de regresión de MusicXML para ',
80         'PDF of MusicXML regtests for ': 'Pruebas de MusicXML en PDF para ',
81
82         'Doc tarball for ': 'Tarball de la documentación para ',
83         ' (did not exist in 2.12)': ' (no existía en la versión 2.12)',
84      },
85     'fr': {
86         'Source': 'Sources',
87
88         'Learning': 'Initiation',
89         'Music glossary': 'Glossaire',
90         'Essay': 'Essai',
91         'Notation': 'Notation',
92         'Usage': 'Utilisation',
93         'Snippets': 'Morceaux choisis',
94         'Web': 'Web',
95         'Changes': 'Nouveautés',
96         'Extending': 'Extension',
97         'Internals': 'Propriétés internes',
98         'Contributor': 'Guide du contributeur',
99
100 # keep the spaces!
101         ' (split HTML)': ' (HTML multipages)',
102         ' (big HTML)': ' (HTML en page unique)',
103
104         'Regression tests for ': 'Tests de régression pour ',
105         'PDF of regtests for ': 'PDF des tests de régression pour ',
106         'MusicXML Regression tests for ': 'Tests de régression de MusicXML pour ',
107         'PDF of MusicXML regtests for ': 'PDF des tests de régression de MusicXML pour ',
108
109         'Doc tarball for ': 'Archive de la documentation pour ',
110         ' (did not exist in 2.12)': ' (non disponible pour la version 2.12)',
111         },
112     'hu': {
113         'Source': 'Forrás',
114         'Learning': 'Tankönyv',
115         'Music glossary': 'Fogalomtár',
116         'Essay': 'Esszé',
117         'Notation': 'Kottaírás',
118         'Usage': 'Használat',
119         'Snippets': 'Kódrészletek',
120         'Web': 'Web',
121         'Changes': 'Változások',
122
123         #TODO
124         'Extending': 0,
125         'Internals': 'Belső működés',
126         'Contributor': 0,
127
128         ' (split HTML)': 0,
129         ' (big HTML)': 0,
130
131         'Regression tests for ': 0,
132         'PDF of regtests for ': 0,
133         'MusicXML Regression tests for ': 0,
134         'PDF of MusicXML regtests for ': 0,
135
136         'Doc tarball for ': 0,
137         ' (did not exist in 2.12)': 0,
138         },
139     'ja': {
140         'Source': 'ソース',
141         'Learning': '学習',
142         'Music glossary': '用語集',
143         'Essay': 'エッセー',
144         'Notation': '記譜法',
145         'Usage': '使用方法',
146         'Snippets': 'コード断片集',
147         'Web': 'Web',
148         'Changes': '変更点',
149
150         #TODO
151         'Extending': '拡張',
152         'Internals': '内部リファレンス',
153         'Contributor': '貢献者向けガイド',
154
155 # keep the spaces!
156         ' (split HTML)': ' (ページ毎に分割された HTML)',
157         ' (big HTML)': ' (1 つの大きな HTML)',
158
159         'Regression tests for ': '回帰テスト バージョン ',
160         'PDF of regtests for ': '回帰テスト (PDF 版) バージョン ',
161         'MusicXML Regression tests for ': 'MusicXML 回帰テスト バージョン ',
162         'PDF of MusicXML regtests for ': 'MusicXML 回帰テスト (PDF 版) バージョン ',
163
164         'Doc tarball for ': 'ドキュメント アーカイブ バージョン ',
165         ' (did not exist in 2.12)': ' (バージョン 2.12 には存在しません)',
166
167         },
168     'nl': {
169         'Source': 'Broncode',
170
171         'Learning': 'Beginnen',
172         'Music glossary': 'Terminologie',
173         'Essay': 'Essay',
174         'Notation': 'Notatie',
175         'Usage': 'Gebruik',
176         'Snippets': 'Snippers',
177         'Web': 'Web',
178         'Changes': 'Veranderingen',
179         'Extending': 'Uitbreidingen',
180         'Internals': 'Internals',
181         'Contributor': 'Contributor',
182
183 # keep the spaces!
184         ' (split HTML)': ' (opgesplitste HTML)',
185         ' (big HTML)': ' (grote pagina HTML)',
186
187         'Regression tests for ': 'Regressietesten voor ',
188         'PDF of regtests for ': 'PDF van regressietesten voor ',
189         'MusicXML Regression tests for ': 'MusicXML regressietesten voor ',
190         'PDF of MusicXML regtests for ': 'MusicXML regressietesten voor ',
191
192         'Doc tarball for ': 'Tarball met documentation voor ',
193         ' (did not exist in 2.12)': ' (bestond nog niet in 2.12)',
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 def addLang(url, lang):
348     if lang:
349         base, ext = os.path.splitext(url)
350         return base + '.' + lang + ext
351     else:
352         return url
353
354 def make_manual_links(name, version, lang):
355     """Here is where all the macros manualStableLearningSplit,
356     manualStableLearningBig, manualStableLearningSplitNoName, etc. are
357     created on the fly.  Hopefully this documentation string will help
358     others a bit while grepping for those.
359     """
360     for m in manuals:
361         manual = m
362         # TODO: this is a stupid way of doing it
363         if (m=='music-glossary'):
364             mshort = 'Glossary'
365         else:
366             mshort = m.capitalize()
367         if (manual=='music-glossary'):
368             manual = 'Music glossary'
369         url = translateNameToUrl(m, version)
370
371         if (url == ''):
372             # can't have a comma here due to texinfo
373             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
374                 "http://lilypond.org",
375                 mshort+getTrans(" (did not exist in 2.12)",lang))
376             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
377                 "http://lilypond.org",
378                 mshort+getTrans(" (did not exist in 2.12)",lang))
379             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
380                 "http://lilypond.org",
381                 mshort+getTrans(" (did not exist in 2.12)",lang))
382             make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
383                 "http://lilypond.org",
384                 mshort+getTrans(" (did not exist in 2.12)",lang))
385             continue
386         # this is stupid and I shouldn't have bothered trying
387         # to support the 2.12 docs and it will be deleted once
388         # 2.14 is out and the website won't be visible to users
389         # until 2.14 is out.  -gp
390         if (url.endswith('.html')):
391             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
392                       addLang(url, lang),
393                       getTrans(manual.capitalize(),lang) + '.pdf')
394             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
395                       addLang(url, lang),
396                       getTrans(manual.capitalize(),lang) +
397                       getTrans(' (split HTML)',lang))
398             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
399                       addLang(url, lang),
400                       getTrans(manual.capitalize(),lang) +
401                       getTrans(' (big HTML)',lang))
402             newurl = url
403         else:
404             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
405                       # TODO: this is an even stupider way of doing it
406                       addLang(url+'.pdf', lang),
407                       getTrans(manual.capitalize(),lang) + '.pdf')
408             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
409                       addLang(url + '/index.html', lang),
410                       getTrans(manual.capitalize(),lang) +
411                       getTrans(' (split HTML)',lang))
412             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
413                       addLang(url + '-big-page.html', lang),
414                       getTrans(manual.capitalize(),lang) +
415                       getTrans(' (big HTML)',lang))
416             newurl = url + '/index.html'
417         make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
418                   addLang(newurl, lang),
419                   getTrans(manual.capitalize(),lang))
420
421 def make_regtest_links(name, version, lang):
422     ver_split = version.split('.')
423     ver_minor = ver_split[0] + '.' + ver_split[1]
424     url = depth + "doc/v" + ver_minor + "/input/regression/"
425
426     make_ver_link(macroLang("regtest"+name, lang),
427         url+"collated-files.html",
428         getTrans("Regression tests for ", lang)+version)
429     make_ver_link(macroLang("regtest"+name+"Pdf", lang),
430         url+"collated-files.pdf",
431         getTrans("PDF of regtests for ", lang)+version)
432     make_ver_link(macroLang("regtest"+name+"Xml", lang),
433         url+"musicxml/collated-files.html",
434         getTrans("MusicXML Regression tests for ", lang)+version)
435     make_ver_link(macroLang("regtest"+name+"Abc", lang),
436         url+"abc2ly/collated-files.html",
437         getTrans("abc2ly Regression tests for ", lang)+version)
438     make_ver_link(macroLang("regtest"+name+"LilypondBook", lang),
439         url+"lilypond-book/collated-files.html",
440         getTrans("lilypond-book Regression tests for ", lang)+version)
441     make_ver_link(macroLang("regtest"+name+"XmlPdf", lang),
442          url+"musicxml/collated-files.pdf",
443         getTrans("PDF of MusicXML regtests for ", lang)+version)
444     make_ver_link(macroLang("regtest"+name+"AbcPdf", lang),
445          url+"abc2ly/collated-files.pdf",
446         getTrans("PDF of abc2ly regtests for ", lang)+version)
447     make_ver_link(macroLang("regtest"+name+"LilypondBookPdf", lang),
448          url+"lilypond-book/collated-files.pdf",
449         getTrans("PDF of lilypond-book regtests for ", lang)+version)
450
451 def make_doctarball_links(name, version, lang):
452     url = depth + "download/binaries/documentation/lilypond-"
453     # ugly FIXME, but proper build number support isn't Critical.
454     url += version + "-1"
455     url += ".documentation.tar.bz2"
456     make_ver_link(macroLang("doctarball"+name, lang),
457         url, getTrans("Doc tarball for ", lang)+version)
458
459 print "@c ************************ Download binaries ************"
460 make_all_downloads("Stable", VERSION_STABLE)
461 make_all_downloads("Devel", VERSION_DEVEL)
462
463 print "@c ************************ Download source ************"
464 # FIXME: icky hard-coding!  -gp
465 for lang in langs:
466     print "@c *********", lang, "***"
467     make_download_source("downloadStableSource","v2.12",VERSION_STABLE,lang)
468     make_download_source("downloadDevelSource","v2.13",VERSION_DEVEL,lang)
469
470 print "@c ************************ Manual links ************"
471 for lang in langs:
472     print "@c *********", lang, "***"
473     make_manual_links("Stable", VERSION_STABLE,lang)
474     make_manual_links("Devel", VERSION_DEVEL,lang)
475
476     make_doctarball_links("Stable", VERSION_STABLE,lang)
477     make_doctarball_links("Devel", VERSION_DEVEL,lang)
478
479 print "@c ************************ Regtest links ************"
480 for lang in langs:
481     print "@c *********", lang, "***"
482     make_regtest_links("Stable", VERSION_STABLE,lang)
483     make_regtest_links("Devel", VERSION_DEVEL,lang)
484
485