-
Notifications
You must be signed in to change notification settings - Fork 5
/
hackage-reverse-lookup
executable file
·47 lines (37 loc) · 1.29 KB
/
hackage-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
#!/usr/bin/ruby
require 'concurrent'
require 'http'
require 'pycall/import'
require 'set'
include PyCall::Import
pyimport :pyalpm
pkg = ARGV[0]
name_preset = HTTP.follow.get("https://github.com/berberman/arch-hs/raw/master/data/NAME_PRESET.json").parse(:json)
archpkg = name_preset.key(pkg) || "haskell-#{pkg}"
handle = pyalpm.Handle.new(".", "/var/lib/pacman")
rdeps = Set[]
["extra"].each { |db|
db_handle = handle.register_syncdb(db, 0)
db_handle.search("").each { |package|
["depends", "makedepends", "checkdepends"].each { |field|
rdeps << [package.name, package.version.split("-")[0]] if package.send(field).include? archpkg
}
}
}
pool = Concurrent::FixedThreadPool.new(Concurrent.processor_count)
lock = Mutex.new
rdeps.each { |rdep, ver|
pool.post {
hackage_name = name_preset[rdep] || rdep[8..-1]
cabal = HTTP.get("https://hackage.haskell.org/package/#{hackage_name}-#{ver}/revision/0.cabal")
puts "Failed to fetch #{hackage_name}-#{ver}, ignoring..." or next if !cabal.status.success?
lock.synchronize {
puts "Extracting #{rdep}..."
cabal.to_s.each_line { |line|
puts line if line =~ /[^\w\/\-`]#{pkg}[^\w\/\-`]/
}
}
}
}
pool.shutdown
pool.wait_for_termination