From 482c6e36d782f4069b6ef78abb444b2a5179b7b1 Mon Sep 17 00:00:00 2001 From: Liyou Zhou Date: Mon, 23 Nov 2015 18:07:35 +0000 Subject: [PATCH] Add script to change license headers for sdk files --- script/copyright_header.txt | 31 +++++++++++++++++++++++++++++++ script/replace_headers.py | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 script/copyright_header.txt create mode 100644 script/replace_headers.py diff --git a/script/copyright_header.txt b/script/copyright_header.txt new file mode 100644 index 0000000..81c3753 --- /dev/null +++ b/script/copyright_header.txt @@ -0,0 +1,31 @@ +/* + * Copyright (c) Nordic Semiconductor ASA + * All rights reserved. + * + * 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 Nordic Semiconductor ASA nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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. + * + */ \ No newline at end of file diff --git a/script/replace_headers.py b/script/replace_headers.py new file mode 100644 index 0000000..e6abff7 --- /dev/null +++ b/script/replace_headers.py @@ -0,0 +1,23 @@ +import os + +with open("copyright_header.txt", "r") as fd: + header = fd.read() + +path = "../source/nordic_sdk" +for root, dirs, files in os.walk(path): + for fn in [os.path.join(root, x) for x in files]: + with open(fn, "r+") as fd: + print "+"*35 + print fn + s = fd.read() + start = s.find("/*") + end = s.find("*/") + copyright_str = s[start:end+2] + if "copyright (c)" not in copyright_str.lower(): + s = header + "\n\n" + s + elif copyright_str is not header: + s = s.replace(copyright_str, header) + + fd.seek(0) + fd.write(s) + fd.truncate()