wikilog: Ensure empty wiki page is handled correctly for page init

When a wiki page is empty, or only contains a single entry, ensure
the code still works and use empty content to initialise it.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2018-09-26 13:52:06 +01:00
parent 646ff04e8c
commit 22d8500664
2 changed files with 14 additions and 7 deletions

View File

@ -136,6 +136,8 @@ class YPWiki(object):
parsed = self.parse_json(req) parsed = self.parse_json(req)
pageid = sorted(parsed['query']['pages'].keys())[-1] pageid = sorted(parsed['query']['pages'].keys())[-1]
blurb, entries = "\n", ""
if 'revisions' in parsed['query']['pages'][pageid]:
content = parsed['query']['pages'][pageid]['revisions'][0]['*'] content = parsed['query']['pages'][pageid]['revisions'][0]['*']
blurb, entries = content.split('==', 1) blurb, entries = content.split('==', 1)
# ensure we keep only a single newline after the blurb # ensure we keep only a single newline after the blurb

View File

@ -252,9 +252,14 @@ class WikiLog(service.BuildbotService):
entry_title = next(it) entry_title = next(it)
while entry_title.group(1) != title: while entry_title.group(1) != title:
entry_title = next(it) entry_title = next(it)
next_title = next(it)
head = entries[:entry_title.start()] head = entries[:entry_title.start()]
try:
next_title = next(it)
tail = entries[next_title.start():] tail = entries[next_title.start():]
except StopIteration:
# There was no following entry
tail = ""
update = head + "==[" + new_title + "]==\n" + new_entry + tail update = head + "==[" + new_title + "]==\n" + new_entry + tail
cookies = self.wiki.login() cookies = self.wiki.login()