forked from amazingfate/help
wikihelp: Improve the generation of conditionals (switch/switchinline).
This commit is contained in:
@ -28,11 +28,11 @@ footer_template = "\
|
||||
|
||||
def create_wiki_dirs():
|
||||
dirs = [
|
||||
"All",
|
||||
"Basic",
|
||||
"Calc",
|
||||
"Chart",
|
||||
"Draw",
|
||||
"All",
|
||||
"Impress",
|
||||
"Math",
|
||||
"Writer"
|
||||
@ -77,3 +77,5 @@ os.system( "python to-wiki/wikiconv2.py "+localization )
|
||||
|
||||
# close the bookmarks.h template
|
||||
create_wiki_footer()
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||
|
||||
@ -51,15 +51,15 @@ modules_list = [
|
||||
["scalc","Calc"],
|
||||
["schart","Chart"],
|
||||
["sdraw","Draw"],
|
||||
["shared","All"],
|
||||
["simpress","Impress"],
|
||||
["smath","Math"],
|
||||
["swriter","Writer"]
|
||||
["swriter","Writer"],
|
||||
["shared","All"]
|
||||
]
|
||||
|
||||
def get_module(text):
|
||||
for i in modules_list:
|
||||
if text.find(i[0]) >=0:
|
||||
if text.find('/' + i[0] + '/') >=0:
|
||||
return i[1]
|
||||
return ""
|
||||
|
||||
@ -98,6 +98,10 @@ class TitleParser:
|
||||
return self.title.strip()
|
||||
|
||||
def parsexhp(filename):
|
||||
module = get_module(filename)
|
||||
if module == '':
|
||||
return
|
||||
|
||||
parsing = True
|
||||
file=open(filename,"r")
|
||||
p = xml.parsers.expat.ParserCreate()
|
||||
@ -114,19 +118,20 @@ def parsexhp(filename):
|
||||
return
|
||||
file.close()
|
||||
title = tp.get_title()
|
||||
if len(title):
|
||||
if len(title) > 0:
|
||||
readable_title = readable_text(title)
|
||||
title = get_module(filename) + "/" + wiki_text(title)
|
||||
title = title.replace(" ", "_")
|
||||
title = title.replace("___", "_")
|
||||
title = title.replace("__", "_")
|
||||
title = module + '/' + wiki_text(title)
|
||||
title = title.replace(' ', '_')
|
||||
title = title.replace('___', '_')
|
||||
title = title.replace('__', '_')
|
||||
title = title.strip('_')
|
||||
title = make_unique(title)
|
||||
alltitles.append(title)
|
||||
print filename + ";" + title + ";" + readable_title
|
||||
print filename + ';' + title + ';' + readable_title
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print "getalltitles.py <directory>"
|
||||
print "e.g. getalltitles.py helcontent2/source/text/scalc"
|
||||
print "e.g. getalltitles.py source/text/scalc"
|
||||
sys.exit(1)
|
||||
|
||||
pattern = "xhp"
|
||||
|
||||
@ -7,7 +7,7 @@ import codecs
|
||||
from threading import Thread
|
||||
|
||||
root="source/"
|
||||
max_threads = 4
|
||||
max_threads = 25
|
||||
|
||||
titles = [[]]
|
||||
|
||||
@ -339,7 +339,7 @@ class XhpFile(ElementBase):
|
||||
elif name == 'sort':
|
||||
self.parse_child(Sort(attrs, self))
|
||||
elif name == 'switch':
|
||||
self.parse_child(Switch(attrs, self))
|
||||
self.parse_child(Switch(attrs, self, parser.embedding_app))
|
||||
elif name == 'table':
|
||||
self.parse_child(Table(attrs, self))
|
||||
else:
|
||||
@ -653,7 +653,7 @@ class Section(ElementBase):
|
||||
# sections can be nested
|
||||
self.parse_child(Section(attrs, self, self.depth))
|
||||
elif name == 'switch':
|
||||
self.parse_child(Switch(attrs, self))
|
||||
self.parse_child(Switch(attrs, self, parser.embedding_app))
|
||||
elif name == 'table':
|
||||
self.parse_child(Table(attrs, self))
|
||||
else:
|
||||
@ -738,13 +738,12 @@ class Link(ElementBase):
|
||||
return text
|
||||
|
||||
class SwitchInline(ElementBase):
|
||||
def __init__(self, attrs, parent):
|
||||
def __init__(self, attrs, parent, app):
|
||||
ElementBase.__init__(self, 'switchinline', parent)
|
||||
self.switch = attrs['select']
|
||||
self.embedding_app = ''
|
||||
self.embedding_app = app
|
||||
|
||||
def start_element(self, parser, name, attrs):
|
||||
self.embedding_app = parser.embedding_app
|
||||
if name == 'caseinline':
|
||||
self.parse_child(CaseInline(attrs, self, False))
|
||||
elif name == 'defaultinline':
|
||||
@ -782,22 +781,31 @@ class SwitchInline(ElementBase):
|
||||
# 'shared' into an 'app'
|
||||
if self.embedding_app == '':
|
||||
text = ''
|
||||
default = ''
|
||||
for i in self.objects:
|
||||
appls = {'CALC':'Calc', 'CHART':'Chart', 'DRAW':'Draw', \
|
||||
'IMPRESS': 'Impress', 'MATH':'Math', \
|
||||
'WRITER':'Writer', 'default':''}
|
||||
appls = {'BASIC':'Basic', 'CALC':'Calc', \
|
||||
'CHART':'Chart', 'DRAW':'Draw', \
|
||||
'IMAGE':'Draw', 'IMPRESS': 'Impress', \
|
||||
'MATH':'Math', 'WRITER':'Writer', \
|
||||
'OFFICE':'', 'default':''}
|
||||
try:
|
||||
app = appls[i.case]
|
||||
all = i.get_all()
|
||||
if all == '':
|
||||
pass
|
||||
elif app == '':
|
||||
text = text + all
|
||||
default = all
|
||||
else:
|
||||
text = text + '{{OnlyIn%s|%s}}'% (app, all)
|
||||
text = text + '{{WhenIn%s|%s}}'% (app, all)
|
||||
except:
|
||||
sys.stderr.write('Unhandled "%s" case in "appl" switchinline.\n'% \
|
||||
i.case)
|
||||
|
||||
if text == '':
|
||||
text = default
|
||||
elif default != '':
|
||||
text = text + '{{WhenDefault|%s}}'% default
|
||||
|
||||
return text
|
||||
else:
|
||||
for i in self.objects:
|
||||
@ -839,8 +847,8 @@ class Case(ElementBase):
|
||||
self.unhandled_element(parser, name)
|
||||
|
||||
class Switch(SwitchInline):
|
||||
def __init__(self, attrs, parent):
|
||||
SwitchInline.__init__(self, attrs, parent)
|
||||
def __init__(self, attrs, parent, app):
|
||||
SwitchInline.__init__(self, attrs, parent, app)
|
||||
self.name = 'switch'
|
||||
|
||||
def start_element(self, parser, name, attrs):
|
||||
@ -931,7 +939,7 @@ class Paragraph(ElementBase):
|
||||
elif name == 'link':
|
||||
self.parse_child(Link(attrs, self))
|
||||
elif name == 'switchinline':
|
||||
self.parse_child(SwitchInline(attrs, self))
|
||||
self.parse_child(SwitchInline(attrs, self, parser.embedding_app))
|
||||
elif name == 'variable':
|
||||
self.parse_child(Variable(attrs, self, self.depth))
|
||||
else:
|
||||
@ -1037,18 +1045,23 @@ class XhpParser:
|
||||
self.head_obj = XhpFile()
|
||||
self.filename = filename
|
||||
self.follow_embed = follow_embed
|
||||
self.embedding_app = embedding_app
|
||||
self.help_file_name = help_file_name
|
||||
self.bookmarks = []
|
||||
|
||||
self.current_app = ''
|
||||
for i in [['scalc', 'CALC'], ['sdraw', 'DRAW'], \
|
||||
['schart', 'CHART'], ['simpress', 'IMPRESS'], \
|
||||
for i in [['sbasic', 'BASIC'], ['scalc', 'CALC'], \
|
||||
['sdraw', 'DRAW'], ['schart', 'CHART'], \
|
||||
['simpress', 'IMPRESS'], \
|
||||
['smath', 'MATH'], ['swriter', 'WRITER']]:
|
||||
if filename.find('/%s/'% i[0]) >= 0:
|
||||
self.current_app = i[1]
|
||||
break
|
||||
|
||||
if embedding_app != '':
|
||||
self.embedding_app = embedding_app
|
||||
else:
|
||||
self.embedding_app = self.current_app
|
||||
|
||||
file = codecs.open(filename, "r", "utf-8")
|
||||
p = xml.parsers.expat.ParserCreate()
|
||||
|
||||
@ -1121,7 +1134,7 @@ if len(sys.argv) > 1:
|
||||
|
||||
for title in titles:
|
||||
while threading.active_count() > max_threads:
|
||||
time.sleep(0.1)
|
||||
time.sleep(0.001)
|
||||
|
||||
outfile = ""
|
||||
infile = ""
|
||||
|
||||
Reference in New Issue
Block a user