1ba8c7b3ac90362000306722a0d392dbc6a66dce
[external/busybox.git] / util-linux / debian / scripts / check-links.py
1 #!/usr/bin/python
2 #
3 # Check that the binaries for links BusyBox outputs and the ones
4 # in the packages *.links files match.
5 #
6 # Copyright (C) 2008 by Nokia Corporation
7 #
8 # Contact: Eero Tamminen <eero.tamminen@nokia.com>
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # version 2 as published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 # 02110-1301 USA
23
24 import os, sys
25
26 def add_links_from(filename, olditems):
27     "read busybox.links file and return a list of binary names"
28     newitems = {}
29     existing = []
30     print "-", filename
31     for line in open(filename):
32         line = line.strip()
33         if not line:
34             continue
35         name = os.path.basename(line.split()[-1])
36         if name in olditems and name not in newitems:
37             # same package may symlink same name to different
38             # places, but other packages may not
39             existing.append(name)
40         else:
41             olditems[name] = filename
42             newitems[name] = 1
43     
44     if existing:
45         print "ERROR: following items were already in (some) previous links file:"
46         for name in existing:
47             print "-", name
48         print "Re-run of create-control.py needed?"
49         sys.exit(1)
50
51
52 def process_args(argv):
53     links = {}
54     bblinks = {}
55     print "Checking:"
56     add_links_from(argv[1], bblinks)
57     for filename in argv[2:]:
58         add_links_from(filename, links)
59     
60     missing = []
61     for link in bblinks.keys():
62         if link in links:
63             del(links[link])
64         else:
65             missing.append(link)
66     
67     if missing:
68         print "WARNING: links files for packages are missing following BB links:"
69         for link in missing:
70             print "-", link
71         print "Are all these installed as alternatives?"
72     
73     if links:
74         print "ERROR: BB links file doesn't contain following packages links:"
75         for link in links.keys():
76             print "- %s (in '%s')" % (link, links[link])
77         print "Re-run of create-control.py needed?"
78         sys.exit(1)
79
80
81 if __name__ == "__main__":
82     if len(sys.argv) > 2:
83         process_args(sys.argv)
84     else:
85         print """
86 Script to check that binary names in packages link files
87 match the list of binary names in the BB link file.
88
89 usage: %s <BB links file> <packages link files>
90 """ % os.path.basename(sys.argv[0])
91         sys.exit(1)
92