"""Plugin utilities.""" import logging from certbot import util from certbot.compat import os from certbot.compat.misc import STANDARD_BINARY_DIRS logger = logging.getLogger(__name__) def get_prefixes(path): """Retrieves all possible path prefixes of a path, in descending order of length. For instance, (linux) /a/b/c returns ['/a/b/c', '/a/b', '/a', '/'] (windows) C:\\a\\b\\c returns ['C:\\a\\b\\c', 'C:\\a\\b', 'C:\\a', 'C:'] :param str path: the path to break into prefixes :returns: all possible path prefixes of given path in descending order :rtype: `list` of `str` """ prefix = os.path.normpath(path) prefixes = [] while prefix: prefixes.append(prefix) prefix, _ = os.path.split(prefix) # break once we hit the root path if prefix == prefixes[-1]: break return prefixes def path_surgery(cmd): """Attempt to perform PATH surgery to find cmd Mitigates https://github.com/certbot/certbot/issues/1833 :param str cmd: the command that is being searched for in the PATH :returns: True if the operation succeeded, False otherwise """ path = os.environ["PATH"] added = [] for d in STANDARD_BINARY_DIRS: if d not in path: path += os.pathsep + d added.append(d) if any(added): logger.debug("Can't find %s, attempting PATH mitigation by adding %s", cmd, os.pathsep.join(added)) os.environ["PATH"] = path if util.exe_exists(cmd): return True expanded = " expanded" if any(added) else "" logger.debug("Failed to find executable %s in%s PATH: %s", cmd, expanded, path) return False
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
__init__.py | File | 30 B | 0644 |
|
common.py | File | 18.68 KB | 0644 |
|
common_test.py | File | 14.89 KB | 0644 |
|
disco.py | File | 9.96 KB | 0644 |
|
disco_test.py | File | 11.34 KB | 0644 |
|
dns_common.py | File | 11.69 KB | 0644 |
|
dns_common_lexicon.py | File | 5.41 KB | 0644 |
|
dns_common_lexicon_test.py | File | 651 B | 0644 |
|
dns_common_test.py | File | 8.18 KB | 0644 |
|
dns_test_common.py | File | 1.65 KB | 0644 |
|
dns_test_common_lexicon.py | File | 5.48 KB | 0644 |
|
enhancements.py | File | 5.58 KB | 0644 |
|
enhancements_test.py | File | 2.36 KB | 0644 |
|
manual.py | File | 7.88 KB | 0644 |
|
manual_test.py | File | 5.6 KB | 0644 |
|
null.py | File | 1.27 KB | 0644 |
|
null_test.py | File | 624 B | 0644 |
|
selection.py | File | 13.55 KB | 0644 |
|
selection_test.py | File | 7.78 KB | 0644 |
|
standalone.py | File | 7.72 KB | 0644 |
|
standalone_test.py | File | 6.64 KB | 0644 |
|
storage.py | File | 4.14 KB | 0644 |
|
storage_test.py | File | 5.47 KB | 0644 |
|
util.py | File | 1.69 KB | 0644 |
|
util_test.py | File | 1.81 KB | 0644 |
|
webroot.py | File | 12.08 KB | 0644 |
|
webroot_test.py | File | 13.11 KB | 0644 |
|