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):
58 if dirpath.startswith("."):
61 for filename in filenames:
62 if filename_check is None or filename_check(filename):
63 yield os.path.join(dirpath, filename)
68 Searches out source code for lines like
70 /* *DEPRECATED* 2011/7/17 bgl.Buffer.list info text */
74 # *DEPRECATED* 2010/12/22 some.py.func more info */
78 SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
80 SKIP_DIRS_ABS = [os.path.join(SOURCE_DIR, p) for p in SKIP_DIRS]
86 print("scanning in %r for '*DEPRECATED* YYYY/MM/DD info'" % SOURCE_DIR)
88 for fn in source_list(SOURCE_DIR, is_source_any):
91 for p in SKIP_DIRS_ABS:
98 file = open(fn, 'r', encoding="utf8")
99 for i, l in enumerate(file):
100 # logic for deprecation warnings
101 if '*DEPRECATED*' in l:
104 data = l.split('*DEPRECATED*', 1)[-1].strip().strip()
105 data = [w.strip() for w in data.split('/', 2)]
106 data[-1], info = data[-1].split(' ', 1)
107 info = info.split("*/", 1)[0]
109 print(" poorly formatting line:\n"
115 data = datetime.datetime(*tuple([int(w) for w in data]))
117 deprecations_ls.append((data, (fn, i + 1), info))
119 print("Error file - %r:%d" % (fn, i + 1))
121 traceback.print_exc()
125 print(" scanned %d files" % scan_tot)
127 return deprecations_ls
132 now = datetime.datetime.now()
134 deps = deprecations()
136 print("\nAll deprecations...")
137 for data, fileinfo, info in deps:
138 days_old = (now - data).days
139 if days_old > DEPRECATE_DAYS:
140 info = "*** REMOVE! *** " + info
141 print(" %r, days-old(%.2d), %s:%d - %s" % (data, days_old, fileinfo[0], fileinfo[1], info))
145 print("\nnone found!")
147 if __name__ == '__main__':