blob: 8f706f363741787c7554e787f7397473d53c80a4 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Enable other layers to have modules in the same named directory
2from pkgutil import extend_path
3__path__ = extend_path(__path__, __name__)
4
5
6# Borrowed from CalledProcessError
7
8class 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 Williamsd8c66bc2016-06-20 12:57:21 -050016def 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