github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/contrib/scripts/license.py (about) 1 #!/usr/bin/python 2 3 import sys 4 5 notice = """ 6 /* 7 * Copyright 2018 Dgraph Labs, Inc. and Contributors 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 """ 22 23 def addCopyright(file): 24 print("Add copyright to", file) 25 f = open(file, "r+") 26 lines = f.readlines() 27 lines.insert(0, notice) 28 f.seek(0) 29 for l in lines: 30 f.write(l) 31 f.close() 32 33 def update(file): 34 f = open(file, "r") 35 lines = f.readlines() 36 f.close() 37 38 found = False 39 for idx, l in enumerate(lines): 40 if "Copyright" in l and "Dgraph" in l: 41 start = idx - 1 42 found = True 43 break 44 45 if not found: 46 addCopyright(file) 47 return 48 49 for idx, l in enumerate(lines[start:]): 50 if "*/" in l: 51 end = start + idx 52 break 53 54 if end == 0: 55 print "ERROR: Couldn't find copyright:", file 56 return 57 58 updated = lines[:start] 59 updated.extend(lines[end+1:]) 60 updated.insert(start, notice) 61 f = open(file, "w") 62 for l in updated: 63 f.write(l) 64 f.close() 65 66 if len(sys.argv) == 0: 67 sys.exit(0) 68 69 update(sys.argv[1])