wikilog: Allow footer of archived logs

Preseve a footer 'Archived Logs' section at the end of the BuildLog wiki
page. This will be later used for archiving purposes.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2020-10-21 14:21:45 +01:00
parent 31f297e026
commit 6a4cebdfee
2 changed files with 14 additions and 9 deletions

View File

@ -136,15 +136,20 @@ class YPWiki(object):
parsed = self.parse_json(req)
pageid = sorted(parsed['query']['pages'].keys())[-1]
blurb, entries = "\n", ""
blurb, entries, footer = "\n", "", "\n==Archived Logs=="
if 'revisions' in parsed['query']['pages'][pageid]:
content = parsed['query']['pages'][pageid]['revisions'][0]['*']
blurb, entries = content.split('==', 1)
# ensure we keep only a single newline after the blurb
blurb = blurb.strip() + "\n"
entries = '=='+entries
entries = '==' + entries
try:
entries, footer = entries.rsplit('\n==Archived Logs==', 1)
footer = '\n==Archived Logs==' + footer
except ValueError:
pass
return blurb, entries
return blurb, entries, footer
def post_entry(self, wiki_page, content, summary, cookies):
"""

View File

@ -159,19 +159,19 @@ class WikiLog(service.BuildbotService):
content = content + '* ' + forcedby + '\n* ' + reason + '\n'
new_entry = '{}\n{}\n'.format(section_title, content)
blurb, entries = self.wiki.get_content(self.wiki_page)
blurb, entries, footer = self.wiki.get_content(self.wiki_page)
if not blurb:
log.err("wkl: Unexpected content retrieved from wiki!")
return False
entries = new_entry + entries
content = blurb + new_entry + entries + footer
cookies = self.wiki.login()
if not cookies:
log.err("wkl: Failed to login to wiki")
return False
post = self.wiki.post_entry(self.wiki_page, blurb+entries, summary, cookies)
post = self.wiki.post_entry(self.wiki_page, content, summary, cookies)
if not post:
log.err("wkl: Failed to post entry for %s" % buildid)
return False
@ -248,7 +248,7 @@ class WikiLog(service.BuildbotService):
log.err("wkl: Starting to update entry for %s(%s)" % (buildid, parent['buildid']))
blurb, entries = self.wiki.get_content(self.wiki_page)
blurb, entries, footer = self.wiki.get_content(self.wiki_page)
if not blurb:
log.err("wkl: Unexpected content retrieved from wiki!")
return False
@ -310,14 +310,14 @@ class WikiLog(service.BuildbotService):
# There was no following entry
tail = ""
update = head + "==[" + new_title + "]==\n" + new_entry + tail
update = blurb + head + "==[" + new_title + "]==\n" + new_entry + tail + footer
cookies = self.wiki.login()
if not cookies:
log.err("wkl: Failed to login to wiki")
return False
post = self.wiki.post_entry(self.wiki_page, blurb+update, summary, cookies)
post = self.wiki.post_entry(self.wiki_page, update, summary, cookies)
if not post:
log.err("wkl: Failed to update entry for %s(%s)" % (buildid, parent['buildid']))
return False