1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
22 from os.path import splitext
26 SKIP_DIRS = ("extern",
27 "tests", # not this dir
31 def is_c_header(filename):
32 ext = splitext(filename)[1]
33 return (ext in {".h", ".hpp", ".hxx", ".hh"})
37 ext = splitext(filename)[1]
38 return (ext in {".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"})
41 def is_c_any(filename):
42 return is_c(filename) or is_c_header(filename)
46 ext = splitext(filename)[1]
50 def is_source_any(filename):
51 return is_c_any(filename) or is_py(filename)
54 def source_list(path, filename_check=None):
55 for dirpath, dirnames, filenames in os.walk(path):
57 dirnames[:] = [d for d in dirnames if not d.startswith(".")]
59 for filename in filenames:
60 if filename_check is None or filename_check(filename):
61 yield os.path.join(dirpath, filename)
66 Searches out source code for lines like
68 /* *DEPRECATED* 2011/7/17 bgl.Buffer.list info text */
72 # *DEPRECATED* 2010/12/22 some.py.func more info */
76 SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
78 SKIP_DIRS_ABS = [os.path.join(SOURCE_DIR, p) for p in SKIP_DIRS]
84 print("scanning in %r for '*DEPRECATED* YYYY/MM/DD info'" % SOURCE_DIR)
86 for fn in source_list(SOURCE_DIR, is_source_any):
89 for p in SKIP_DIRS_ABS:
96 file = open(fn, 'r', encoding="utf8")
97 for i, l in enumerate(file):
98 # logic for deprecation warnings
99 if '*DEPRECATED*' in l:
102 data = l.split('*DEPRECATED*', 1)[-1].strip().strip()
103 data = [w.strip() for w in data.split('/', 2)]
104 data[-1], info = data[-1].split(' ', 1)
105 info = info.split("*/", 1)[0]
107 print(" poorly formatting line:\n"
113 data = datetime.datetime(*tuple([int(w) for w in data]))
115 deprecations_ls.append((data, (fn, i + 1), info))
117 print("Error file - %r:%d" % (fn, i + 1))
119 traceback.print_exc()
123 print(" scanned %d files" % scan_tot)
125 return deprecations_ls
130 now = datetime.datetime.now()
132 deps = deprecations()
134 print("\nAll deprecations...")
135 for data, fileinfo, info in deps:
136 days_old = (now - data).days
137 if days_old > DEPRECATE_DAYS:
138 info = "*** REMOVE! *** " + info
139 print(" %r, days-old(%.2d), %s:%d - %s" % (data, days_old, fileinfo[0], fileinfo[1], info))
143 print("\nnone found!")
146 if __name__ == '__main__':