From 491886a5c2213ed29c1258b37214fa6d05a130ec Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 1 Aug 2015 20:06:48 +0200 Subject: [PATCH] #2106 - Unify the copyright in source files --- radio/util/copyright-header.txt | 20 +++++++++++++ radio/util/copyright.py | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 radio/util/copyright-header.txt create mode 100755 radio/util/copyright.py diff --git a/radio/util/copyright-header.txt b/radio/util/copyright-header.txt new file mode 100755 index 000000000..84ad4ca2f --- /dev/null +++ b/radio/util/copyright-header.txt @@ -0,0 +1,20 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + diff --git a/radio/util/copyright.py b/radio/util/copyright.py new file mode 100755 index 000000000..9a12c285d --- /dev/null +++ b/radio/util/copyright.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import os +import re +import sys + +def writeheader(filename,header): + """ + write a header to filename, + skip files where first line after optional shebang matches the skip regex + filename should be the name of the file to write to + header should be a list of strings + skip should be a regex + """ + f = open(filename,"r") + inpt =f.readlines() + f.close() + output = [] + + #comment out the next 3 lines if you don't wish to preserve shebangs + if len(inpt) > 0 and inpt[0].startswith("#!"): + output.append(inpt[0]) + inpt = inpt[1:] + + if inpt[0].strip().startswith("/*"): + for i, line in enumerate(inpt): + if line.strip().endswith("*/"): + inpt = inpt[i+1:] + break + + while not inpt[0].strip(): + inpt = inpt[1:] + + output.extend(header) #add the header + for line in inpt: + output.append(line) + try: + f = open(filename,'w') + f.writelines(output) + f.close() + print "added header to %s" %filename + except IOError,err: + print "something went wrong trying to add header to %s: %s" % (filename,err) + +def main(args=sys.argv): + headerfile = open(args[1]) + header = headerfile.readlines() + headerfile.close() + writeheader(args[2], header) + +#call the main method +main()