Changeset 8b96e17 in rtems-source-builder
- Timestamp:
- 08/06/17 23:59:49 (6 years ago)
- Branches:
- 5, master
- Children:
- 2064f90
- Parents:
- 295c197
- Files:
-
- 33 added
- 307 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
README
r295c197 r8b96e17 12 12 welcome this happening in other open source or commercial projects. 13 13 14 The project is part of the RTEMS Project. See http://www.rtems.org/ for 15 details. The master repositiory is 16 http://git.rtems.org/rtems-source-builder.git/. 14 The project is part of the RTEMS Project. The project's websites are: 17 15 18 Documentation is in the 'doc' directory and available as HTML at https://docs.rtems.org/rsb/. 16 RTEMS Project Website: 17 https://www.rtems.org/ 18 19 GIT Source Repository: 20 https://git.rtems.org/rtems-source-builder.git/ 21 22 Documentation: 23 https://docs.rtems.org/branches/master/rsb/index.html 24 25 Bugs: 26 https://devel.rtems.org/query?component=RSB 27 28 Please refer to the LICENSE file for license details. 19 29 20 30 Contributions, suggestions, and bug reports are welcome. -
source-builder/sb/reports.py
r295c197 r8b96e17 25 25 from __future__ import print_function 26 26 27 import base64 27 28 import copy 28 29 import datetime … … 140 141 return self.content 141 142 142 class asciidoc_formatter(formatter):143 class markdown_formatter(formatter): 143 144 def __init__(self): 144 super(asciidoc_formatter, self).__init__() 145 super(markdown_formatter, self).__init__() 146 self.level_current = 1 147 self.level_path = '0.' 148 self.levels = { '0.': 0 } 149 self.cols = [20, 55] 150 151 def _heading(self, heading, level): 152 return '%s %s' % ('#' * level, heading) 153 154 def _strong(self, s): 155 return '__' + s + '__' 156 157 def _bold(self, s): 158 return '__' + s + '__' 159 160 def _italic(self, s): 161 return '_' + s + '_' 162 163 def _table_line(self): 164 l = '|' 165 for c in self.cols: 166 l += '-' * c + '|' 167 return l 168 169 def _table_row(self, cols): 170 if len(cols) != len(self.cols): 171 raise error.general('invalid table column count') 172 l = '|' 173 for c in range(0, len(cols)): 174 l += '%-*s|' % (self.cols[c], cols[c]) 175 return l 176 177 def _btext(self, level, text): 178 return '> ' * (level - 1) + text 179 180 def _bline(self, level, text): 181 self.line(self._btext(level, text)) 182 183 def _level(self, nest_level): 184 if nest_level > self.level_current: 185 self.level_path += '%d.' % (self.levels[self.level_path]) 186 if nest_level < self.level_current: 187 self.level_path = self.level_path[:-2] 188 if self.level_path not in self.levels: 189 self.levels[self.level_path] = 0 190 self.level_current = nest_level 191 self.levels[self.level_path] += 1 192 return '%s%d.' % (self.level_path[2:], self.levels[self.level_path]) 145 193 146 194 def format(self): 147 return ' asciidoc'195 return 'markdown' 148 196 149 197 def ext(self): 150 return '. txt'198 return '.md' 151 199 152 200 def introduction(self, name, now, intro_text): 153 h = 'RTEMS Source Builder Report' 154 self.line(h) 155 self.line('=' * len(h)) 156 self.line(':doctype: book') 157 self.line(':toc2:') 158 self.line(':toclevels: 5') 159 self.line(':icons:') 160 self.line(':numbered:') 161 self.line(':data-uri:') 162 self.line('') 163 self.line(_title) 164 self.line(now) 165 self.line('') 166 image = _make_path(self.sbpath, options.basepath, 'images', 'rtemswhitebg.jpg') 167 self.line('image:%s["RTEMS",width="20%%"]' % (image)) 201 self.line('- - -') 202 self.line(self._heading('RTEMS Source Builder Report', 1)) 203 self.line(self._strong(_title)) 204 self.line('') 205 self.line(self._bold('Generated: ' + now)) 168 206 self.line('') 169 207 if intro_text: 170 208 self.line('%s' % ('\n'.join(intro_text))) 209 self.line('') 210 self.line('') 211 self.line('- - -') 212 self.line(self._heading('Table Of Contents', 2)) 213 self.line('') 214 self.line('[TOC]') 215 self.line('') 171 216 172 217 def release_status(self, release_string): 173 218 self.line('') 174 self.line("'''") 175 self.line('') 176 self.line('.%s' % (_release_status_text)) 219 self.line(self._heading(_release_status_text, 2)) 220 self.line('') 177 221 self.line('*Version*: %s;;' % (release_string)) 178 222 self.line('') 179 self.line("'''")180 self.line('')181 223 182 224 def git_status(self, valid, dirty, head, remotes): 183 225 self.line('') 184 self.line("'''") 185 self.line('') 186 self.line('.%s' % (_git_status_text)) 226 self.line('- - -') 227 self.line(self._heading(_git_status_text, 2)) 187 228 if valid: 188 self.line('*Remotes*:;;') 229 self.line(self._strong('Remotes:')) 230 self.line('') 231 rc = 1 189 232 for r in remotes: 190 233 if 'url' in remotes[r]: … … 192 235 else: 193 236 text = 'no URL found' 194 text = '%s: %s' % (r, text) 195 self.line('. %s' % (text)) 196 self.line('*Status*:;;') 237 self.line('%d. %s: %s' % (rc, r, text)) 238 rc += 1 239 self.line('') 240 self.line(self._strong('Status:')) 241 self.line('') 197 242 if dirty: 198 self.line(' _Repository is dirty_')243 self.line('> ' + self._italic('Repository is dirty')) 199 244 else: 200 self.line(' Clean')201 self.line(' *Head*:;;')202 self.line(' Commit: %s' % (head))245 self.line('> Clean') 246 self.line('>') 247 self.line('> ' + self._bold('Head: ') + head) 203 248 else: 204 self.line('_Not a valid GIT repository_') 205 self.line('') 206 self.line("'''") 249 self.line('> ' + self._italic('Not a valid GIT repository')) 207 250 self.line('') 208 251 209 252 def config(self, nest_level, name, _config): 210 self.line('*Package*: _%s_ +' % (name)) 211 self.line('*Config*: %s' % (_config.file_name())) 212 self.line('') 253 self._bline(nest_level, self._bold('Package:')) 254 self._bline(nest_level, '') 255 self._bline(nest_level + 1, self._table_row([self._bold('Item'), 256 self._bold('Description')])) 257 self._bline(nest_level + 1, self._table_line()) 258 self._bline(nest_level + 1, self._table_row(['Package', name])) 259 self._bline(nest_level + 1, self._table_row(['Config', 260 _config.file_name()])) 213 261 214 262 def config_end(self, nest_level, name): 215 self.line('') 216 self.line("'''") 217 self.line('') 263 self._bline(nest_level + 1, '') 218 264 219 265 def buildset_start(self, nest_level, name): 220 h = '%s' % (name) 221 self.line('=%s %s' % ('=' * int(nest_level), h)) 266 if nest_level == 1: 267 self.line('- - -') 268 self._bline(nest_level, 269 self._heading('RTEMS Source Builder Packages', 2)) 270 self._bline(nest_level, 271 self._heading('%s Build %s' % (self._level(nest_level), name), 3)) 222 272 223 273 def info(self, nest_level, name, info, separated): 224 end = '' 225 if separated: 226 self.line('*%s:*::' % (name)) 227 self.line('') 228 else: 229 self.line('*%s:* ' % (name)) 230 end = ' +' 231 spaces = '' 232 for l in info: 233 self.line('%s%s%s' % (spaces, l, end)) 234 if separated: 235 self.line('') 274 self._bline(nest_level + 1, 275 self._table_row([name, ' '.join(info)])) 236 276 237 277 def directive(self, nest_level, name, data): 238 self.line('') 239 self.line('*%s*:' % (name)) 240 self.line('--------------------------------------------') 278 self._bline(nest_level, '') 279 self._bline(nest_level, self._bold(name + ':')) 241 280 for l in data: 242 self.line(l) 243 self.line('--------------------------------------------') 281 self._bline(nest_level + 1, ' ' * 4 + l) 244 282 245 283 def files(self, nest_level, singular, plural, _files): 246 self.line('') 247 self.line('*' + plural + ':*::') 284 self._bline(nest_level, '') 285 self._bline(nest_level, self._bold(plural + ':')) 286 self._bline(nest_level, '') 248 287 if len(_files) == 0: 249 self.line('No ' + plural.lower()) 288 self._bline(nest_level + 1, 'No ' + plural.lower()) 289 fc = 0 250 290 for name in _files: 251 291 for s in _files[name]: 252 self.line('. %s' % (s[0]))292 fc += 1 253 293 if s[1] is None: 254 h = 'No checksum'294 h = self._bold('No checksum') 255 295 else: 256 296 hash = s[1].split() 257 297 h = '%s: %s' % (hash[0], hash[1]) 258 self.line('+\n%s\n' % (h)) 259 260 class html_formatter(asciidoc_formatter): 298 self._bline(nest_level, 299 '%d. [%s](%s "%s %s")<br/>' % (fc, s[0], s[0], 300 name, singular.lower())) 301 self._bline(nest_level, 302 ' <span class=checksum>%s</span>' % (h)) 303 304 class html_formatter(markdown_formatter): 261 305 def __init__(self): 262 306 super(html_formatter, self).__init__() 307 self.html_header = '<!DOCTYPE html>' + os.linesep + \ 308 '<html lang="en">' + os.linesep + \ 309 '<head>' + os.linesep + \ 310 '<title>RTEMS RSB - @BUILD@</title>' + os.linesep + \ 311 '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />' + os.linesep + \ 312 '<meta name="created" content="@NOW@" />' + os.linesep + \ 313 '<meta name="description" content="RTEMS RSB Report" />' + os.linesep + \ 314 '<meta name="keywords" content="RTEMS RSB" />' + os.linesep + \ 315 '<meta charset="utf-8">' + os.linesep + \ 316 '<meta http-equiv="X-UA-Compatible" content="IE=edge">' + os.linesep + \ 317 '<meta name="viewport" content="width=device-width, initial-scale=1">' + os.linesep + \ 318 '<style type="text/css">' + os.linesep + \ 319 'body {' + os.linesep + \ 320 ' font-family: arial, helvetica, serif;' + os.linesep + \ 321 ' font-style: normal;' + os.linesep + \ 322 ' font-weight: 400;' + os.linesep + \ 323 '}' + os.linesep + \ 324 'h1, h2 { margin: 10px 5px 10px 5px; }' + os.linesep + \ 325 'h1 { font-size: 28px; }' + os.linesep + \ 326 'h2 { font-size: 22px;}' + os.linesep + \ 327 'h3 { font-size: 18px; }' + os.linesep + \ 328 'p, ol, blockquote, h3, table, pre { margin: 1px 20px 2px 7px; }' + os.linesep + \ 329 'table, th, td, pre { border: 1px solid gray; border-spacing: 0px; }' + os.linesep + \ 330 'table { width: 100%; }' + os.linesep + \ 331 'th, td { padding: 1px; }' + os.linesep + \ 332 'pre { padding: 4px; }' + os.linesep + \ 333 '.checksum { font-size: 12px; }' + os.linesep + \ 334 '</style>' + os.linesep + \ 335 '</head>' + os.linesep + \ 336 '<body>' + os.linesep 337 self.html_footer = '</body>' + os.linesep + \ 338 '</html>' + os.linesep 339 340 def _logo(self): 341 logo = _make_path(self.sbpath, options.basepath, 'images', 'rtemswhitebg.jpg') 342 try: 343 with open(logo, "rb") as image: 344 b64 = base64.b64encode(image.read()) 345 except: 346 raise error.general('installation error: no logo found') 347 logo = '<img alt="RTEMS Project" height="100" src="data:image/png;base64,' + b64 + '" />' 348 return logo 263 349 264 350 def format(self): … … 268 354 return '.html' 269 355 356 def introduction(self, name, now, intro_text): 357 self.name = name 358 self.now = now 359 super(html_formatter, self).introduction(name, now, intro_text) 360 270 361 def post_process(self): 271 import io272 infile = io.StringIO(self.content)273 outfile = io.StringIO()274 362 try: 275 import asciidocapi363 import markdown 276 364 except: 277 raise error.general('installation error: no asciidocapi found') 278 asciidoc_py = _make_path(self.sbpath, options.basepath, 'asciidoc', 'asciidoc.py') 365 raise error.general('installation error: no markdown found') 279 366 try: 280 asciidoc = asciidocapi.AsciiDocAPI(asciidoc_py) 367 out = markdown.markdown(self.content, 368 output_format = 'html5', 369 extensions = ['markdown.extensions.toc', 370 'markdown.extensions.tables', 371 'markdown.extensions.sane_lists', 372 'markdown.extensions.smarty']) 281 373 except: 282 raise error.general('application error: asciidocapi failed')283 asciidoc.execute(infile, outfile)284 out = outfile.getvalue()285 infile.close()286 outfile.close()287 return out374 raise 375 raise error.general('application error: markdown failed') 376 header = self.html_header.replace('@BUILD@', self.name).replace('@NOW@', self.now) 377 footer = self.html_footer 378 logo = self._logo() 379 return header + logo + out + footer 288 380 289 381 class text_formatter(formatter): … … 504 596 if formatter == 'text': 505 597 self.formatter = text_formatter() 506 elif formatter == ' asciidoc':507 self.formatter = asciidoc_formatter()598 elif formatter == 'markdown': 599 self.formatter = markdown_formatter() 508 600 elif formatter == 'html': 509 601 self.formatter = html_formatter() … … 785 877 optargs = { '--list-bsets': 'List available build sets', 786 878 '--list-configs': 'List available configurations', 787 '--format': 'Output format (text, html, asciidoc, ini, xml)',879 '--format': 'Output format (text, html, markdown, ini, xml)', 788 880 '--output': 'File name to output the report' } 789 opts = options.load(args, optargs )881 opts = options.load(args, optargs, logfile = False) 790 882 if opts.get_arg('--output') and len(opts.params()) > 1: 791 883 raise error.general('--output can only be used with a single config') … … 806 898 if format_opt[1] == 'text': 807 899 pass 808 elif format_opt[1] == ' asciidoc':809 formatter = asciidoc_formatter()900 elif format_opt[1] == 'markdown': 901 formatter = markdown_formatter() 810 902 elif format_opt[1] == 'html': 811 903 formatter = html_formatter() … … 825 917 config = build.find_config(_config, configs) 826 918 if config is None: 827 raise error.general('config file not found: %s' % ( inname))919 raise error.general('config file not found: %s' % (_config)) 828 920 r.create(config, outname) 829 921 del r
Note: See TracChangeset
for help on using the changeset viewer.