File: replace_headers.py

package info (click to toggle)
firmware-microbit-micropython 1.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 25,448 kB
  • sloc: ansic: 83,496; cpp: 27,664; python: 2,475; asm: 274; makefile: 245; javascript: 41; sh: 25
file content (23 lines) | stat: -rw-r--r-- 558 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()