-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibraries.py
More file actions
70 lines (62 loc) · 1.95 KB
/
libraries.py
File metadata and controls
70 lines (62 loc) · 1.95 KB
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
import json
import os
import stat
import subprocess
devnull = open(os.devnull, "w")
system_packages = dict()
command = "dpkg --get-selections | awk '{print $1}' | xargs dpkg-query --show $1"
commands = ["/bin/bash", "-c", command]
for line in subprocess.check_output(commands, stderr=devnull).decode().split("\n")[:-1]:
lib, version = [t for t in line.split() if t]
system_packages[lib] = version
python_modules = dict()
for line in (
subprocess.check_output(["/usr/local/bin/pip", "freeze"], stderr=devnull)
.decode()
.split("\n")[:-1]
):
lib, version = line.split("==")
python_modules[lib] = version
c_libs = dict()
lines = filter(
lambda line: line.startswith("\t"),
subprocess.check_output(["/sbin/ldconfig", "-vN"], stderr=devnull)
.decode()
.split("\n"),
)
for line in lines:
lib, version = line.split()[2].split(".so")
version = "?" if not version else version[1:]
c_libs[lib] = version
perl_modules = dict()
commands = ["/bin/bash", "-c", "yes | /usr/bin/cpan -l"]
subprocess.check_output(commands, stderr=devnull)
for line in (
subprocess.check_output(["/usr/bin/cpan", "-l"], stderr=devnull)
.decode()
.split("\n")[1:-1]
):
lib, version = line.split("\t")
if version == "undef":
version = "?"
perl_modules[lib] = version
bins = []
executable = stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
for path in os.environ["PATH"].split(":"):
for name in os.listdir(path):
file_path = os.path.join(path, name)
if os.path.isfile(file_path) and os.stat(file_path).st_mode & executable:
bins.append(name)
print(
json.dumps(
{
"libraries": {
"system": dict(sorted(system_packages.items())),
"python": dict(sorted(python_modules.items())),
"perl": dict(sorted(perl_modules.items())),
"c": dict(sorted(c_libs.items())),
},
"bin": sorted(bins),
}
)
)