File: make-copyright.py

package info (click to toggle)
wims-help 4.01-5
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 18,412 kB
  • sloc: python: 46; sh: 16; makefile: 7
file content (53 lines) | stat: -rw-r--r-- 2,220 bytes parent folder | download
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
#!/usr/bin/python3
import sys, os.path, re
from subprocess import call, PIPE, Popen

copyright="""\
Format: http://dep.debian.net/deps/dep5
Upstream-Name: wims-help
Source: those files are extracted from an installed Wims service, after
        refreshing the modules from the repository WimsEdu. See the file
        "refresh" in the source package.

%s

Files: debian/*
Copyright: 2011 Georges Khaznadar <georgesk@ofset.org>
License: GPL-2+
 This package is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 .
 This package is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 .
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>
 .
 On Debian systems, the complete text of the GNU General
 Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
"""

if __name__=="__main__":
    path=sys.argv[1]
    indexes=Popen("find %s -type f -name INDEX" %path, shell=True, stdout=PIPE).communicate()[0].decode("utf-8")
    indexes=indexes.strip().split("\n")
    files=""
    for i in sorted(indexes):
        d=os.path.dirname(i)
        f=os.path.basename(i)
        author=Popen("sed -n 's/^author=\\(.*\\)/\\1/ p' %s" %i, shell=True, stdout=PIPE).communicate()[0].strip()
        email=Popen("sed -n 's/^address=\\(.*\\)/\\1/ p' %s" %i, shell=True, stdout=PIPE).communicate()[0].strip()
        copy=Popen("sed -n 's/^copyright=\\(.*\\)/\\1/ p' %s" %i, shell=True, stdout=PIPE).communicate()[0].decode("utf-8").strip()
        assert "GNU GPL" in copy
        lic = "GNU Public License version 2\n see '/usr/share/common-licenses/GPL-2'"
        years=" ".join(re.findall("[-0-9]+", copy))
        files+="Files: %s/*\n" %d
        files+="Copyright: %s %s <%s>\n" %(years, author, email)
        files+="License: %s\n\n" %(lic)

    print (copyright %(files))