From dc1a1524335ff36b09b7a6f7c49446e4c0151005 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 14 Aug 2023 10:46:27 +0200 Subject: [PATCH] Added `get_default_pid_file` utility method. --- platypush/__init__.py | 3 ++- platypush/cli.py | 5 +++-- platypush/utils/__init__.py | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/platypush/__init__.py b/platypush/__init__.py index f4e9ecb9..ede8fee4 100644 --- a/platypush/__init__.py +++ b/platypush/__init__.py @@ -5,12 +5,13 @@ Platypush .. license: MIT """ -from .app import Application, main +from .app import Application from .config import Config from .context import get_backend, get_bus, get_plugin from .message.event import Event from .message.request import Request from .message.response import Response +from .runner import main __author__ = 'Fabio Manganiello ' diff --git a/platypush/cli.py b/platypush/cli.py index 81bc4c35..9864c16b 100644 --- a/platypush/cli.py +++ b/platypush/cli.py @@ -2,6 +2,7 @@ import argparse from typing import Sequence from platypush.bus.redis import RedisBus +from platypush.utils import get_default_pid_file def parse_cmdline(args: Sequence[str]) -> argparse.Namespace: @@ -61,10 +62,10 @@ def parse_cmdline(args: Sequence[str]) -> argparse.Namespace: '-P', dest='pidfile', required=False, - default=None, + default=get_default_pid_file(), help="File where platypush will " + "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( diff --git a/platypush/utils/__init__.py b/platypush/utils/__init__.py index fd80f1e9..a164c982 100644 --- a/platypush/utils/__init__.py +++ b/platypush/utils/__init__.py @@ -14,6 +14,7 @@ import socket import ssl import urllib.request from threading import Lock as TLock +from tempfile import gettempdir from typing import Generator, Optional, Tuple, Union from dateutil import parser, tz @@ -625,4 +626,11 @@ def get_lock( 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: