summaryrefslogtreecommitdiff
path: root/copybump.py
blob: 0b9bdf6b9086a5ca41e4d9203459c09c8c7c1727 (plain)
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
#! /usr/bin/env python3

import os
import re
import datetime


FSF = 'by the Free Software Foundation, Inc.'
this_year = datetime.date.today().year
pyre = re.compile(r'^# Copyright (C) (?P<start>\d{4}-)?(?P<end>\d{4})')


def do_file(path):
    with open(path) as in_file, open(path + '.out', 'w') as out_file:
        for line in in_file:
            mo = pyre.match(line)
            if mo is None:
                out_file.write(line)
                continue
            start = (mo.group('end')
                     if mo.group('start') is None
                     else mo.group('start'))
            print('# Copyright (C) {}-{} {}'.format(
                  mo.group('end'), this_year, FSF), file=out_file)
            for line in in_file:
                out_file.write(line)
    os.rename(path + '.out', path)