Blender V2.61 - r43446

check_deprecated.py

Go to the documentation of this file.
00001 # ##### BEGIN GPL LICENSE BLOCK #####
00002 #
00003 #  This program is free software; you can redistribute it and/or
00004 #  modify it under the terms of the GNU General Public License
00005 #  as published by the Free Software Foundation; either version 2
00006 #  of the License, or (at your option) any later version.
00007 #
00008 #  This program is distributed in the hope that it will be useful,
00009 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 #  GNU General Public License for more details.
00012 #
00013 #  You should have received a copy of the GNU General Public License
00014 #  along with this program; if not, write to the Free Software Foundation,
00015 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00016 #
00017 # ##### END GPL LICENSE BLOCK #####
00018 
00019 # <pep8 compliant>
00020 
00021 import os
00022 from os.path import splitext
00023 
00024 DEPRECATE_DAYS = 120
00025 
00026 SKIP_DIRS = ("extern",
00027              "scons",
00028              os.path.join("source", "tests"),  # not this dir
00029              )
00030 
00031 
00032 def is_c_header(filename):
00033     ext = splitext(filename)[1]
00034     return (ext in (".h", ".hpp", ".hxx"))
00035 
00036 
00037 def is_c(filename):
00038     ext = splitext(filename)[1]
00039     return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"))
00040 
00041 
00042 def is_c_any(filename):
00043     return is_c(filename) or is_c_header(filename)
00044 
00045 
00046 def is_py(filename):
00047     ext = splitext(filename)[1]
00048     return (ext == ".py")
00049 
00050 
00051 def is_source_any(filename):
00052     return is_c_any(filename) or is_py(filename)
00053 
00054 
00055 def source_list(path, filename_check=None):
00056     for dirpath, dirnames, filenames in os.walk(path):
00057 
00058         # skip '.svn'
00059         if dirpath.startswith("."):
00060             continue
00061 
00062         for filename in filenames:
00063             if filename_check is None or filename_check(filename):
00064                 yield os.path.join(dirpath, filename)
00065 
00066 
00067 def deprecations():
00068     """
00069     Searches out source code for lines like
00070 
00071     /* *DEPRECATED* 2011/7/17 bgl.Buffer.list info text */
00072 
00073     Or...
00074 
00075     # *DEPRECATED* 2010/12/22 some.py.func more info */
00076 
00077     """
00078     import datetime
00079     SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))))
00080 
00081     SKIP_DIRS_ABS = [os.path.join(SOURCE_DIR, p) for p in SKIP_DIRS]
00082 
00083     deprecations_ls = []
00084 
00085     scan_tot = 0
00086 
00087     print("scanning in %r for '*DEPRECATED* YYYY/MM/DD info'" % SOURCE_DIR)
00088 
00089     for fn in source_list(SOURCE_DIR, is_source_any):
00090         # print(fn)
00091         skip = False
00092         for p in SKIP_DIRS_ABS:
00093             if fn.startswith(p):
00094                 skip = True
00095                 break
00096         if skip:
00097             continue
00098 
00099         file = open(fn, 'r', encoding="utf8")
00100         for i, l in enumerate(file):
00101             # logic for deprecation warnings
00102             if '*DEPRECATED*' in l:
00103                 try:
00104                     l = l.strip()
00105                     data = l.split('*DEPRECATED*', 1)[-1].strip().strip()
00106                     data = [w.strip() for w in data.split('/', 2)]
00107                     data[-1], info = data[-1].split(' ', 1)
00108                     info = info.split("*/", 1)[0]
00109                     if len(data) != 3:
00110                         print("    poorly formatting line:\n"
00111                               "    %r:%d\n"
00112                               "    %s" %
00113                               (fn, i + 1, l)
00114                               )
00115                     else:
00116                         data = datetime.datetime(*tuple([int(w) for w in data]))
00117 
00118                         deprecations_ls.append((data, (fn, i + 1), info))
00119                 except:
00120                     print("Error file - %r:%d" % (fn, i + 1))
00121                     import traceback
00122                     traceback.print_exc()
00123 
00124         scan_tot += 1
00125 
00126     print("    scanned %d files" % scan_tot)
00127 
00128     return deprecations_ls
00129 
00130 
00131 def main():
00132     import datetime
00133     now = datetime.datetime.now()
00134 
00135     deps = deprecations()
00136 
00137     print("\nAll deprecations...")
00138     for data, fileinfo, info in deps:
00139         days_old = (now - data).days
00140         if days_old > DEPRECATE_DAYS:
00141             info = "*** REMOVE! *** " + info
00142         print("   %r, days-old(%.2d), %s:%d - %s" % (data, days_old, fileinfo[0], fileinfo[1], info))
00143     if deps:
00144         print("\ndone!")
00145     else:
00146         print("\nnone found!")
00147 
00148 if __name__ == '__main__':
00149     main()