From 0534e683df2b08131f663127192490f6f7517550 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..0d654310 100644 --- a/documentation/gw.rst +++ b/documentation/gw.rst @@ -14,7 +14,7 @@ The following commands will set up a gateway instance named ``mygw`` on a Linux # generate a simple configuration file sudo python -m p4p.gw --example-config /etc/pvagw/mygw.conf - # generate a systemd unit file to support the gateway + # generate a systemd unit file template to support the gateway sudo python -m p4p.gw --example-systemd \ /etc/systemd/system/pvagw@.service # start the gateway diff --git a/src/p4p/gw.py b/src/p4p/gw.py index fca7b336..f4291ef0 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 + I = '%i' + conf = '/etc/pvagw/%i.conf' 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