[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
www/server/source/sitemap-generator sitemap-gen...
From: |
Pavel Kharitonov |
Subject: |
www/server/source/sitemap-generator sitemap-gen... |
Date: |
Fri, 01 Feb 2013 14:47:49 +0000 |
CVSROOT: /web/www
Module name: www
Changes by: Pavel Kharitonov <ineiev> 13/02/01 14:47:49
Modified files:
server/source/sitemap-generator: sitemap-generator.py
Log message:
Collect all available translations when titles of different
files coincide RT #798493.
Use TOP_DIRECTORY relative to sitemap-generator.py location
by default (RT #797547), and command line argument when
provided.
Add a note about being automatically generated to the sitemap.
Compile data first, and write them to the files as the last step.
CVSWeb URLs:
http://web.cvs.savannah.gnu.org/viewcvs/www/server/source/sitemap-generator/sitemap-generator.py?cvsroot=www&r1=1.5&r2=1.6
Patches:
Index: sitemap-generator.py
===================================================================
RCS file: /web/www/www/server/source/sitemap-generator/sitemap-generator.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- sitemap-generator.py 29 Jan 2013 09:17:56 -0000 1.5
+++ sitemap-generator.py 1 Feb 2013 14:47:48 -0000 1.6
@@ -39,7 +39,7 @@
OUTPUT_FILE_NAME = 'sitemap.html'
# The expression for names of localized sitemap versions.
SITEMAP_REGEXP = 'sitemap\.' + LANGCODE_REGEXP + '\.html'
-TOP_DIRECTORY = '/home/g/gnun/checkouts/www'
+TOP_DIRECTORY = ''
SITEMAP_DIR = 'server'
TRANSLATION_REGEXP = '\.(?P<langcode>[a-z]{2}|[a-z]{2}-[a-z]{2})' \
+ FILENAMES_TO_LIST_REGEXP
@@ -60,10 +60,10 @@
print_always = None
excluded_dirs = None
excluded_files = None
-output_file = None
+output_text = ''
title_tails = None
replacement_titles = None
-msgids = []
+translations = {}
def is_directory_empty(path):
directory_contents = get_directory_contents(path)
@@ -306,21 +306,37 @@
ret = re.sub('\n', ' \\\\' + 'n' + '"\n"', ret)
return ret
-def append_sitemap_pos(msgid, msgstr = None):
- # Avoid duplicate msgids.
- if msgid in msgids:
- return
+def po_entry(msgid, msgstr):
+ return '\nmsgid "' + escape_po_string(msgid) + '"\n' \
+ + 'msgstr "' + escape_po_string(msgstr) + '"\n'
+
+def output_translations(prefix):
for lang in sitemap_linguas:
- fd = open(OUTPUT_FILE_NAME + '.' + lang + '.po', 'a')
- if msgstr == None or lang in msgstr:
- string = '\nmsgid "' + escape_po_string(msgid) \
- + '"\n' + 'msgstr "' \
- + escape_po_string(msgstr[lang] \
- if msgstr else msgid)\
- + '"\n'
+ fd = open(prefix + '.' + lang + '.po', 'a')
+ for msgid in translations:
+ string = ''
+ trans = translations[msgid]
+ if trans == None:
+ string = po_entry(msgid, msgid)
+ elif lang in trans:
+ string = po_entry(msgid, trans[lang])
+ if string != '':
fd.write(string.encode('utf-8'))
fd.close()
- msgids.append(msgid)
+
+def append_sitemap_pos(msgid, msgstr = None):
+ trans = {}
+ if msgstr == None:
+ translations[msgid] = None
+ return
+ if msgid in translations:
+ if translations[msgid] == None:
+ return
+ trans = translations[msgid]
+ for lang in sitemap_linguas:
+ if lang in msgstr:
+ trans[lang] = msgstr[lang]
+ translations[msgid] = trans
def append_title_to_pos(filename, title, titles):
msgstr = {}
@@ -354,7 +370,6 @@
append_sitemap_pos('</span>')
append_sitemap_pos('<span>')
append_sitemap_pos('</a>')
- append_sitemap_pos('Copyright © 2013 Free Software Foundation,
Inc.')
append_sitemap_pos('span.topmost-title, #content a.topmost-title '\
+ '{ font-size: 1.3em; font-weight: bold } ' \
+ '#content dt a { font-weight: normal } ' \
@@ -480,9 +495,17 @@
return None
def write(message):
- output_file.write(message.encode('utf-8'))
+ global output_text
+ output_text = output_text + message
-output_file = open(OUTPUT_FILE_NAME, 'w')
+if len(sys.argv) > 1:
+ TOP_DIRECTORY = sys.argv[1]
+else:
+ prog_dir = sys.argv[0]
+ pos = prog_dir.rfind('/')
+ prog_dir = prog_dir[ : pos] if (pos != -1) else './'
+ # This script's place is /server/source/sitemap-generator/
+ TOP_DIRECTORY = os.path.abspath(os.path.join(prog_dir, '../../..'))
no_index_checks = \
read_file('directories_ignored_in_double_index_file_checks').splitlines()
@@ -497,7 +520,29 @@
init_sitemap_pos()
write(read_file('output.head'))
+write('''
+
+
+
+<!--
+
+ This file is automatically generated by ''' + sys.argv[0] + '''.
+
+ The generator is also in charge of partially updating
+ the existing translations of this file. This is why you
+ should neither edit this file manually, nor commit it alone
+ without merging the updates to the translations.
+
+ -->
+
+
+
+''')
print_map('', 0)
write(read_file('output.tail'))
+output_file = open(OUTPUT_FILE_NAME, 'w')
+output_file.write(output_text.encode('utf-8'))
output_file.close()
+
+output_translations(OUTPUT_FILE_NAME)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- www/server/source/sitemap-generator sitemap-gen...,
Pavel Kharitonov <=