summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils
diff options
context:
space:
mode:
authorAndrew Butcher <abutcher@afrolegs.com>2017-01-25 11:37:48 -0500
committerGitHub <noreply@github.com>2017-01-25 11:37:48 -0500
commitd8fee0cc8441812cdd5e7aaae815adad7a9bbee7 (patch)
tree81aafd9b795aeab7d64e1ae94fc72b3e5c7c576d /roles/lib_utils
parent22706eb1bef19329ac0e72303d02f1c47e48e825 (diff)
parentcf5f85ff884107cfba3ac929d2f731d98f467ce0 (diff)
downloadopenshift-d8fee0cc8441812cdd5e7aaae815adad7a9bbee7.tar.gz
openshift-d8fee0cc8441812cdd5e7aaae815adad7a9bbee7.tar.bz2
openshift-d8fee0cc8441812cdd5e7aaae815adad7a9bbee7.tar.xz
openshift-d8fee0cc8441812cdd5e7aaae815adad7a9bbee7.zip
Merge pull request #3141 from tbielawa/fragment_banners
Fragment banners
Diffstat (limited to 'roles/lib_utils')
-rw-r--r--roles/lib_utils/library/yedit.py16
-rwxr-xr-xroles/lib_utils/src/generate.py37
2 files changed, 52 insertions, 1 deletions
diff --git a/roles/lib_utils/library/yedit.py b/roles/lib_utils/library/yedit.py
index 6a5b40dcc..8a2bd92f9 100644
--- a/roles/lib_utils/library/yedit.py
+++ b/roles/lib_utils/library/yedit.py
@@ -24,6 +24,8 @@
# limitations under the License.
#
+# -*- -*- -*- Begin included fragment: class/import.py -*- -*- -*-
+
# pylint: disable=wrong-import-order
import json
import os
@@ -33,6 +35,10 @@ import ruamel.yaml as yaml
import shutil
from ansible.module_utils.basic import AnsibleModule
+# -*- -*- -*- End included fragment: class/import.py -*- -*- -*-
+
+# -*- -*- -*- Begin included fragment: doc/yedit -*- -*- -*-
+
DOCUMENTATION = '''
---
module: yedit
@@ -168,6 +174,10 @@ EXAMPLES = '''
# b:
# c: d
'''
+
+# -*- -*- -*- End included fragment: doc/yedit -*- -*- -*-
+
+# -*- -*- -*- Begin included fragment: class/yedit.py -*- -*- -*-
# noqa: E301,E302
@@ -733,6 +743,10 @@ class Yedit(object):
return {'failed': True, 'msg': 'Unkown state passed'}
+# -*- -*- -*- End included fragment: class/yedit.py -*- -*- -*-
+
+# -*- -*- -*- Begin included fragment: ansible/yedit.py -*- -*- -*-
+
# pylint: disable=too-many-branches
def main():
@@ -772,3 +786,5 @@ def main():
if __name__ == '__main__':
main()
+
+# -*- -*- -*- End included fragment: ansible/yedit.py -*- -*- -*-
diff --git a/roles/lib_utils/src/generate.py b/roles/lib_utils/src/generate.py
index 6daade108..3f23455b5 100755
--- a/roles/lib_utils/src/generate.py
+++ b/roles/lib_utils/src/generate.py
@@ -27,19 +27,54 @@ def parse_args():
return parser.parse_args()
+def fragment_banner(fragment_path, side, data):
+ """Generate a banner to wrap around file fragments
+
+:param string fragment_path: A path to a module fragment
+:param string side: ONE OF: "header", "footer"
+:param StringIO data: A StringIO object to write the banner to
+"""
+ side_msg = {
+ "header": "Begin included fragment: {}",
+ "footer": "End included fragment: {}"
+ }
+ annotation = side_msg[side].format(fragment_path)
+
+ banner = """
+# -*- -*- -*- {} -*- -*- -*-
+""".format(annotation)
+
+ # Why skip?
+ #
+ # * 'generated' - This is the head of the script, we don't want to
+ # put comments before the #!shebang
+ #
+ # * 'license' - Wrapping this just seemed like gratuitous extra
+ if ("generated" not in fragment_path) and ("license" not in fragment_path):
+ data.write(banner)
+
+ # Make it self-contained testable
+ return banner
+
+
def generate(parts):
- '''generate the source code for the ansible modules'''
+ '''generate the source code for the ansible modules
+
+:param Array parts: An array of paths (strings) to module fragments
+ '''
data = six.StringIO()
for fpart in parts:
# first line is pylint disable so skip it
with open(os.path.join(OPENSHIFT_ANSIBLE_PATH, fpart)) as pfd:
+ fragment_banner(fpart, "header", data)
for idx, line in enumerate(pfd):
if idx in [0, 1] and 'flake8: noqa' in line or 'pylint: skip-file' in line: # noqa: E501
continue
data.write(line)
+ fragment_banner(fpart, "footer", data)
return data