From ec64b0ef8b83fa7a13501b59c238a39133584166 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 17 Aug 2023 23:16:24 +0200 Subject: [PATCH] Added `--device_id` command line option. --- platypush/app/_app.py | 19 ++++++++++++++----- platypush/cli.py | 11 +++++++++++ platypush/platydock/__main__.py | 1 - 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/platypush/app/_app.py b/platypush/app/_app.py index e95d0db3..c11e1af0 100644 --- a/platypush/app/_app.py +++ b/platypush/app/_app.py @@ -42,6 +42,7 @@ class Application: config_file: Optional[str] = None, workdir: Optional[str] = None, logsdir: Optional[str] = None, + device_id: Optional[str] = None, pidfile: Optional[str] = None, requests_to_process: Optional[int] = None, no_capture_stdout: bool = False, @@ -61,6 +62,10 @@ class Application: ``filename`` setting under the ``logging`` section of the configuration file is used. If not set, logging will be sent to 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, useful if you're planning to integrate the application within a service or a launcher script (default: None). @@ -97,11 +102,14 @@ class Application: os.path.abspath(os.path.expanduser(logsdir)) if logsdir else None ) - Config.init(self.config_file) - Config.set('ctrl_sock', ctrl_sock) - - if workdir: - Config.set('workdir', os.path.abspath(os.path.expanduser(workdir))) + Config.init( + self.config_file, + device_id=device_id, + workdir=os.path.abspath(os.path.expanduser(workdir)) if workdir else None, + 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_stderr = no_capture_stderr @@ -199,6 +207,7 @@ class Application: config_file=opts.config, workdir=opts.workdir, logsdir=opts.logsdir, + device_id=opts.device_id, pidfile=opts.pidfile, no_capture_stdout=opts.no_capture_stdout, no_capture_stderr=opts.no_capture_stderr, diff --git a/platypush/cli.py b/platypush/cli.py index 9864c16b..f3768b19 100644 --- a/platypush/cli.py +++ b/platypush/cli.py @@ -29,6 +29,17 @@ def parse_cmdline(args: Sequence[str]) -> argparse.Namespace: 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( '--logsdir', '-l', diff --git a/platypush/platydock/__main__.py b/platypush/platydock/__main__.py index f216837d..bc0461ab 100644 --- a/platypush/platydock/__main__.py +++ b/platypush/platydock/__main__.py @@ -3,4 +3,3 @@ from platypush.platydock import main main() # vim:sw=4:ts=4:et: -