| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# SPDX-FileCopyrightText: 2014 Aurélien Gâteau <[email protected]> |
| 4 |
# SPDX-FileCopyrightText: 2014 Alex Merry <[email protected]> |
| 5 |
# SPDX-FileCopyrightText: 2014 Alex Turbov <[email protected]> |
| 6 |
# |
| 7 |
# SPDX-License-Identifier: BSD-2-Clause |
| 8 |
|
| 9 |
def _quote(txt): |
| 10 |
return '"' + txt + '"' |
| 11 |
|
| 12 |
|
| 13 |
class DoxyfileWriter(object): |
| 14 |
"""Makes it easy to write entries in a Doxyfile, correctly handling quoting |
| 15 |
""" |
| 16 |
def __init__(self, fl): |
| 17 |
self.fl = fl |
| 18 |
|
| 19 |
def write_entry(self, key, value): |
| 20 |
"""Write an entry |
| 21 |
|
| 22 |
Args: |
| 23 |
key: the key part of the entry |
| 24 |
value: the value part of the entry. Can be a string, a list, a |
| 25 |
tuple or a boolean |
| 26 |
""" |
| 27 |
if isinstance(value, (list, tuple)): |
| 28 |
txt = ' '.join([_quote(x) for x in value]) |
| 29 |
elif isinstance(value, bool): |
| 30 |
txt = ['NO', 'YES'][value] |
| 31 |
else: |
| 32 |
txt = _quote(str(value)) |
| 33 |
self.fl.write(key + ' = ' + txt + '\n') |
| 34 |
|
| 35 |
def write_entries(self, **kwargs): |
| 36 |
""" Call write_entry for all arguments passed""" |
| 37 |
for key, value in kwargs.items(): |
| 38 |
self.write_entry(key, value) |