update_license_header_cpp.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import os
00004 import datetime
00005 
00006 exclude_folders = ["lib", "bin", "build", "qpoases", "templates"]
00007 
00008 def update_license(filename, copyright):
00009     utfstr = chr(0xef) + chr(0xbb) + chr(0xbf)
00010     fdata = file(filename, "r+").read()
00011     
00012     isUTF = False
00013     if (fdata.startswith(utfstr)):
00014         isUTF = True
00015         fdata = fdata[3:]
00016     
00017     if fdata.startswith( "/*" ):
00018         # File starts with a header
00019         
00020         # Find end of the comment and trim the file
00021         fdata = fdata[fdata.find( "*/" ) + 2:]
00022         
00023     # Now write data to the file
00024     ndata = copyright[:-1] + fdata
00025     
00026     print "Updating: " + filename
00027     if (isUTF):
00028         file(filename, "w").write(utfstr + ndata)
00029     else:
00030         file(filename, "w").write(ndata)
00031 
00032 def recursive_traversal(dir, copyright):
00033     global exclude_folders
00034     fns = os.listdir(dir)
00035     for fn in fns:
00036         fullfn = os.path.join(dir, fn)
00037         if (os.path.isdir(fullfn)):
00038             if (os.path.basename( fullfn ) in exclude_folders):
00039                 continue
00040             recursive_traversal(fullfn, copyright)
00041         else:
00042             if (fullfn.endswith(".cpp") or fullfn.endswith(".hpp") or fullfn.endswith(".ipp")):
00043                 update_license(fullfn, copyright)
00044 
00045 # Read copyright data
00046 copyright = file("license_header_cpp.txt", "r+").read() % datetime.datetime.today().year
00047 # Update the licensing information
00048 folders = ["../include",
00049                    "../src",
00050                    "../external_packages/include",
00051                    "../external_packages/src",
00052                    "../examples"]
00053 
00054 for f in folders:
00055         recursive_traversal(f, copyright)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 12:01:27