#! /usr/bin/env python3 #=============================== # # html_base # # 2021/02/09 Kuninori Morimoto #=============================== import os import base import view #==================================== # # html # #==================================== class html(base.base): __head = 0 __noclose = ["input", "frame", "link", "br", ] #-------------------- # option #-------------------- def option(self, dic): if (dic): self.dic.update(dic) #-------------------- # __init__ #-------------------- def __init__(self, mark, dic = None): super().__init__() self.dic = {} self.mark = mark self.option(dic) self.txt = "" #-------------------- # open #-------------------- def open(self, ret = 0): self.txt = "" if (ret): for i in range(html.__head): self.txt += "\t" self.txt += "<{}".format(self.mark) for d in self.dic: self.txt += " {}=\"{}\"".format(d, self.dic[d]) self.txt += ">" html.__head += 1 #-------------------- # close #-------------------- def close(self, ret = 0): html.__head -= 1 # no end-mark if (self.mark in html.__noclose): return if (ret): for i in range(html.__head): self.txt += "\t" self.txt += "".format(self.mark) #-------------------- # text #-------------------- def text(self, txt = ""): self.open() self.txt += txt self.close() return self.txt #-------------------- # print #-------------------- def print(self, txt = ""): self.open(1) self.txt += txt self.close(0) print(self.txt) #-------------------- # for with #-------------------- def __enter__(self): self.open(1) print(self.txt) self.txt = "" return self def __exit__(self, exception_type, exception_value, traceback): self.close(1) print(self.txt) self.txt = "" #==================================== # # myhtml # #==================================== class myhtml(base.base): def __init__(self): super().__init__() self.git = self.config("git-linux") def relpath(self, path, frm): return os.path.relpath("{}/{}".format(self.top(), path), frm) def relpath_y2h(self, file, frm): return os.path.relpath(file.replace("yaml", "html").replace("projects", "html"), frm) def git_title(self, id): title, ret = self.run2("git -C {} log -1 {} --format=%s".format(self.git, id)) if (ret != 0): title = "commit {}".format(id) return title def commit_url(self, id, type): if (type == "bsp"): return "https://github.com/renesas-rcar/linux-bsp/commit/{}?diff=unified".format(id) if (type == "torvalds"): return "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id={}".format(id) if (type == "next"): return "https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id={}".format(id) if (type == "lore"): return "https://lore.kernel.org/r/{}".format(id) return id; #-------------------- # print_css #-------------------- def print_css(self, dir): html("link", {"rel":"stylesheet", "type":"text/css", "href":self.relpath("scripts/css", dir)}).print() #-------------------- # print_commit_bsp #-------------------- def print_commit_bsp(self, bsp_list): with html("ul"): for bsp in bsp_list: html("li").print(html("a", {"href":self.commit_url(bsp, "bsp"), "target":"_blank"}).text(self.git_title(bsp))) return len(bsp_list) #-------------------- # __task_commit_upstream #-------------------- def __task_commit_upstream(self, v, upstream, item): if (not item in upstream): return 0 commit = upstream[item] with html("tr"): html("th").print(item) html("td").print(html("a", {"href":self.commit_url(commit, item), "target":"_blank"}).text(self.git_title(commit))) return 1 #-------------------- # __task_commit_posted #-------------------- def __task_commit_posted(self, v, posted, item): if (not item in posted): return 0 msgid = posted[item] with html("tr"): html("th").print(item) html("td").print(html("a", {"href":self.commit_url(msgid, item), "target":"_blank"}).text(msgid)) return 1 #-------------------- # task_commit_upstream #-------------------- def task_commit_upstream(self, v): done = 0 cnt = 0 status = v.get_data("status") if (status == "Done" or status == "Abandoned"): done = 1 upstream = v.get_data("upstream") if (not len(upstream)): if (done): html("p").print("ignored") cnt = 1 else: with html("table"): for up in upstream: cnt += self.__task_commit_upstream(v, up, "torvalds") for up in upstream: cnt += self.__task_commit_upstream(v, up, "next") for up in upstream: cnt += self.__task_commit_posted(v, up, "lore") return (done, cnt) #-------------------- # summary #-------------------- def __summary(self, status, dir, files): if (not len(files)): return html("h3").print(html("a", {"target":"summary", "href":self.relpath("html/{}.html?summary".format(status), dir)}).text(status)) with html("table", {"border":"1"}): with html("tr"): html("th").print("file") html("th").print("team") html("th").print("assignee") html("th").print("title") files.sort() for file in files: v = view.viewer([file]) v.set_data(file) subbody = html("a", {"target":"subbody"}) summary = html("a", {"target":"summary"}) with html("tr"): subbody.option({"href":self.relpath_y2h(file, dir)}) html("td").print(subbody.text(os.path.basename(file).replace(".yaml", ""))) team = v.get_data("team") summary.option({"href":self.relpath("html/{}.html".format(team), dir)}) html("td").print(summary.text(team)) assignee = v.get_data("assignee") if (not len(assignee)): assignee = "NoAssignee" summary.option({"href":self.relpath("html/{}.html".format(assignee), dir)}) html("td").print(summary.text(assignee)) html("td").print(v.get_data("title")) #-------------------- # summary #-------------------- def summary(self, title, dir, files): # ------- # summary # ------- # # ------- if (title): html("h2").print(title) new = [] active = [] blocked = [] paused = [] done = [] abandoned = [] for file in files: v = view.viewer([file]) v.set_data(file) status = v.get_data("status") if (status == "New"): new.append(file) elif (status == "Active"): active.append(file) elif (status == "Blocked"): blocked.append(file) elif (status == "Paused"): paused.append(file) elif (status == "Done"): done.append(file) else: abandoned.append(file) self.__summary("New", dir, new) self.__summary("Active", dir, active) self.__summary("Blocked", dir, blocked) self.__summary("Paused", dir, paused) self.__summary("Done", dir, done) self.__summary("Abandoned", dir, abandoned)