From 24b23600aa5f74e2c81cfc25b78064eeab8d80de Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Tue, 16 Jan 2024 14:27:16 +0100 Subject: [PATCH] gw: fix config and systemd example generation --- documentation/gw.rst | 2 +- src/p4p/gw.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/documentation/gw.rst b/documentation/gw.rst index 04645788..75c747ed 100644 --- a/documentation/gw.rst +++ b/documentation/gw.rst @@ -16,7 +16,7 @@ The following commands will set up a gateway instance named ``mygw`` on a Linux sudo python -m p4p.gw --example-config /etc/pvagw/mygw.conf # generate a systemd unit file to support the gateway sudo python -m p4p.gw --example-systemd \ - /etc/systemd/system/pvagw@.service + /etc/systemd/system/pvagw@mygw.service # start the gateway sudo systemctl daemon-reload sudo systemctl start pvagw@mygw.service diff --git a/src/p4p/gw.py b/src/p4p/gw.py index fca7b336..be07e75a 100644 --- a/src/p4p/gw.py +++ b/src/p4p/gw.py @@ -745,21 +745,28 @@ def main(args=None): args = getargs().parse_args(args) catfile = None + conf = '/etc/pvagw/%i.conf' + I = '%i' if args.example_config: catfile = 'example.conf' + I = os.path.splitext(os.path.basename(args.config))[0] + conf = os.path.abspath(args.config) elif args.example_systemd: catfile = 'pvagw@.service' + inst = os.path.splitext(os.path.basename(args.config))[0].split('@') + if len(inst) == 2 and inst[1]: + I = inst[1] + conf = '/etc/pvagw/{0}.conf'.format(I) if catfile is not None: if args.config=='-': O = sys.stdout - I = '%i' - conf = '/etc/pvagw/%i.conf' - print('# eg. save as /etc/systemd/system/pvagw@.service', file=sys.stderr) + if args.example_config: + print('# eg. save as /etc/pvagw/.conf', file=sys.stderr) + elif args.example_systemd: + print('# eg. save as /etc/systemd/system/pvagw@.service', file=sys.stderr) else: O = open(args.config, 'w') - I = os.path.splitext(os.path.basename(args.config))[0] - conf = os.path.abspath(args.config) pythonpath=os.environ.get('PYTHONPATH','').split(os.pathsep) modroot = os.path.dirname(os.path.dirname(__file__)) # directory containing p4p/gw.py