From 83127c026c6bed02bc63ee4d8fabc54efbbcf48f Mon Sep 17 00:00:00 2001 From: "mila@ringwald.ch" Date: Fri, 6 Feb 2015 10:46:18 +0000 Subject: [PATCH] add update_copyright python script --- tools/update_copyright.py | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tools/update_copyright.py diff --git a/tools/update_copyright.py b/tools/update_copyright.py new file mode 100644 index 000000000..8a2c370a3 --- /dev/null +++ b/tools/update_copyright.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +import os +import re + +copyright = """ +/* + * Copyright (C) 2014 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ +""" + +onlyDumpDifferentCopyright = True +copyrightString = "Copyright (C) 2014 BlueKitchen GmbH" +copyrighters = ["BlueKitchen", "Matthias Ringwald"] + +ignoreFolders = ["cpputest", "msp-exp430f5438-cc2564b", "msp430f5229lp-cc2564b", "ez430-rf2560", "ios"] +ignoreFiles = ["ant_cmds.h"] + +class State: + SearchStartComment = 0 + SearchCopyrighter = 1 + SearchEndComment = 2 + EndSearch = 3 + +def updateCopyright(file_name): + global onlyDumpDifferentCopyright + if not onlyDumpDifferentCopyright: + print file_name, ": Update copyright" + +def analyseCopyright(file_name): + global copyrightString, onlyDumpDifferentCopyright + + with open(file_name, "rb") as fin: + parts = [] + allowedCopyrighters = [] + state = State.SearchStartComment + + for line in fin: + if state == State.SearchStartComment: + parts = re.match('\s*(/\*).*',line, re.I) + if parts: + state = State.SearchCopyrighter + + if state == State.SearchCopyrighter: + parts = re.match('.*(Copyright).*',line, re.I) + if parts: + allowedCopyrighterFound = False + for name in copyrighters: + allowedCopyrighters = re.match('.*('+name+').*',line, re.I) + if allowedCopyrighters: + allowedCopyrighterFound = True + if not (re.match(copyrightString,line)): + updateCopyright(file_name) + if not allowedCopyrighterFound and onlyDumpDifferentCopyright: + print file_name, ": Copyrighter not allowed > ", parts.group() + state = State.SearchEndComment + + if state == State.SearchEndComment: + parts = re.match('\s*(\*/).*',line, re.I) + if parts: + state = State.EndSearch + + if state == State.EndSearch: + continue + fin.close() + +for root, dirs, files in os.walk('../', topdown=True): + dirs[:] = [d for d in dirs if d not in ignoreFolders] + files[:] = [f for f in files if f not in ignoreFiles] + for f in files: + if f.endswith(".h") or f.endswith(".c"): + file_name = root + "/" + f + analyseCopyright(file_name) + + + \ No newline at end of file