root/trunk/tools/remove_dLocalize.py

Revision 3302, 0.9 kB (checked in by paul, 1 year ago)

I thought I'd commit the script I used to remove the dLocalize
import lines, in case it is useful for others to run against
their own apps.

Line 
1 """Clears the 'from dabo.dLocalize import *' lines from all python
2 files underneath the directory or directories you specify. If you
3 don't specify a directory, the current directory will be used.
4 """
5
6 import os
7
8 def clear_localize_walk(arg, dirname, fnames):
9     print "Processing directory %s..." % dirname
10     for fname in fnames:
11         if os.path.splitext(fname)[1] == ".py":
12             print "Checking file %s..." % fname
13             full_fname = os.path.join(dirname, fname)
14             rlines = open(full_fname).readlines()
15             wlines = []
16             for idx, line in enumerate(rlines):
17                 lineno = idx + 1
18                 if "dLocalize" in line:
19                     print "--> Removing line %s, '%s'" % (lineno, line)
20                     continue
21                 wlines.append(line)
22             open(full_fname, "wb").write(''.join(wlines))
23
24 def clear_localize(dirname):
25     os.path.walk(dirname, clear_localize_walk, None)
26
27
28 if __name__ == "__main__":
29     import sys
30
31     dirs = sys.argv[1:]
32     if not dirs:
33         dirs = ["."]
34     for dir in dirs:
35         clear_localize(dir)
Note: See TracBrowser for help on using the browser.