#! /usr/bin/env python3 #=============================== # # html_base # # 2021/02/09 Kuninori Morimoto #=============================== import os import base #==================================== # # 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): return self.run("git -C {} log -1 {} --format=%s".format(self.git, id)) 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)