summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorTim Bielawa <tbielawa@redhat.com>2017-01-20 10:30:19 -0800
committerTim Bielawa <tbielawa@redhat.com>2017-01-24 07:55:39 -0800
commit14ddb400093cbfb4abeca60b7edc434fcf380315 (patch)
tree6f903ced126fb1fdcd1f3a60df715e70e1127e38 /roles
parent14d118989cbca57c22c5b6e970067e0d9f9708bb (diff)
downloadopenshift-14ddb400093cbfb4abeca60b7edc434fcf380315.tar.gz
openshift-14ddb400093cbfb4abeca60b7edc434fcf380315.tar.bz2
openshift-14ddb400093cbfb4abeca60b7edc434fcf380315.tar.xz
openshift-14ddb400093cbfb4abeca60b7edc434fcf380315.zip
Update the generators to include fragment banners
Diffstat (limited to 'roles')
-rwxr-xr-xroles/lib_openshift/src/generate.py37
-rwxr-xr-xroles/lib_utils/src/generate.py37
2 files changed, 72 insertions, 2 deletions
diff --git a/roles/lib_openshift/src/generate.py b/roles/lib_openshift/src/generate.py
index 6daade108..3f23455b5 100755
--- a/roles/lib_openshift/src/generate.py
+++ b/roles/lib_openshift/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
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