From 1b4e56ab9b3d6a84ecf9475cb79cd439e0240f9b Mon Sep 17 00:00:00 2001 From: Sam Gleske Date: Wed, 30 Jul 2014 18:37:16 -0400 Subject: [PATCH] Now reads from stdin if no hosts.dat or --hostlist Example: cat hosts.dat | horde /tmp/test /tmp/test Fixes bug if --hostlist is passed junk like: horde --hostlist 1,2,3,,,\#test /tmp/test /tmp/test Fixes bug --hostlist passing blank list of hosts like: ./horde --hostlist '' /tmp/test /tmp/test --- horde/horde.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/horde/horde.py b/horde/horde.py index 55b1cef..abc1f9b 100755 --- a/horde/horde.py +++ b/horde/horde.py @@ -161,16 +161,15 @@ def local_ip(): def hordemain(): if not os.path.exists(opts['hosts']) and opts['hostlist'] is False: - sys.exit('ERROR: hosts file "%s" does not exist' % opts['hosts']) - - if opts['hosts']: + hosts = [line.strip() for line in sys.stdin] + elif opts['hosts']: hosts = [line.strip() for line in open(opts['hosts'], 'r')] - # filter out comments and empty lines - hosts = [ - host for host in hosts if not re.match("^#", host) - and host is not ''] else: hosts = opts['hostlist'].split(',') + # filter out comments and empty lines + hosts = [host for host in hosts if not re.match("^#", host) and not host == ''] + if len(hosts) == 0: + sys.exit('ERROR: No hosts provided.') # handles duplicates hosts = list(set(hosts)) log.info("Running with options: %s" % opts)