Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nrf51-sdk by
script/replace_headers.py@0:bc2961fa1ef0, 2016-04-06 (annotated)
- Committer:
- Jonathan Austin
- Date:
- Wed Apr 06 23:55:04 2016 +0100
- Revision:
- 0:bc2961fa1ef0
Synchronized with git rev 90647e3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
0:bc2961fa1ef0 | 1 | import os |
Jonathan Austin |
0:bc2961fa1ef0 | 2 | |
Jonathan Austin |
0:bc2961fa1ef0 | 3 | with open("copyright_header.txt", "r") as fd: |
Jonathan Austin |
0:bc2961fa1ef0 | 4 | header = fd.read() |
Jonathan Austin |
0:bc2961fa1ef0 | 5 | |
Jonathan Austin |
0:bc2961fa1ef0 | 6 | path = "../source/nordic_sdk" |
Jonathan Austin |
0:bc2961fa1ef0 | 7 | for root, dirs, files in os.walk(path): |
Jonathan Austin |
0:bc2961fa1ef0 | 8 | for fn in [os.path.join(root, x) for x in files]: |
Jonathan Austin |
0:bc2961fa1ef0 | 9 | with open(fn, "r+") as fd: |
Jonathan Austin |
0:bc2961fa1ef0 | 10 | print "+"*35 |
Jonathan Austin |
0:bc2961fa1ef0 | 11 | print fn |
Jonathan Austin |
0:bc2961fa1ef0 | 12 | s = fd.read() |
Jonathan Austin |
0:bc2961fa1ef0 | 13 | start = s.find("/*") |
Jonathan Austin |
0:bc2961fa1ef0 | 14 | end = s.find("*/") |
Jonathan Austin |
0:bc2961fa1ef0 | 15 | copyright_str = s[start:end+2] |
Jonathan Austin |
0:bc2961fa1ef0 | 16 | if "copyright (c)" not in copyright_str.lower(): |
Jonathan Austin |
0:bc2961fa1ef0 | 17 | s = header + "\n\n" + s |
Jonathan Austin |
0:bc2961fa1ef0 | 18 | elif copyright_str is not header: |
Jonathan Austin |
0:bc2961fa1ef0 | 19 | s = s.replace(copyright_str, header) |
Jonathan Austin |
0:bc2961fa1ef0 | 20 | |
Jonathan Austin |
0:bc2961fa1ef0 | 21 | fd.seek(0) |
Jonathan Austin |
0:bc2961fa1ef0 | 22 | fd.write(s) |
Jonathan Austin |
0:bc2961fa1ef0 | 23 | fd.truncate() |