Changeset 573b810 in mod_gnutls


Ignore:
Timestamp:
Jan 9, 2020, 2:47:21 AM (11 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
asyncio, master, proxy-ticket
Children:
7e10018
Parents:
278381d
Message:

mgstest.services: Use pathlib and conditional expressions

Just a minor simplification.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/mgstest/services.py

    r278381d r573b810  
    1717import errno
    1818import os
    19 import os.path
    2019import signal
    2120import subprocess
     
    2322
    2423from contextlib import contextmanager
     24from pathlib import Path
    2525from time import sleep
    2626
     
    3737        self.forking = forking
    3838        # condition: start service if the function returns true
    39         if condition:
    40             self.condition = condition
    41         else:
    42             self.condition = lambda: True
     39        self.condition = condition or (lambda: True)
    4340
    4441        # child process for non-forking services
     
    4643        # Forking processes like apache2 require a PID file for
    4744        # tracking. The process must delete its PID file when exiting.
    48         self.pidfile = pidfile
     45        self.pidfile = Path(pidfile) if pidfile else None
    4946        if not self.pidfile and self.forking:
    5047            raise ValueError('Forking service must provide PID file!')
     
    8683        # Read PID file before actually sending the stop signal
    8784        if self.pidfile:
    88             if not os.path.exists(self.pidfile):
     85            if not self.pidfile.exists():
    8986                print(f'Skipping stop of {self.stop_command}, no PID file!')
    9087                # Presumably the process isn't running, ignore.
    9188                return
    92             with open(self.pidfile, 'r') as file:
    93                 self.pid = int(file.read())
     89            self.pid = int(self.pidfile.read_text())
    9490        if self.stop_command:
    9591            print(f'Stopping: {self.stop_command}')
     
    170166
    171167    def __init__(self, config, env=None, pidfile=None, check=None):
    172         self.config = os.path.realpath(config)
     168        self.config = Path(config).resolve()
    173169        base_cmd = [self.apache2, '-f', str(self.config), '-k']
    174170        if not check:
     
    183179
    184180    def config_exists(self):
    185         return os.path.isfile(self.config)
     181        return self.config.is_file()
    186182
    187183    def pidfile_check(self):
    188184        """Default check method for ApacheService, waits for the PID file to
    189185        be present."""
    190         return os.path.exists(self.pidfile)
     186        return self.pidfile.is_file()
Note: See TracChangeset for help on using the changeset viewer.