3 # Copyright 2006 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 from optparse import OptionParser
31 dirs_to_ignore = ('CVS', '.svn', '.deps', '.libs')
32 extensions_to_ignore = ('.o', '.lo',
36 '.ko', '.fasl', '.rwbak',
37 '.tar', '.gz', '.log',
38 '.eps', '.ps', '.pdf',
39 '.png', '.jpg', '.jpeg', '.bmp',
42 '.lib', '.lst', '.rel', '.sym', '.asm', '.rst', 'mem', '.map', # sdcc output
43 '.rbf', '.esf', '.qpf', '.psf', '.quartus', '.bsf', '.cmp' # quartus
46 def destructively_remove(list, predicate):
48 Destructively remove elements from LIST for which PREDICATE is true
50 for i in range(len(list)):
51 if predicate(list[i]):
53 destructively_remove(list, predicate)
57 def expunge_unwanted_dirnames(dirnames):
59 Destructively remove directory names that we don't want to visit.
60 This is a _very_ non-functional approach to programming...
62 destructively_remove(dirnames, lambda d: d in dirs_to_ignore)
64 def expunge_unwanted_filenames(filenames):
66 Destructively remove filenames that we don't want to visit.
67 This is a _very_ non-functional approach to programming...
69 destructively_remove(filenames,
70 lambda f: f.endswith('~') or os.path.splitext(f)[1] in extensions_to_ignore)
73 def walk_directory(dirname):
74 for dirpath, dirnames, filenames in os.walk(dirname):
75 expunge_unwanted_dirnames(dirnames)
76 expunge_unwanted_filenames(filenames)
78 update_one(os.path.join(dirpath, f))
81 addr_pattern = re.compile(r'\b59 Temple Place(,| *-) *Suite 330\b', re.IGNORECASE)
82 addr_replacement = '51 Franklin Street'
83 zip_pattern = re.compile(r'\b02111-1307\b')
84 zip_replacement = '02110-1301'
86 def update_one(filename):
87 f = open(filename, 'r')
91 t = addr_pattern.sub(addr_replacement, t)
92 t = zip_pattern.sub(zip_replacement, t)
94 modified_files.append(filename)
96 f = open(filename, 'w')
100 def handle_file_or_dir(file_or_dir):
101 if os.path.isfile(file_or_dir):
102 update_one(file_or_dir)
103 elif os.path.isdir(file_or_dir):
104 walk_directory(file_or_dir)
106 pass # ignore the other cases
112 usage = '%prog: [options] [file_or_dir...]'
113 parser = OptionParser (usage=usage)
114 parser.add_option('-l', '--list-modified-files', action='store_true', default=False,
115 help='List modified files to stdout [default=%default]')
116 parser.add_option('', '--dry-run', action='store_true', default=False,
117 help="Don't modify any files, just report what would be modified [default=%default]")
118 (options, args) = parser.parse_args()
120 dry_run = options.dry_run
122 options.list_modified_files = True
124 for file_or_dir in args:
125 handle_file_or_dir(file_or_dir)
127 if options.list_modified_files:
128 for f in modified_files:
129 sys.stdout.write(f + '\n')
132 if __name__ == '__main__':