Skip to content

Commit

Permalink
gw: fix config and systemd example generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphlange committed Jan 16, 2024
1 parent f5c96ba commit 0534e68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion documentation/gw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
# start the gateway
Expand Down
17 changes: 12 additions & 5 deletions src/p4p/gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]'
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/[email protected]', file=sys.stderr)
if args.example_config:
print('# eg. save as /etc/pvagw/<instance>.conf', file=sys.stderr)
elif args.example_systemd:
print('# eg. save as /etc/systemd/system/[email protected]', 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
Expand Down

0 comments on commit 0534e68

Please sign in to comment.