- file_split = file.split('.')
- # we want to strip the .html
- out_filename = os.path.basename(file_split[0])
- if (len(file_split) == 2):
- # it's English
- lang = ''
- # possibly necessary for automatic language selection
- file_symlink =file.replace(".html", ".en.html")
- if (not (os.path.exists(file_symlink))):
- os.symlink (file, file_symlink)
- else:
- # it's a translation
- lang = file_split[1]
- # it's a symlink
- if (lang == "en"):
- continue
- out_filename += '.'+lang
-
-# I can't get the previous name to work
- out_filename = os.path.basename(file)
-
- # translation links should point to translations
- lines = open(file).readlines()
- # ick
- os.remove(file)
-
- # ick
- lang_footer = makeFooter(lang, out_filename.split('.')[0])
-
- outfile = open( out_filename, 'w')
- for line in lines:
- # avoid external links
- if ((line.find("href") >= 0) and (line.find("http")==-1)):
-# eventually we want to do this, but I can't get it to work.
-# waiting for help with apache (?)
-# line = line.replace(".html", "."+lang)
- text = ""
- if (not (lang=="")):
- text += "." + lang
- text += ".html"
- line = line.replace(".html", text)
- if ((line.find("href") >= 0) and
- (line.find("http")==-1) and
- (line.find("pdf") >= 0)):
- text = ""
- if (not (lang=="")):
- text += "." + lang
- text += ".pdf"
- line = line.replace(".pdf", text)
-
-
- if (line.find("<!-- FOOTER -->") >= 0):
- outfile.write( lang_footer )
- outfile.write(line)
- outfile.close()
-
+ ### we want to strip the .html and get the lang
+ file_split = file.split('.')
+ file_base = os.path.basename( file_split[0] )
+ if (len(file_split) == 2):
+ # it's English
+ lang = ''
+ # possibly necessary for automatic language selection
+ file_symlink = file.replace(".html", ".en.html")
+ if not os.path.lexists (file_symlink):
+ os.symlink (file, file_symlink)
+ elif (len(file_split) == 3):
+ # it's a translation
+ lang = file_split[1]
+ if (lang == "en"):
+ # it's a symlink
+ continue
+ else:
+ # it's a mess
+ print "is a mess"
+ continue
+
+ ### we need to replace parts of the file
+ lines = open(file).readlines()
+ os.remove(file)
+ outfile = open(file, 'w')
+
+ lang_footer = makeFooter (file_base, lang)
+
+ ### alter file
+ for line in lines:
+ ### alter links as appropriate
+ link = getLocalHref(line)
+ if (link != ""):
+ # questionable
+ if (not link.startswith("../doc/")):
+ if (link.endswith(".html")):
+ langlink = addLangExt(link[:-5], lang, "html")
+ line = line.replace(link, langlink)
+ if (link.endswith(".pdf")):
+ langlink = addLangExt(link[:-4], lang, "pdf")
+ line = line.replace(link, langlink)
+ ### add google tracker header
+ if (line.find("</head>") >= 0):
+ outfile.write("""<!-- Google tracking !-->
+<script src="http://www.google-analytics.com/urchin.js"
+type="text/javascript">
+</script>
+<script type="text/javascript">
+_uacct = "UA-68969-1";
+urchinTracker();
+</script>
+""");
+ #### add google tracker goals
+ if (line.find("href=\"http://download.linuxaudio.org") >= 0):
+ # TODO: more ugly hardcoding to make releases hard. :(
+ if (line.find('2.16') >= 0):
+ line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.16\');\" href=')
+ elif (line.find('2.17') >= 0):
+ line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.17\');\" href=')
+ ### add language selection footer
+ if (line.find("<div id=\"verifier_texinfo\">") >= 0):
+ outfile.write("<div id=\"footer\">\n")
+ outfile.write( lang_footer )
+ if (line.find("</body") >= 0):
+ outfile.write("</div>\n")
+ outfile.write(line)
+ outfile.close()