Added get_default_pid_file utility method.

This commit is contained in:
Fabio Manganiello 2023-08-14 10:46:27 +02:00
parent c11bc69a66
commit dc1a152433
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
3 changed files with 13 additions and 3 deletions

View file

@ -5,12 +5,13 @@ Platypush
.. license: MIT .. license: MIT
""" """
from .app import Application, main from .app import Application
from .config import Config from .config import Config
from .context import get_backend, get_bus, get_plugin from .context import get_backend, get_bus, get_plugin
from .message.event import Event from .message.event import Event
from .message.request import Request from .message.request import Request
from .message.response import Response from .message.response import Response
from .runner import main
__author__ = 'Fabio Manganiello <fabio@manganiello.tech>' __author__ = 'Fabio Manganiello <fabio@manganiello.tech>'

View file

@ -2,6 +2,7 @@ import argparse
from typing import Sequence from typing import Sequence
from platypush.bus.redis import RedisBus from platypush.bus.redis import RedisBus
from platypush.utils import get_default_pid_file
def parse_cmdline(args: Sequence[str]) -> argparse.Namespace: def parse_cmdline(args: Sequence[str]) -> argparse.Namespace:
@ -61,10 +62,10 @@ def parse_cmdline(args: Sequence[str]) -> argparse.Namespace:
'-P', '-P',
dest='pidfile', dest='pidfile',
required=False, required=False,
default=None, default=get_default_pid_file(),
help="File where platypush will " help="File where platypush will "
+ "store its PID, useful if you're planning to " + "store its PID, useful if you're planning to "
+ "integrate it in a service", + f"integrate it in a service (default: {get_default_pid_file()})",
) )
parser.add_argument( parser.add_argument(

View file

@ -14,6 +14,7 @@ import socket
import ssl import ssl
import urllib.request import urllib.request
from threading import Lock as TLock from threading import Lock as TLock
from tempfile import gettempdir
from typing import Generator, Optional, Tuple, Union from typing import Generator, Optional, Tuple, Union
from dateutil import parser, tz from dateutil import parser, tz
@ -625,4 +626,11 @@ def get_lock(
lock.release() lock.release()
def get_default_pid_file() -> str:
"""
Get the default PID file path.
"""
return os.path.join(gettempdir(), 'platypush.pid')
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: