diff options
author | Scott Moser <smoser@ubuntu.com> | 2014-01-24 20:13:38 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-01-24 20:13:38 -0500 |
commit | 9876ad7d74f90f7c7433fb4dc1fa07e664ff92bc (patch) | |
tree | eb248c6ab4c08665fa336e1bd4a1b7d5ea5c9ece | |
parent | 93c0bcf6a048e278ead6b4392d3507c40441b7bb (diff) | |
download | vyos-cloud-init-9876ad7d74f90f7c7433fb4dc1fa07e664ff92bc.tar.gz vyos-cloud-init-9876ad7d74f90f7c7433fb4dc1fa07e664ff92bc.zip |
minor changes for pylint, write_boot_content improvement.
if write_boot_content is given somethign that starts with #!,
then there isn't a reason to invoke 'file' to tell us that it
starts with shebang.
This way, we only run file in 2 cases:
a.) binary content (don't really know if that is supported or not)
b.) magic "user meant to run this with /bin/bash but couldn't be bothered to
type that"
-rw-r--r-- | cloudinit/sources/DataSourceSmartOS.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py index b0fabe05..140c7814 100644 --- a/cloudinit/sources/DataSourceSmartOS.py +++ b/cloudinit/sources/DataSourceSmartOS.py @@ -36,7 +36,6 @@ from cloudinit import util import os import os.path import serial -import subprocess LOG = logging.getLogger(__name__) @@ -313,7 +312,8 @@ def dmi_data(): return (sys_uuid.lower().strip(), sys_type.strip()) -def write_boot_content(content, content_f, link=None, shebang=False, mode=0400): +def write_boot_content(content, content_f, link=None, shebang=False, + mode=0400): """ Write the content to content_f. Under the following rules: 1. If no content, remove the file @@ -343,16 +343,15 @@ def write_boot_content(content, content_f, link=None, shebang=False, mode=0400): util.write_file(content_f, content, mode=mode) - if shebang: + if shebang and not content.startswith("#!"): try: cmd = ["file", "--brief", "--mime-type", content_f] (f_type, _err) = util.subp(cmd) - LOG.debug("script %s mime type is %s" % (content_f, f_type)) - line_one = content.splitlines()[0] - if f_type.strip() == "text/plain" and "#!" not in line_one: + LOG.debug("script %s mime type is %s", content_f, f_type) + if f_type.strip() == "text/plain": new_content = "\n".join(["#!/bin/bash", content]) util.write_file(content_f, new_content, mode=mode) - LOG.debug("added shebang to file %s" % content_f) + LOG.debug("added shebang to file %s", content_f) except Exception as e: util.logexc(LOG, ("Failed to identify script type for %s" % |