Debian Codegraph @

packaging/year-tweak

raw
1 #!/usr/bin/env python3
2
3 # This uses the output from "support/git-set-file-times --list" to discern
4 # the last-modified year of each *.c & *.h file and updates the copyright
5 # year if it isn't set right.
6
7 import sys, os, re, argparse, subprocess
8 from datetime import datetime
9
10 def main():
11 latest_year = '2000'
12
13 proc = subprocess.Popen('support/git-set-file-times --list'.split(), stdout=subprocess.PIPE, encoding='utf-8')
14 for line in proc.stdout:
15 m = re.match(r'^\S\s+(?P<year>\d\d\d\d)\S+\s+\S+\s+(?P<fn>.+)', line)
16 if not m:
17 print("Failed to parse line from git-set-file-times:", line)
18 sys.exit(1)
19 m = argparse.Namespace(**m.groupdict())
20 if m.year > latest_year:
21 latest_year = m.year
22 proc.communicate()
23
24 fn = 'latest-year.h'
25 with open(fn, 'r', encoding='utf-8') as fh:
26 old_txt = fh.read()
27
28 txt = f'#define LATEST_YEAR "{latest_year}"\n'
29 if txt != old_txt:
30 print(f"Updating {fn} with year {latest_year}")
31 with open(fn, 'w', encoding='utf-8') as fh:
32 fh.write(txt)
33
34
35 if __name__ == '__main__':
36 parser = argparse.ArgumentParser(description="Grab the year of the last mod for our c & h files and make sure the LATEST_YEAR value is accurate.")
37 args = parser.parse_args()
38 main()
39
40 # vim: sw=4 et