diff options
author | Joshua Harlow <harlowja@gmail.com> | 2013-07-21 09:34:26 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@gmail.com> | 2013-07-21 09:34:26 -0700 |
commit | 27f096a1ab2e60222f85d87c961e388fdefaf92c (patch) | |
tree | 2caf81d15bd749166b760b31212a4bd45c75d4e6 | |
parent | 7022512f3ceb955be2834844f05d4683f78ff276 (diff) | |
download | vyos-cloud-init-27f096a1ab2e60222f85d87c961e388fdefaf92c.tar.gz vyos-cloud-init-27f096a1ab2e60222f85d87c961e388fdefaf92c.zip |
Use a util helper to do prefix/suffix removal.
-rw-r--r-- | cloudinit/handlers/boot_hook.py | 8 | ||||
-rw-r--r-- | cloudinit/util.py | 8 |
2 files changed, 11 insertions, 5 deletions
diff --git a/cloudinit/handlers/boot_hook.py b/cloudinit/handlers/boot_hook.py index 5e7b6204..1848ce2c 100644 --- a/cloudinit/handlers/boot_hook.py +++ b/cloudinit/handlers/boot_hook.py @@ -48,11 +48,9 @@ class BootHookPartHandler(handlers.Handler): def _write_part(self, payload, filename): filename = util.clean_filename(filename) filepath = os.path.join(self.boothook_dir, filename) - contents = util.dos2unix(payload) - if contents.startswith(BOOTHOOK_PREFIX): - real_start = len(BOOTHOOK_PREFIX) + 1 - contents = contents[real_start:] - util.write_file(filepath, contents, 0700) + contents = util.strip_prefix_suffix(util.dos2unix(payload), + prefix=BOOTHOOK_PREFIX) + util.write_file(filepath, contents.lstrip(), 0700) return filepath def handle_part(self, _data, ctype, filename, # pylint: disable=W0221 diff --git a/cloudinit/util.py b/cloudinit/util.py index c45aae06..47d71ef4 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1530,6 +1530,14 @@ def shellify(cmdlist, add_header=True): return content +def strip_prefix_suffix(line, prefix=None, suffix=None): + if prefix and line.startswith(prefix): + line = line[len(prefix):] + if suffix and line.endswith(suffix): + line = line[:-len(suffix)] + return line + + def is_container(): """ Checks to see if this code running in a container of some sort |