Use a util helper to do prefix/suffix removal.

This commit is contained in:
Joshua Harlow
2013-07-21 09:34:26 -07:00
parent c6c310d5ac
commit 0ef9a365d9
2 changed files with 11 additions and 5 deletions

View File

@@ -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

View File

@@ -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