/usr/lib/python3/dist-packages/pyutilib/dev/replaceCopyright.py is in python3-pyutilib 5.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/usr/bin/env python
#
# A script that replaces copyright statements in files with a
# new copyright statement
#
# replaceCopyright old new file [file...]
#
import sys
import os
def match_head(file,lines):
INPUT=open(file)
i=0
for line in INPUT:
if line.strip() != lines[i].strip():
return False
i=i+1
if i == len(lines):
break
return True
def main():
INPUT = open(sys.argv[1])
old_cr = INPUT.readlines()
INPUT.close()
for i in range(0,len(old_cr)):
old_cr[i] = old_cr[i].strip()
INPUT = open(sys.argv[2])
new_cr = INPUT.readlines()
INPUT.close()
#print old_cr
#print ""
#print new_cr
for file in sys.argv[3:]:
INPUT = open(file)
OUTPUT = open(file+".tmp","w")
i=0
newfile=True
for line in INPUT:
if i == len(old_cr):
#
# Print new copyright
#
for crline in new_cr:
OUTPUT.write(crline)
i=i+1
if i > len(old_cr):
#
# Print lines from the old file
#
OUTPUT.write(line)
else:
#
# Keep checking that the copyright is what is expected
#
if line.strip() == old_cr[i]:
i=i+1
else:
INPUT.close()
if match_head(file,new_cr):
print("File %s is up to date." % file)
else:
print("Unexpected line in file %s\n" % file)
print(" Expected line:\n")
print(old_cr[i]+'\n')
print(" Current line:\n")
print(line)
newfile=False
break
OUTPUT.close()
INPUT.close()
if newfile:
os.remove(file)
os.rename(file+".tmp",file)
print("Updating file %s\n" % file)
if __name__ == '__main__':
main()
|