Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import sys
  2. import re
  3. import shlex
  4. import subprocess as sp
  5.  
  6. exe_pat = re.compile(r'(\s*)\(!>(.*)<\)\s*')
  7. inc_pat = re.compile(r'(\s*)\(>(.*)<\)\s*')
  8.  
  9. if __name__ == "__main__":
  10.   for line in sys.stdin:
  11.     match_exe = re.match(exe_pat, line)
  12.     match_inc = re.match(inc_pat, line)
  13.     if match_exe:
  14.       space = match_exe.group(1)
  15.       exe = match_exe.group(2).strip()
  16.       args = shlex.split(exe)
  17.       sys.stdout.writelines(map(lambda x: space+x+"\n", sp.check_output(args).split("\n")))
  18.     elif match_inc:
  19.       space = match_inc.group(1)
  20.       inc = match_inc.group(2).strip()
  21.       sys.stdout.writelines(map(lambda x: space+x, open(inc)))
  22.     else:
  23.       sys.stdout.write(line)