2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author : Adrien BRUNETON (CEA/DEN)
27 from optparse import OptionParser
30 DEFAULT_EXT = ['.hxx', '.cxx', '.txx', '.py', '.i', '.dox', '.rst', '.h', '.hh', '.hpp', '.c', '.cpp', ]
33 REPLACEMENTS = [("RevIntegral", "IntensiveConservation"),
34 ("ConservativeVolumic", "IntensiveMaximum"),
35 ("IntegralGlobConstraint", "ExtensiveConservation"),
36 ("Integral", "ExtensiveMaximum"),
37 ("MEDCouplingAutoRefCountObjectPtr", "MCAuto"),
38 ("deepCpy", "deepCopy")
41 __myName = os.path.abspath(__file__)
43 def convert(root_dir, ext, quiet):
44 if not os.path.isdir(root_dir):
45 raise ValueError("%s is not a valid directory!" % root_dir)
47 for root, _, fNames in os.walk(root_dir, followlinks=False):
49 fileName = os.path.join(root, fName)
51 if fileName == __myName:
53 print "!!! Skipping script %s !!!" % __myName
57 if fileName[-len(e):] == e:
60 if not ok: continue # skip file
61 if not quiet: print "Handling %s ..." % fileName
62 for line in fileinput.input(fileName, inplace=1, backup='.bak'):
63 for before, after in REPLACEMENTS:
64 line = re.sub("(\W|^)(%s)(\W|$)" % before, r"\1%s\3" % after, line.rstrip())
65 print(line) # print in file
67 parser = OptionParser()
68 parser.set_usage("Automatic code renaming, corresponding to the API changes between version 7x and 8x of MEDCoupling.\n"
69 "Original files are backup adding '.bak' to the original name.\n"
70 "On Linux file systems, links are not followed!\n\n"
71 " %prog [options] root_directory")
72 ext_disp = ",".join(DEFAULT_EXT)
73 parser.add_option("-e", "--extension", dest="extension", default="", metavar="EXTENSIONS",
74 help="Comma separated list of handled extensions (default is %s)" % ext_disp)
75 parser.add_option("-q", "--quiet",
76 action="store_false", dest="verbose", default=True,
77 help="Don't print status messages to stdout")
78 (opts, args) = parser.parse_args()
84 if opts.extension != "":
85 ext = [s.strip() for s in opts.extension.split(",")]
89 dirName = os.path.abspath(args[0])
90 convert(dirName, ext, not opts.verbose)