コード例 #1
0
# 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
コード例 #2
0
def _atexit_call(func, *args, **kwargs):
    if _INITIAL_PID == os.getpid():
        func(*args, **kwargs)
コード例 #3
0
def send_signal(signum):
    """Send the given signal"""
    os.kill(os.getpid(), signum)
コード例 #4
0
ファイル: util_test.py プロジェクト: kcolford/letsencrypt
 def test_called(self):
     self._test_common(os.getpid())
     self.func.assert_called_with(*self.args, **self.kwargs)
コード例 #5
0
ファイル: error_handler.py プロジェクト: certbot/certbot
 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)
コード例 #6
0
def _atexit_call(func: Callable, *args: Any, **kwargs: Any) -> None:
    if _INITIAL_PID == os.getpid():
        func(*args, **kwargs)
コード例 #7
0
 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)
コード例 #8
0
ファイル: util.py プロジェクト: certbot/certbot
def _atexit_call(func, *args, **kwargs):
    if _INITIAL_PID == os.getpid():
        func(*args, **kwargs)
コード例 #9
0
ファイル: util.py プロジェクト: certbot/certbot
# 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:
コード例 #10
0
ファイル: util_test.py プロジェクト: certbot/certbot
 def test_called(self):
     self._test_common(os.getpid())
     self.func.assert_called_with(*self.args, **self.kwargs)
コード例 #11
0
ファイル: error_handler_test.py プロジェクト: certbot/certbot
def send_signal(signum):
    """Send the given signal"""
    os.kill(os.getpid(), signum)