]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/dev/archery/archery/utils/report.py
6c7587ddd8729f1a8f6dcec48832d90e65c99351
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
18 from abc
import ABCMeta
, abstractmethod
24 def markdown_escape(s
):
25 for char
in ('*', '#', '_', '~', '`', '>'):
26 s
= s
.replace(char
, '\\' + char
)
30 class Report(metaclass
=ABCMeta
):
32 def __init__(self
, **kwargs
):
33 for field
in self
.fields
:
34 if field
not in kwargs
:
35 raise ValueError('Missing keyword argument {}'.format(field
))
38 def __getattr__(self
, key
):
39 return self
._data
[key
]
51 class JinjaReport(Report
):
53 def __init__(self
, **kwargs
):
54 self
.env
= jinja2
.Environment(
55 loader
=jinja2
.PackageLoader('archery', 'templates')
57 self
.env
.filters
['md'] = markdown_escape
58 self
.env
.globals['today'] = datetime
.date
.today
59 super().__init
__(**kwargs
)
61 def render(self
, template_name
):
62 template_path
= self
.templates
[template_name
]
63 template
= self
.env
.get_template(template_path
)
64 return template
.render(**self
._data
)