# ANSI SGR escape codes # Formats text as bold or with increased intensity ANSI_SGR_BOLD = '\033[1m' # Colors text red ANSI_SGR_RED = "\033[31m" # Resets output format ANSI_SGR_RESET = "\033[0m" PERM_ERR_FMT = os.linesep.join( ("The following error was encountered:", "{0}", "Either run as root, or set --config-dir, " "--work-dir, and --logs-dir to writeable paths.")) # Stores importing process ID to be used by atexit_register() _INITIAL_PID = os.getpid() # Maps paths to locked directories to their lock object. All locks in # the dict are attempted to be cleaned up at program exit. If the # program exits before the lock is cleaned up, it is automatically # released, but the file isn't deleted. _LOCKS = OrderedDict() # type: OrderedDict[str, lock.LockFile] def env_no_snap_for_external_calls(): """ When Certbot is run inside a Snap, certain environment variables are modified. But Certbot sometimes calls out to external programs, since it uses classic confinement. When we do that, we must modify the env to remove our modifications so it will use the system's libraries, since they may be incompatible with the versions of libraries included in the Snap. For example, apachectl, Nginx, and
def _atexit_call(func, *args, **kwargs): if _INITIAL_PID == os.getpid(): func(*args, **kwargs)
def send_signal(signum): """Send the given signal""" os.kill(os.getpid(), signum)
def test_called(self): self._test_common(os.getpid()) self.func.assert_called_with(*self.args, **self.kwargs)
def _call_signals(self): """Finally call the deferred signals.""" for signum in self.received_signals: logger.debug("Calling signal %s", signum) os.kill(os.getpid(), signum)
def _atexit_call(func: Callable, *args: Any, **kwargs: Any) -> None: if _INITIAL_PID == os.getpid(): func(*args, **kwargs)
def _call_signals(self) -> None: """Finally call the deferred signals.""" for signum in self.received_signals: logger.debug("Calling signal %s", signum) os.kill(os.getpid(), signum)
# Formats text as bold or with increased intensity ANSI_SGR_BOLD = '\033[1m' # Colors text red ANSI_SGR_RED = "\033[31m" # Resets output format ANSI_SGR_RESET = "\033[0m" PERM_ERR_FMT = os.linesep.join(( "The following error was encountered:", "{0}", "Either run as root, or set --config-dir, " "--work-dir, and --logs-dir to writeable paths.")) # Stores importing process ID to be used by atexit_register() _INITIAL_PID = os.getpid() # Maps paths to locked directories to their lock object. All locks in # the dict are attempted to be cleaned up at program exit. If the # program exits before the lock is cleaned up, it is automatically # released, but the file isn't deleted. _LOCKS = OrderedDict() # type: OrderedDict[str, lock.LockFile] def run_script(params, log=logger.error): """Run the script with the given params. :param list params: List of parameters to pass to Popen :param callable log: Logger method to use for errors """ try: