Added --device_id command line option.

This commit is contained in:
Fabio Manganiello 2023-08-17 23:16:24 +02:00
parent ac83b43f98
commit ec64b0ef8b
Signed by: blacklight
GPG key ID: D90FBA7F76362774
3 changed files with 25 additions and 6 deletions

View file

@ -42,6 +42,7 @@ class Application:
config_file: Optional[str] = None, config_file: Optional[str] = None,
workdir: Optional[str] = None, workdir: Optional[str] = None,
logsdir: Optional[str] = None, logsdir: Optional[str] = None,
device_id: Optional[str] = None,
pidfile: Optional[str] = None, pidfile: Optional[str] = None,
requests_to_process: Optional[int] = None, requests_to_process: Optional[int] = None,
no_capture_stdout: bool = False, no_capture_stdout: bool = False,
@ -61,6 +62,10 @@ class Application:
``filename`` setting under the ``logging`` section of the ``filename`` setting under the ``logging`` section of the
configuration file is used. If not set, logging will be sent to configuration file is used. If not set, logging will be sent to
stdout and stderr. stdout and stderr.
:param device_id: Override the device ID used to identify this
instance. If not passed here, it is inferred from the configuration
(device_id field). If not present there either, it is inferred from
the hostname.
:param pidfile: File where platypush will store its PID upon launch, :param pidfile: File where platypush will store its PID upon launch,
useful if you're planning to integrate the application within a useful if you're planning to integrate the application within a
service or a launcher script (default: None). service or a launcher script (default: None).
@ -97,11 +102,14 @@ class Application:
os.path.abspath(os.path.expanduser(logsdir)) if logsdir else None os.path.abspath(os.path.expanduser(logsdir)) if logsdir else None
) )
Config.init(self.config_file) Config.init(
Config.set('ctrl_sock', ctrl_sock) self.config_file,
device_id=device_id,
if workdir: workdir=os.path.abspath(os.path.expanduser(workdir)) if workdir else None,
Config.set('workdir', os.path.abspath(os.path.expanduser(workdir))) ctrl_sock=os.path.abspath(os.path.expanduser(ctrl_sock))
if ctrl_sock
else None,
)
self.no_capture_stdout = no_capture_stdout self.no_capture_stdout = no_capture_stdout
self.no_capture_stderr = no_capture_stderr self.no_capture_stderr = no_capture_stderr
@ -199,6 +207,7 @@ class Application:
config_file=opts.config, config_file=opts.config,
workdir=opts.workdir, workdir=opts.workdir,
logsdir=opts.logsdir, logsdir=opts.logsdir,
device_id=opts.device_id,
pidfile=opts.pidfile, pidfile=opts.pidfile,
no_capture_stdout=opts.no_capture_stdout, no_capture_stdout=opts.no_capture_stdout,
no_capture_stderr=opts.no_capture_stderr, no_capture_stderr=opts.no_capture_stderr,

View file

@ -29,6 +29,17 @@ def parse_cmdline(args: Sequence[str]) -> argparse.Namespace:
help='Custom working directory to be used for the application', help='Custom working directory to be used for the application',
) )
parser.add_argument(
'--device-id',
'-d',
dest='device_id',
required=False,
default=None,
help='Override the device ID used to identify this instance. If not '
'passed here, it is inferred from the configuration (device_id field).'
'If not present there either, it is inferred from the hostname.',
)
parser.add_argument( parser.add_argument(
'--logsdir', '--logsdir',
'-l', '-l',

View file

@ -3,4 +3,3 @@ from platypush.platydock import main
main() main()
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: