summaryrefslogtreecommitdiff
path: root/scripts/html_task.py
blob: 4aa2d291ec9ce47ff35412aa074b3b82ef06bcf3 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#! /usr/bin/env python3
#===============================
#
# html_task
#
# 2021/02/09 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
#===============================
import sys
import os
import re

import view
import html_base
from html_base import html
#====================================
#
# periject_html
#
#====================================
class periject_html(html_base.myhtml):

    re_http_url = re.compile(r'(https?://[\w/:%#\$&\?\(\)~\.=\+\-]+)')
    re_blank_line = re.compile(r'\n\n+')

    def __init__(self):
        super().__init__()

    def _link(self, text):
        match = periject_html.re_http_url.search(text)
        if not match:
            return text

        a = html("a", {"href": match.group(), "target": "_blank"})
        return match.string[:match.start()] + \
               a.text(match.group()) + \
               match.string[match.end():]

    #--------------------
    # task_commit_bsp
    #--------------------
    def task_commit_bsp(self, v):
        cnt = 0
        with html("table"):
            for b in self.bsp_list():
                bsp_list = v.get_data(b)
                if (not bsp_list):
                    continue
                with html("tr"):
                    html("th").print(b)
                    with html("td"):
                        cnt += self.print_commit_bsp(bsp_list)
        return cnt

    #--------------------
    # task_status
    #--------------------
    def task_status(self, v):
        dir		= os.path.dirname(v.file)
        assignee	= v.get_data("assignee")
        status		= v.get_data("status")
        team		= v.get_data("team")

        if (not len(assignee)):
            assignee = "NoAssignee"

        with html("table", {"border":"1"}):
            with html("tr"):
                html("th").print("file")
                html("th").print("status")
                html("th").print("team")
                html("th").print("assignee")
                html("th").print("key")

            with html("tr"):
                html("td").print(os.path.relpath(v.file, self.top()))
                html("td").print(html("a", {"target":"summary",
                                            "href":self.relpath("html/{}.html?summary".format(status), dir)}).text(status))
                html("td").print(html("a", {"target":"summary",
                                            "href":self.relpath("html/{}.html?summary".format(team), dir)}).text(team))
                html("td").print(html("a", {"target":"summary",
                                            "href":self.relpath("html/{}.html?summary".format(assignee), dir)}).text(assignee))
                html("td").print(v.get_data("key"))

    #--------------------
    # _task_relation
    #--------------------
    def _task_relation(self, relationship, v, item):

        current_dir = os.path.dirname(v.file)
        related_file = v.get_related_file(relationship[item])

        if (not os.path.exists(related_file)):
            with html("tr"):
                html("td").print(item)
                html("td").print("Unknown({})".format(related_file))
            return

        rv = view.viewer([related_file])
        rv.set_data(related_file)
        with html("tr"):
            html("td").print(item)
            html("td").print(html("a", {"href":
                                        self.relpath_y2h(related_file, current_dir)}).text(rv.get_data("title")))

    #--------------------
    # task_relation
    #--------------------
    def task_relation(self, v):

        relationships = v.get_data("relationships")
        if (not relationships):
            return

        current_dir = os.path.dirname(v.file)

        with html("table", {"border":"1"}):
            for relationship in relationships:
                if ("parent" in relationship):
                    self._task_relation(relationship, v, "parent")
                if ("depends" in relationship):
                    self._task_relation(relationship, v, "depends")
                if ("blocks" in relationship):
                    self._task_relation(relationship, v, "blocks")

    #--------------------
    # task_head
    #--------------------
    def task_head(self, v):

        with html("table"):
            with html("tr"):
                with html("td"):
                    self.task_status(v)
                with html("td"):
                    self.task_relation(v)

    #--------------------
    # task_commit
    #--------------------
    def task_commit(self, v):

        has_bsp = 0
        for b in self.bsp_list():
            if (v.get_data(b)):
                has_bsp = 1
                break
        upstream = v.get_data("upstream")

        with html("table", {"border":"1"}):
            with html("tr"):
                if (has_bsp):
                    html("th").print("BSP")
                if (upstream):
                    html("th").print("upstream")
            with html("tr"):
                if (has_bsp):
                    with html("td"):
                        self.task_commit_bsp(v)
                if (upstream):
                    with html("td"):
                        self.task_commit_upstream(v)

    #--------------------
    # _task_comments
    #--------------------
    def _task_comments(self, v):

        if isinstance(v, list):
            with html("ul"):
                for comment in v:
                    with html("li"):
                        self._task_comments(comment)

        elif isinstance(v, dict):
            for key, value in v.items():
                html("p").print(self._link(key))
                with html("p"):
                    self._task_comments(value)

        elif isinstance(v, str):
            comment = self._link(v)

            comment = periject_html.re_blank_line.split(comment)
            for para in comment:
                html("p").print(para)

        else:
            print(v)
            raise TypeError(f"Incorrect type for comments ({type(v)})")

    #--------------------
    # task_comments
    #--------------------
    def task_comments(self, v):
        comments = v.get_data("comments")
        if (not comments):
            return

        self._task_comments(comments)

    #--------------------
    # print
    #--------------------
    def print(self, argv):
        # remove this script
        argv.pop(0)

        v = view.viewer([argv[0]])
        v.set_data(argv[0])

        dir = os.path.dirname(argv[0].replace("projects", "html"))

        self.print_css(dir)
        with html("body"):
            html("h2").print(v.get_data("title"))
            self.task_head(v)
            self.task_commit(v)
            self.task_comments(v)

#====================================
#
# As command
#
#====================================
if __name__=='__main__':
    # html_task.py projects/xxx/xxx.yaml
    periject_html().print(sys.argv)