-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvrms
executable file
·82 lines (60 loc) · 2.27 KB
/
vrms
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
74
75
76
77
78
79
80
#!/usr/bin/env python3
# If you consider the output of this program to be legal advice,
# you're insane.
import os
import os.path
import sys
from optparse import OptionParser
import pyalpm
# DFSG/OSI-approved licenses, and the various variants in naming them
# I see in my package database
import vrms_arch
import vrms_arch.license_finder
import vrms_arch.unambiguous_db
parser = OptionParser()
parser.add_option("-g", "--global-repos",
dest="use_global_repos",
action="store_true",
default=False,
help="Check licenses in all packages in all synced repositories (but not the AUR!), rather than that of locally installed packages")
parser.add_option("-a", "--list-licenses",
dest="list_all_licenses",
action="store_true",
default=False,
help="List all licenses")
parser.add_option("-u", "--list-unknowns",
dest="list_unknowns",
action="store_true",
default=False,
help="List packages of unknown license instead of non-free packages")
(options, args) = parser.parse_args()
h = pyalpm.Handle("/", "/var/lib/pacman")
dbs_to_visit = []
if(options.use_global_repos):
for d in set(os.path.splitext(f)[0] for f in os.listdir("/var/lib/pacman/sync")):
h.register_syncdb(d, 0)
dbs_to_visit = h.get_syncdbs()
else:
# print("There are %d installed packages." % len(h.get_localdb()))
dbs_to_visit.append(h.get_localdb())
visitor = vrms_arch.license_finder.LicenseFinder()
for db in dbs_to_visit:
# print("Reading pacman DB: %s" % db.name, file=sys.stderr)
db = vrms_arch.unambiguous_db.UnambiguousDb(db)
visitor.visit_db(db)
if options.list_unknowns:
visitor.list_all_unknown_packages()
elif options.list_all_licenses:
visitor.list_all_licenses_as_python()
else:
visitor.list_all_nonfree_packages()
# print out a convenient list of all licenses on the box:
# seen_licenses = []
# for pkg in pkgs:
# for license in pkg.licenses:
# if license not in seen_licenses:
# seen_licenses.append(license)
# seen_licenses.sort()
# for lic in seen_licenses:
# print(" \"%s\"," % lic)
# print("Seen licenses: %s" % seen_licenses)