Commit c0c3612e authored by vieira's avatar vieira Committed by Brian May

Allow subnets to be given only by file (-s)

This should fix #116. Handling this while still having the positional
arguments and -s both write to the same list turned out to be more
complicated than it's worth so each writes to their own variable and we
merge them at the end.
parent 0033efca
...@@ -20,13 +20,13 @@ def main(): ...@@ -20,13 +20,13 @@ def main():
try: try:
if opt.firewall: if opt.firewall:
if opt.subnets: if opt.subnets or opt.subnets_file:
parser.error('exactly zero arguments expected') parser.error('exactly zero arguments expected')
return firewall.main(opt.method, opt.syslog) return firewall.main(opt.method, opt.syslog)
elif opt.hostwatch: elif opt.hostwatch:
return hostwatch.hw_main(opt.subnets) return hostwatch.hw_main(opt.subnets)
else: else:
includes = opt.subnets includes = opt.subnets + opt.subnets_file
excludes = opt.exclude excludes = opt.exclude
if not includes and not opt.auto_nets: if not includes and not opt.auto_nets:
parser.error('at least one subnet, subnet file, ' parser.error('at least one subnet, subnet file, '
......
...@@ -106,7 +106,7 @@ class Concat(Action): ...@@ -106,7 +106,7 @@ class Concat(Action):
super(Concat, self).__init__(option_strings, dest, **kwargs) super(Concat, self).__init__(option_strings, dest, **kwargs)
def __call__(self, parser, namespace, values, option_string=None): def __call__(self, parser, namespace, values, option_string=None):
curr_value = getattr(namespace, self.dest, []) curr_value = getattr(namespace, self.dest, None) or []
setattr(namespace, self.dest, curr_value + values) setattr(namespace, self.dest, curr_value + values)
...@@ -269,7 +269,7 @@ parser.add_argument( ...@@ -269,7 +269,7 @@ parser.add_argument(
"-s", "--subnets", "-s", "--subnets",
metavar="PATH", metavar="PATH",
action=Concat, action=Concat,
dest="subnets", dest="subnets_file",
type=parse_subnet_file, type=parse_subnet_file,
help=""" help="""
file where the subnets are stored, instead of on the command line file where the subnets are stored, instead of on the command line
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment