summaryrefslogtreecommitdiff
path: root/scripts/packages-formatter.py
blob: 1432cdaebec7eac3c777de49056729669dc9dc17 (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
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
#!/usr/bin/env python
"""\
This module formats the package version and copyright information for the
viewer and its dependent packages.

$LicenseInfo:firstyear=2014&license=viewerlgpl$
Second Life Viewer Source Code
Copyright (C) 2014, Linden Research, Inc.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2.1 of the License only.

This library 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
$/LicenseInfo$
"""
import os
import sys
import re
import subprocess

autobuild=os.getenv('AUTOBUILD',
                    'autobuild' if not ( sys.platform == 'win32' or sys.platform == 'cygwin')
                    else 'autobuild.cmd')

pkg_line=re.compile('^([\w-]+):\s+(.*)$')

version={}
versions=subprocess.Popen([autobuild, 'install', '--versions'],
                            stdin=None, stdout=subprocess.PIPE, universal_newlines=True).stdout
for line in versions:
    pkg_info = pkg_line.match(line)
    if pkg_info:
        pkg = pkg_info.group(1)
        if pkg not in version:
            version[pkg] = pkg_info.group(2).strip()
        else:
            sys.exit("Duplicate version for %s" % pkg)
    else:
        sys.exit("Unrecognized --versions output: %s" % line)

copyright={}
copyrights=subprocess.Popen([autobuild, 'install', '--copyrights'],
                            stdin=None, stdout=subprocess.PIPE, universal_newlines=True).stdout
viewer_copyright = copyrights.readline() # first line is the copyright for the viewer itself
for line in copyrights:
    pkg_info = pkg_line.match(line)
    if pkg_info:
        pkg = pkg_info.group(1)
        if pkg not in copyright:
            copyright[pkg] = pkg_info.group(2).strip()
        else:
            sys.exit("Duplicate copyright for %s" % pkg)
    else:
        sys.exit("Unrecognized --copyrights output: %s" % line)

print viewer_copyright
for pkg in sorted(version):
    print ': '.join([pkg, version[pkg]])
    if pkg in copyright:
        print copyright[pkg]
    else:
        sys.exit("No copyright for %s" % pkg)