Add remove_from_path() function for removing an entry from the system PATH.
* All removed entries should have an @atexit hook to be reinserted into the system PATH before the Python interpreter exits.testing/mmn/mktime_takes_localtime_not_gmtime
parent
a34fd1c423
commit
f67270609f
20
src/gnupg.py
20
src/gnupg.py
|
@ -245,6 +245,26 @@ class GPGBase(object):
|
||||||
log.debug("Created a copy of system PATH: %r" % path_copy)
|
log.debug("Created a copy of system PATH: %r" % path_copy)
|
||||||
assert not os.environ.has_key('PATH'), "OS env kept $PATH anyway!"
|
assert not os.environ.has_key('PATH'), "OS env kept $PATH anyway!"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def remove_program_from_path(path, prog_base):
|
||||||
|
"""Remove all directories which contain a program from PATH.
|
||||||
|
|
||||||
|
:param str path: The contents of the system environment's
|
||||||
|
PATH.
|
||||||
|
:param str prog_base: The base (directory only) portion of a
|
||||||
|
program's location.
|
||||||
|
"""
|
||||||
|
paths = path.split(':')
|
||||||
|
for directory in paths:
|
||||||
|
if directory == prog_base:
|
||||||
|
log.debug("Found directory with target program: %s"
|
||||||
|
% directory)
|
||||||
|
path.remove(directory)
|
||||||
|
self._removed_path_entries.append(directory)
|
||||||
|
log.debug("Deleted all found instance of %s." % directory)
|
||||||
|
log.debug("PATH is now:%s%s" % (os.linesep, path))
|
||||||
|
new_path = ':'.join([p for p in path])
|
||||||
|
return new_path
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_path(env_copy, path_value):
|
def update_path(env_copy, path_value):
|
||||||
|
|
Loading…
Reference in New Issue