-
Notifications
You must be signed in to change notification settings - Fork 5
/
python-reverse-lookup
executable file
·71 lines (58 loc) · 2.2 KB
/
python-reverse-lookup
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
#!/usr/bin/ruby
"""
Usage: $0 pypi_package [repository]
"""
require 'concurrent'
$pkg = ARGV[0].downcase
$repos = ARGV[1] || "all"
$repos = $repos == "all" ? ["core", "extra", "multilib", "core-testing", "extra-testing", "multilib-testing"] : $repos.split(",")
CACHEDIR = "#{Dir.home}/.cache/python-reverse-lookup"
Dir.mkdir(CACHEDIR) unless Dir.exist?(CACHEDIR)
POOL = Concurrent::FixedThreadPool.new(Concurrent.processor_count)
PACMAN_LOCK = Mutex.new
def parse_metadata(pattern)
`pacman -Fx #{pattern}`.split(/\n/).each do |line|
case line.split
in [file, "is", "owned", "by", package, version]
repo, package = package.split("/")
next unless $repos.include?(repo)
POOL.post do
cachefile = "#{CACHEDIR}/" + "#{package}-#{version}-#{file}".gsub("/", "_")
unless File.exist?(cachefile)
path = "/var/cache/pacman/pkg/#{package}-#{version}-*.pkg.tar.zst"
if ! File.exist? path
PACMAN_LOCK.synchronize do
out = `sudo pacman -Sw --noconfirm #{repo}/#{package} 2>&1`
puts out unless $?.success?
end
end
content = `bsdtar xOf #{path} #{file}`
File.write(cachefile, content) if $?.success?
end
File.readlines(cachefile).each do |line|
yield [repo, package].join("/"), line
end if File.exist?(cachefile)
end
end
end
end
parse_metadata("/usr/lib/python3\\.[0-9]+/site-packages/.*\\.dist-info/METADATA") do |package, line|
if line.downcase.start_with? /requires-dist: #{$pkg}[^\w]/
puts "#{package}: #{line}"
end
end
$last_package = nil
parse_metadata("/usr/lib/python3\\.[0-9]+/site-packages/.*\\.egg-info/requires.txt") do |package, line|
if package != $last_package
$extra = ""
$last_package = package
end
if line.match /\[.+\]/
$extra = " #{line.chomp}"
end
if line.downcase.start_with? /#{$pkg}[^\w]/
puts "#{package}: #{line.chomp}#{$extra}"
end
end
POOL.shutdown
POOL.wait_for_termination