Permalink
Browse files

Fixed range plugin parsing when handling multiple plugins

and ranges.
  • Loading branch information...
1 parent 9fcf5ac commit 3a91be688c1066e9d0035b4253b2f3d65da72645 @dwighthubbard dwighthubbard committed Aug 15, 2012
Showing with 30 additions and 5 deletions.
  1. +28 −3 hostlists/hostlists.py
  2. +1 −1 setup.py
  3. +1 −1 sshmap/sshmap.py
@@ -77,6 +77,10 @@ def expand(range_list):
item=None
newlist+=plugins[plugin].expand(':'.join(temp[1:]).strip(':'))
found_plugin=True
+ else:
+ # Default to running through the range plugin
+ item=None
+ newlist+=plugins['range'].expand(temp[0])
if item:
newlist.append(item)
# Recurse back through ourselves incase a plugin returns a value that needs to be parsed
@@ -93,15 +97,36 @@ def compress(range_list):
# really compress at all.
return ','.join(range_list).strip(',')
+def range_split(range):
+ """ Split up a range string, this needs to seperate comma seperated
+ items unless they are within square brackets """
+ in_brackets=False
+ current=""
+ result_list=[]
+ for c in range:
+ if c in ['[']:
+ in_brackets=True
+ if c in [']']:
+ in_brackets=False
+ if not in_brackets and c==',':
+ result_list.append(current)
+ current=""
+ else:
+ current+=c
+ if len(current):
+ result_list.append(current)
+ return result_list
+
if __name__ == "__main__":
parser = optparse.OptionParser(usage="usage: %prog [options] plugin:parameters")
parser.add_option("-s","--sep",dest="sep",default=',',help="Seperator character, default=\",\"")
parser.add_option("--onepass",dest="onepass",default=False,action="store_true")
parser.add_option("--expand","-e",dest="expand",default=False,action="store_true",help="Expand the host list and dislay one host per line")
(options, args) = parser.parse_args()
- range=','.join(args)
+ range=range_split(','.join(args))
+
if options.expand:
- print '\n'.join(expand(range.split(',')))
+ print '\n'.join(expand(range))
else:
- print compress(expand(range.split(',')))
+ print compress(expand(range))
View
@@ -18,7 +18,7 @@
setup(
name="sshmap",
- version="0.2.99",
+ version="0.3.0",
author="Dwight Hubbard",
author_email="dhubbard@yahoo-inc.com",
url="http://www.yahoo.com",
View
@@ -429,7 +429,7 @@ def run(range,command,username=None,password=None,sudo=False,script=None,timeout
None
"""
status_info(output_callback,' \bLooking up hosts')
- hosts=hostlists.expand(range)
+ hosts=hostlists.expand(hostlists.range_split(range))
if shuffle:
random.shuffle(hosts)
status_clear()

0 comments on commit 3a91be6

Please sign in to comment.