Skip to content

Instantly share code, notes, and snippets.

@Voker57
Created June 23, 2009 20:26
Show Gist options
  • Save Voker57/134818 to your computer and use it in GitHub Desktop.
Save Voker57/134818 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Hackage [http://hackage.haskell.org] documentation downloader
# Fetches documentation for installed only (or all available) Cabal packages in current directory
# Use --all to download docs for all packages
# Requires wget and cabal to be installed
# by Voker57 <voker57@gmail.com>
#
# Public domain
require 'fileutils'
installed = (ARGV.include? "--all") ? "" : "--installed"
packages = `cabal list #{installed} --simple-output`.split($/).map{|v| v.split(/\s+/)}
packages.each do |pk|
print "Fetching docs for #{pk[0]}, version #{pk[1]}..."
STDOUT.flush
dir = "#{pk[0]}/#{pk[1]}"
if File.exists? dir
puts "skipped."
else
FileUtils.mkdir_p dir
`wget -c --mirror -np -k -nH --cut-dirs=6 -A html,png,gif,css,js -a log.txt -P #{dir} http://hackage.haskell.org/packages/archive/#{pk[0]}/#{pk[1]}/doc/html/`
if $?.exitstatus == 0
puts "done."
File.delete "log.txt"
else
puts "error #{$?.exitstatus}, see log.txt for details"
FileUtils.rm_r dir if File.exists? dir
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment