Skip to content

Commit

Permalink
[offline-renderer] Provide a mechanism to ignore certain templates
Browse files Browse the repository at this point in the history
Add some stub templates to the list.  These should not be shown as
this results in a message similar to "click to edit."

Signed-off-by: Christopher Hall <hsw@openmoko.com>
  • Loading branch information
hxw committed May 27, 2010
1 parent 5c975a8 commit 3781837
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
32 changes: 26 additions & 6 deletions host-tools/offline-renderer/ArticleIndex.py
Expand Up @@ -54,6 +54,7 @@ def usage(message):
print(' --language=<xx> Set language for index conversions [en]')
print(' --limit=number Limit the number of articles processed')
print(' --prefix=name Device file name portion for .fnd/.pfx [pedia]')
print(' --ignore-templates=file File of templates to ignore(no default)')
print(' --templates=file Database for templates [templates.db]')
print(' --truncate-title Set when not using language links to save space')
exit(1)
Expand All @@ -65,12 +66,13 @@ def main():


try:
opts, args = getopt.getopt(sys.argv[1:], 'hvi:o:c:t:l:p:L:T',
opts, args = getopt.getopt(sys.argv[1:], 'hvi:o:c:t:I:l:p:L:T',
['help', 'verbose',
'article-index=',
'article-offsets=',
'article-counts=',
'templates=',
'ignore-templates=',
'limit=',
'prefix=',
'language=',
Expand All @@ -86,6 +88,7 @@ def main():
fnd_name = 'pedia.fnd'
pfx_name = 'pedia.pfx'
template_name = 'templates.db'
ignore_templates_name = None
limit = 'all'
language = 'en' # some languages may require special processing
truncate_title = False # set tru when not using language links
Expand All @@ -103,6 +106,10 @@ def main():
cnt_name = arg
elif opt in ('-t', '--templates'):
template_name = arg
elif opt in ('-I', '--ignore-templates'):
ignore_templates_name = arg
if not os.path.exists(ignore_templates_name):
usage(u'ignore-templates file: {0:s} does not exist'.format(ignore_templates_name))
elif opt in ('-T', '--truncate-title'):
truncate_title = True
elif opt in ('-l', '--limit'):
Expand All @@ -126,12 +133,23 @@ def main():
if [] == args:
usage('Missing argument(s)')

ignored_templates = {}
if None != ignore_templates_name:
with open(ignore_templates_name) as f:
for l in f.readlines():
line = l.strip()
if line.startswith('#'):
continue
if '' != line:
ignored_templates[line] = True

language_convert = LanguageTranslation.LanguageNormal()
if 'ja' == language:
language_convert = LanguageTranslation.LanguageJapanese()

processor = FileProcessing(articles = art_name, offsets = off_name,
templates = template_name,
ignored_templates = ignored_templates,
language = language_convert)

for f in args:
Expand Down Expand Up @@ -214,6 +232,7 @@ def __init__(self, *args, **kw):
self.file_import = self.offset_db_name + '.files'

self.template_db_name = kw['templates']
self.ignored_templates = kw['ignored_templates']

for filename in [self.article_db_name,
self.article_import,
Expand Down Expand Up @@ -429,11 +448,12 @@ def body(self, category, key, title, text, seek):
title = self.translate(title).strip(u'\u200e\u200f')

if self.KEY_TEMPLATE == key:
t1 = unicode(category, 'utf-8').capitalize() + ':' + title
t_body = TidyUp.template(text)
self.template_cursor.execute(u'insert or replace into templates (title, body) values(?, ?)',
[u'~{0:d}~{1:s}'.format(self.file_id(), t1), u'~' + t_body])
self.template_count += 1
if title not in self.ignored_templates:
t1 = unicode(category, 'utf-8').capitalize() + ':' + title
t_body = TidyUp.template(text)
self.template_cursor.execute(u'insert or replace into templates (title, body) values(?, ?)',
[u'~{0:d}~{1:s}'.format(self.file_id(), t1), u'~' + t_body])
self.template_count += 1
return

restricted = FilterWords.is_restricted(title) or FilterWords.is_restricted(text)
Expand Down
5 changes: 4 additions & 1 deletion host-tools/offline-renderer/Makefile
Expand Up @@ -54,6 +54,8 @@ ENABLE_IMAGES ?= YES
ARTICLES_PER_BLOCK ?= 32
ARTICLE_BLOCK_SIZE ?= 262144

IGNORED_TEMPLATES ?= templates-to-ignore

WORKDIR_PATH := $(shell ${RESOLVEPATH} ${WORKDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX})
TEMPDIR_PATH := $(shell ${RESOLVEPATH} ${TEMPDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX})

Expand Down Expand Up @@ -129,12 +131,13 @@ check-html:


.PHONY: index
index: check-dirs check-xml stamp-RedirectedTo.py stamp-PinyinTable.py stamp-user.dic
index: check-dirs check-xml stamp-RedirectedTo.py stamp-PinyinTable.py stamp-user.dic ${IGNORED_TEMPLATES}
./ArticleIndex.py ${VERBOSE_ARG} \
--article-index="${ARTICLES}" \
--article-offsets="${OFFSETS}" \
--article-counts="${COUNTS_FILE}" \
--templates="${TEMPLATE_FILE}" \
--ignore-templates="${IGNORED_TEMPLATES}" \
--language="${WIKI_LANGUAGE}" \
--prefix="${DATA_PREFIX}" ${TRUNCATE_ARG} ${XML_FILES}

Expand Down
14 changes: 14 additions & 0 deletions host-tools/offline-renderer/templates-to-ignore
@@ -0,0 +1,14 @@
# a list of templates that need to be suppressed
# listed one per line
# Note: blank lines and lines starting '#' are ignored

節stub
بذرة مقطع
Секция мъниче
Sectstub
Tynkä/Osa
Seksjonstubb
Sekcja stub
Sect-ciot
Phần sơ khai
Stubavsnitt

0 comments on commit 3781837

Please sign in to comment.