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

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.55 KB  |  hits: 16  |  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. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys
  5. import os
  6. import subprocess
  7.  
  8. def do_sed(fullpath, old, new):
  9.     sed_script = "s/%s/%s/g" % (old, new)
  10.     command = ["sed", "-i", fullpath, "-e", sed_script]
  11.     subprocess.call(command)
  12.  
  13. if __name__ == '__main__':
  14.     argvs = sys.argv
  15.     argc = len(argvs)
  16.  
  17.     if argc != 3:
  18.         sys.exit(1)
  19.  
  20.     old = argvs[1]
  21.     new = argvs[2]
  22.  
  23.     srcdir = "."
  24.     for root,dir,files in os.walk(srcdir):
  25.         for f in files:
  26.             fullpath = os.path.join(root,f)
  27.             do_sed(fullpath, old, new)