diff options
| author | Scott Moser <smoser@ubuntu.com> | 2013-07-24 11:04:34 -0400 | 
|---|---|---|
| committer | Scott Moser <smoser@ubuntu.com> | 2013-07-24 11:04:34 -0400 | 
| commit | 82397d79f1c0618f25eab6e28e65b1e59a98603a (patch) | |
| tree | 282753410e972115da387fdef471f6563b5b3379 /cloudinit/util.py | |
| parent | eae3b6ad499b88b725a52cf07245e4721af380cf (diff) | |
| parent | 0891f6611d1c264220a6f71306802db1e70651fc (diff) | |
| download | vyos-cloud-init-82397d79f1c0618f25eab6e28e65b1e59a98603a.tar.gz vyos-cloud-init-82397d79f1c0618f25eab6e28e65b1e59a98603a.zip  | |
merge from trunk
Diffstat (limited to 'cloudinit/util.py')
| -rw-r--r-- | cloudinit/util.py | 27 | 
1 files changed, 27 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index c45aae06..8542fe27 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 @@ -1743,3 +1751,22 @@ def get_mount_info(path, log=LOG):      mountinfo_path = '/proc/%s/mountinfo' % os.getpid()      lines = load_file(mountinfo_path).splitlines()      return parse_mount_info(path, lines, log) + + +def which(program): +    # Return path of program for execution if found in path +    def is_exe(fpath): +        return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + +    _fpath, _ = os.path.split(program) +    if _fpath: +        if is_exe(program): +            return program +    else: +        for path in os.environ["PATH"].split(os.pathsep): +            path = path.strip('"') +            exe_file = os.path.join(path, program) +            if is_exe(exe_file): +                return exe_file + +    return None  | 
