diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-06-22 17:38:29 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-06-22 17:39:06 (GMT) |
commit | e8360f0dd62ea651e94f681499faef58747f2ece (patch) | |
tree | 5eeb231a12a44c65baf648b0350387a6f25986af /tools | |
parent | 86e892137d512a11edde0aa7760fc1c15e598dad (diff) | |
download | swift-contrib-e8360f0dd62ea651e94f681499faef58747f2ece.zip swift-contrib-e8360f0dd62ea651e94f681499faef58747f2ece.tar.bz2 |
Support vCard-based avatars in MUCs.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/Copyrighter.py | 107 |
1 files changed, 92 insertions, 15 deletions
diff --git a/tools/Copyrighter.py b/tools/Copyrighter.py index 9726f03..189dcf5 100755 --- a/tools/Copyrighter.py +++ b/tools/Copyrighter.py @@ -1,19 +1,96 @@ #!/usr/bin/env python +#coding=utf-8 -import os +import os, re, datetime TEMPLATE = """/* - * Copyright (c) %(year)s %(author)s - * %(license)s - */""" - -for (path, dirs, files) in os.walk("src") : - if "3rdParty" in path : - continue - for filename in files : - if not filename.endswith(".cpp") and not filename.endswith(".h") : - continue - if filename.startswith("moc_") : - continue - fullFilename = path + "/" + filename - print fullFilename + * Copyright (c) %(year)s %(author)s. + * See the included COPYING file for license details. + */ + +""" + +def updateCopyright(fileName) : + file = open(fileName) + fileData = "" + + author = "" + startYear = "" + endYear = "" + previousCopyright = "" + + # Retrieve previous copyright information + header = "" + inHeader = False + inSpaceBelowHeader = False + lines = file.readlines() + lines2 = lines + for line in lines2 : + lines.pop(0) + if inSpaceBelowHeader : + if line.strip() != "" : + break + elif inHeader : + if line.startswith(" */") : + inSpaceBelowHeader = True + else : + header += line + else : + if line.strip() == "" : + continue + elif line.startswith("/*") : + inHeader = True + header += line + else : + fileData += line + break + if "Copyright" in header : + previousCopyright = header + m = re.match("\* Copyright \(c\) (?P<startYear>\d\d\d\d)(-(?P<endYear>\d\d\d\d))? (?P<author>.*)", header) + if m : + author = m.group("author") + startYear = m.group("startYear") + endYear = m.group("endYear") + elif header != "" : + fileData = header + file.close() + + # Read in the rest of the data + fileData += "".join(lines) + + # Guess empty values + if author == "" : + if "Swift/" in fileName : + author = "Kevin Smith" + else : + author = u"Remko Tronçon" + if startYear == "" : + startYear = datetime.date.today().strftime("%Y") + elif endYear == "" : + ## TODO: Guess end year by looking at git log --pretty=format:%ai -- <filename> + pass + + # Generate a copyright + year = startYear + "-" + endYear if len(endYear) > 0 else startYear + copyright = TEMPLATE % { + "author" : author, + "year" : year + } + + # Write the copyright to the file + if copyright.encode("utf-8") != previousCopyright : + file = open(fileName, "w") + file.write(copyright.encode("utf-8")) + file.write(fileData) + file.close() + +for (path, dirs, files) in os.walk("Swiften/JID") : + if "3rdParty" in path : + continue + for filename in files : + if not filename.endswith(".cpp") and not filename.endswith(".h") : + continue + if filename.startswith("moc_") : + continue + fullFilename = path + "/" + filename + updateCopyright(fullFilename) |