diff options
author | Akihiro Motoki <amotoki@gmail.com> | 2020-09-04 07:43:40 +0900 |
---|---|---|
committer | Akihiro Motoki <amotoki@gmail.com> | 2020-09-04 08:08:31 +0900 |
commit | d7b2995d587ef568d57e66ff62d764058c1254f0 (patch) | |
tree | e8181001c4d8cc5cd1e4815012624e1ea7cc0f24 /oslo_policy/generator.py | |
parent | c6ed9f33a55727e2411eae432f379b56ba9b9a6c (diff) | |
download | oslo-policy-d7b2995d587ef568d57e66ff62d764058c1254f0.tar.gz |
sample-generator: Improve YAML output
This commit makes the following minor improvements
in YAML output of oslopolicy-sample-generator.
* Add a blank line between policies.
Previously when a deprecated rule exists there was no blank line
between the deprecated rule and the next rule.
It was not easy to identify the beginning of the next rule.
* Drop unnecessary blank line comment.
If a policy is defined by RuleDefault instead of DocumentedRuleDefault
there is no description and unnecessary blank line comment was added
in an output YAML file.
* Honor newlines in deprecated_text.
Previously newlines in deprecated_text were dropped by
_format_help_text(). Main deprecation message and reason are
processed separately and newlines are not dropped now.
Change-Id: I75889a1b05344a47135419d0553525f54c1a51b8
Diffstat (limited to 'oslo_policy/generator.py')
-rw-r--r-- | oslo_policy/generator.py | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/oslo_policy/generator.py b/oslo_policy/generator.py index a35acae..244de03 100644 --- a/oslo_policy/generator.py +++ b/oslo_policy/generator.py @@ -186,12 +186,13 @@ def _format_rule_default_yaml(default, include_help=True, comment_rule=True, '# Intended scope(s): ' + ', '.join(default.scope_types) + '\n' ) comment = '#' if comment_rule else '' - text = ('%(help)s\n%(op)s%(scope)s%(comment)s%(text)s\n' % - {'help': _format_help_text(default.description), - 'op': op, + text = ('%(op)s%(scope)s%(comment)s%(text)s\n' % + {'op': op, 'scope': intended_scope, 'comment': comment, 'text': text}) + if default.description: + text = _format_help_text(default.description) + '\n' + text if add_deprecated_rules and default.deprecated_for_removal: text = ( @@ -206,29 +207,24 @@ def _format_rule_default_yaml(default, include_help=True, comment_rule=True, # This issues a deprecation warning but aliases the old policy name # with the new policy name for compatibility. deprecated_text = ( - 'DEPRECATED\n"%(old_name)s":"%(old_check_str)s" has been ' - 'deprecated since %(since)s in favor of ' - '"%(name)s":"%(check_str)s".\n%(reason)s' + '"%(old_name)s":"%(old_check_str)s" has been deprecated ' + 'since %(since)s in favor of "%(name)s":"%(check_str)s".' ) % {'old_name': default.deprecated_rule.name, 'old_check_str': default.deprecated_rule.check_str, 'since': default.deprecated_since, 'name': default.name, 'check_str': default.check_str, - 'reason': default.deprecated_reason} + } + text = ('%(text)s# DEPRECATED\n%(deprecated_text)s\n%(reason)s\n' % + {'text': text, + 'reason': _format_help_text(default.deprecated_reason), + 'deprecated_text': _format_help_text(deprecated_text)}) if default.name != default.deprecated_rule.name: - text = ( - '%(text)s%(deprecated_text)s\n"%(old_name)s": "rule:%(name)s"' - '\n' - ) % {'text': text, - 'deprecated_text': _format_help_text(deprecated_text), - 'old_name': default.deprecated_rule.name, - 'name': default.name} - else: - text = ( - '%(text)s%(deprecated_text)s\n' - ) % {'text': text, - 'deprecated_text': _format_help_text(deprecated_text)} + text += ('"%(old_name)s": "rule:%(name)s"\n' % + {'old_name': default.deprecated_rule.name, + 'name': default.name}) + text += '\n' return text |