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",
28 os.path.join("source", "tests"), # not this dir
32 def is_c_header(filename):
33 ext = splitext(filename)[1]
34 return (ext in {".h", ".hpp", ".hxx", ".hh"})
38 ext = splitext(filename)[1]
39 return (ext in {".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"})
42 def is_c_any(filename):
43 return is_c(filename) or is_c_header(filename)
47 ext = splitext(filename)[1]
51 def is_source_any(filename):
52 return is_c_any(filename) or is_py(filename)
55 def source_list(path, filename_check=None):
56 for dirpath, dirnames, filenames in os.walk(path):
59 if dirpath.startswith("."):
62 for filename in filenames:
63 if filename_check is None or filename_check(filename):
64 yield os.path.join(dirpath, filename)
69 Searches out source code for lines like
71 /* *DEPRECATED* 2011/7/17 bgl.Buffer.list info text */
75 # *DEPRECATED* 2010/12/22 some.py.func more info */
79 SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))))
81 SKIP_DIRS_ABS = [os.path.join(SOURCE_DIR, p) for p in SKIP_DIRS]
87 print("scanning in %r for '*DEPRECATED* YYYY/MM/DD info'" % SOURCE_DIR)
89 for fn in source_list(SOURCE_DIR, is_source_any):
92 for p in SKIP_DIRS_ABS:
99 file = open(fn, 'r', encoding="utf8")
100 for i, l in enumerate(file):
101 # logic for deprecation warnings
102 if '*DEPRECATED*' in l:
105 data = l.split('*DEPRECATED*', 1)[-1].strip().strip()
106 data = [w.strip() for w in data.split('/', 2)]
107 data[-1], info = data[-1].split(' ', 1)
108 info = info.split("*/", 1)[0]
110 print(" poorly formatting line:\n"
116 data = datetime.datetime(*tuple([int(w) for w in data]))
118 deprecations_ls.append((data, (fn, i + 1), info))
120 print("Error file - %r:%d" % (fn, i + 1))
122 traceback.print_exc()
126 print(" scanned %d files" % scan_tot)
128 return deprecations_ls
133 now = datetime.datetime.now()
135 deps = deprecations()
137 print("\nAll deprecations...")
138 for data, fileinfo, info in deps:
139 days_old = (now - data).days
140 if days_old > DEPRECATE_DAYS:
141 info = "*** REMOVE! *** " + info
142 print(" %r, days-old(%.2d), %s:%d - %s" % (data, days_old, fileinfo[0], fileinfo[1], info))
146 print("\nnone found!")
148 if __name__ == '__main__':