Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Enable other layers to have modules in the same named directory |
| 2 | from pkgutil import extend_path |
| 3 | __path__ = extend_path(__path__, __name__) |
| 4 | |
| 5 | |
| 6 | # Borrowed from CalledProcessError |
| 7 | |
| 8 | class CommandError(Exception): |
| 9 | def __init__(self, retcode, cmd, output = None): |
| 10 | self.retcode = retcode |
| 11 | self.cmd = cmd |
| 12 | self.output = output |
| 13 | def __str__(self): |
| 14 | return "Command '%s' returned non-zero exit status %d with output: %s" % (self.cmd, self.retcode, self.output) |
| 15 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 16 | def avoid_paths_in_environ(paths): |
| 17 | """ |
| 18 | Searches for every path in os.environ['PATH'] |
| 19 | if found remove it. |
| 20 | |
| 21 | Returns new PATH without avoided PATHs. |
| 22 | """ |
| 23 | import os |
| 24 | |
| 25 | new_path = '' |
| 26 | for p in os.environ['PATH'].split(':'): |
| 27 | avoid = False |
| 28 | for pa in paths: |
| 29 | if pa in p: |
| 30 | avoid = True |
| 31 | break |
| 32 | if avoid: |
| 33 | continue |
| 34 | |
| 35 | new_path = new_path + p + ':' |
| 36 | |
| 37 | new_path = new_path[:-1] |
| 38 | return new_path |