Skip to content

Instantly share code, notes, and snippets.

@rstruber
Last active September 25, 2015 19:24
Show Gist options
  • Save rstruber/615cda0a9617819ed701 to your computer and use it in GitHub Desktop.
Save rstruber/615cda0a9617819ed701 to your computer and use it in GitHub Desktop.
@task
def stats():
with tempfile.NamedTemporaryFile() as f:
f.write('first line')
execute(collect, f.name)
import pdb; pdb.set_trace()
# from pdb, get f.name, and cat the file shows N lines in the file without "first line"
f.seek(0)
# cat the temp file, only has "first line"
for l in f:
print(green(l)) # prints "first line"
@task
@parallel
@roles('vm')
def collect(f_name):
with open(f_name, 'a+b') as f:
f.write('%s\n'.format(env.host))
with open(f_name, 'r+b') as f:
f.seek(0)
print f.read() # prints this host plus whatever else got there first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment