summaryrefslogtreecommitdiff
path: root/scripts/html_base.py
blob: 9b265aec3717dc071c1541c5d8af28c0f8a98946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#! /usr/bin/env python3
#===============================
#
# html_base
#
# 2021/02/09 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
#===============================
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)