]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/website_post.py
8018f3ad6290c2979183b754f063f886fb491a7c
[lilypond.git] / scripts / build / website_post.py
1 #!@PYTHON@
2 #-*- coding: utf-8 -*-
3
4 ## This is web_post.py. This script deals with translations
5 ## in the "make website" target.
6
7 import sys
8 import os
9 import glob
10
11 lang_lookup = {
12   'fr': 'français',
13   'es': 'español',
14   '': 'english'
15 }
16
17 #indir, outdir = sys.argv[1:]
18
19 # FIXME: looks dangerous!
20 indir = sys.argv[1]
21 outdir=indir
22
23 html_files = glob.glob( os.path.join(indir, '*.html') )
24
25 # messy way to get all languages
26 langs_set = set()
27 for file in html_files:
28         file_split = file.split('.')
29         if (len(file_split) == 2):
30                 # it's English
31                 lang = ''
32         else:
33                 # it's a translation
34                 lang = file_split[1]
35         langs_set.add(lang)
36 langs = list(langs_set)
37 langs.sort()
38
39 def makeFooter(currentLang):
40         text = "<p id=\"languages\">\n"
41         text += "Other languages: "
42         for i in range(len(langs)):
43                 l = langs[i]
44                 if (l == currentLang):
45                         continue
46                 text += "<a href=\"index"
47                 if (not (l=='')):
48                         text += "." + l
49                 text += ".html\">"
50                 text += lang_lookup[l]
51                 text += "</a>"
52                 if (i < len(langs)-2):
53                         text += ", "
54                 else:
55                         text += ".\n"
56         # TODO: add link to automatic language selection?
57         # still need to include this page in the new webpages somewhere
58         text += "</p>\n"
59         return text
60
61
62 for file in html_files:
63         file_split = file.split('.')
64         # we want to strip the .html
65         out_filename = os.path.basename(file_split[0])
66         if (len(file_split) == 2):
67                 # it's English
68                 lang = ''
69         else:
70                 # it's a translation
71                 lang = file_split[1]
72         out_filename += '.'+lang
73
74 # I can't get the previous name to work
75         out_filename = os.path.basename(file)
76
77         # translation links should point to translations
78         lines = open(file).readlines()
79         # ick
80         os.remove(file)
81
82         lang_footer = makeFooter(lang)
83         
84         outfile = open( os.path.join(outdir, out_filename), 'w')
85         for line in lines:
86                 # avoid external links
87                 if ((line.find("href") >= 0) and (line.find("http")==-1)):
88 # eventually we want to do this, but I can't get it to work.
89 # waiting for help with apache (?)
90 #                       line = line.replace(".html", "."+lang)
91                         line = line.replace(".html", "."+lang+".html")
92                 if (line.find("<!-- FOOTER -->") >= 0):
93                         outfile.write( lang_footer )
94                 outfile.write(line)
95         outfile.close()
96