Skip to content

Instantly share code, notes, and snippets.

@ieure
Created April 10, 2010 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ieure/362340 to your computer and use it in GitHub Desktop.
Save ieure/362340 to your computer and use it in GitHub Desktop.
from __future__ import with_statement
import itertools
import functools
import sys
def download_files(keylist):
return [key.get_contents_to_filename('%s/%s' % (TEMP_DIR, key.name))
for key in keylist]
def post_process(data):
return copy(data).update(
df_use_percent=data.get('df_use_percent', '').rstrip('%'))
def get_ssh_options(ssh_config, host):
def skip_to_host(lines):
return itertools.islice(
itertools.dropwhile(lambda line: 'Host %s' % host not in line,
lines), 1, sys.maxint)
skip_to_host_end = functools.partial(
itertools.takewhile, lambda line: not line.startswith('Host'))
strip_blanks = functools.partial(itertools.ifilter,
lambda line: line)
def strip_comments_whitespace(lines):
return (line.split('#')[0].strip() for line in lines)
return dict(line.lower().split(None, 1) for line in
strip_blanks(strip_comments_whitespace(
skip_to_host_end(skip_to_host(ssh_config.readlines())))))
with open('/home/ieure/.ssh/config', 'r') as config:
print get_ssh_options(config, 'somehost.com')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment