Skip to content

Instantly share code, notes, and snippets.

@tangentstorm
Last active March 20, 2016 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangentstorm/5038a7c4a032b658744d to your computer and use it in GitHub Desktop.
Save tangentstorm/5038a7c4a032b658744d to your computer and use it in GitHub Desktop.
"""
usage: thing.py t a g s -- machine names
"""
import sys
# get the tags and machine names, each separated by spaces.
# the two groups are separated by --
args = sys.argv[1:]
cut = args.index('--') if '--' in args else len(args)
goal_tags = set(args[:cut])
goal_machines = set(args[cut:])
for line in open('whatever-the-file-is.txt').read().split('\n'):
line_name, line_tags = lines.split(' ',1)
if line_name in goal_machines or not goal_machines:
print line_name, ' '.join(t for t in line_tags.split(' ') if t in goal_tags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment