aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-09-17 21:25:43 -0500
committerJack Nagel2013-09-17 21:29:55 -0500
commitbc1aea3f97a156df9e678cc06446fd6964422162 (patch)
tree68ce1dba97ba3c146f9342cf00bffa5c4038fcdc /Library
parent50d2f632d9157c953dcbaeb33c5b79ef50fee38a (diff)
downloadbrew-bc1aea3f97a156df9e678cc06446fd6964422162.tar.bz2
Convert brew-aspell-dictionaries to Ruby and output resources
This makes the script much more readable, and also allows us to download the language packs into the cache where they can be used when installing aspell.
Diffstat (limited to 'Library')
-rwxr-xr-xLibrary/Contributions/cmd/brew-aspell-dictionaries53
-rwxr-xr-xLibrary/Contributions/cmd/brew-aspell-dictionaries.rb36
2 files changed, 36 insertions, 53 deletions
diff --git a/Library/Contributions/cmd/brew-aspell-dictionaries b/Library/Contributions/cmd/brew-aspell-dictionaries
deleted file mode 100755
index 86ce14904..000000000
--- a/Library/Contributions/cmd/brew-aspell-dictionaries
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/bin/sh
-#
-# brew-aspell-dictionaries - update aspell formula to include latest dictionaries
-# This script fetches the current index for the aspell dictionaries gnu server,
-# it parses the html to retrieve the URL to the dictionary archive for each
-# available language.
-# The script then calculates the sha1 for each dictionary archive and
-# generates a brew formula for each language.
-# The result can then to be merged into the aspell formula, to update
-# the available dictionary formulae.
-
-dictionaries_url=http://ftpmirror.gnu.org/aspell/dict
-dictionaries_mirror=http://ftp.gnu.org/gnu/aspell/dict
-tmp_file=`mktemp -t brew_aspell_dictionaries`
-brew_formulae_tmp_file=`mktemp -t brew_aspell_dictionaries_formulae`
-
-echo "Downloading aspell dictionaries Index"
-curl -sL ${dictionaries_url}/0index.html \
- | egrep '^(<tr><td><a|</table)' \
- | cut -d\" -f2,4 \
- > $tmp_file
-
-echo "# BEGIN generated with `basename $0`" > $brew_formulae_tmp_file
-langs=""
-for dict in `cat $tmp_file`; do
- [ "${dict}" = "</table>" ] && break # only read the entries in the first table, which lists the dictionaries for aspell 0.60
- lang=`echo $dict | awk -F\" '{ gsub("-", "_", $1); print $1 }'`
- url="${dictionaries_url}/"`echo $dict | awk -F\" '{ print $2 }'`
- mirror="${dictionaries_mirror}/"`echo $dict | awk -F\" '{ print $2 }'`
- langs="${langs} ${lang}"
- echo "Calculating sha1 for formula: ${lang}"
- sha1=`curl -sL "${url}" | shasum | awk '{print $1}'`
- cat <<EOF >> $brew_formulae_tmp_file
-class Aspell_${lang} < AspellLang
- url '${url}'
- mirror '${mirror}'
- sha1 '${sha1}'
-end
-EOF
-done
-
-cat <<EOF >> $brew_formulae_tmp_file
-class Aspell < Formula
- def self.available_languages
- %w(${langs})
- end
-end
-# END generated with `basename $0`
-EOF
-
-rm $tmp_file
-
-echo "The formulae for the aspell dictionaries have been written to\n$brew_formulae_tmp_file"
diff --git a/Library/Contributions/cmd/brew-aspell-dictionaries.rb b/Library/Contributions/cmd/brew-aspell-dictionaries.rb
new file mode 100755
index 000000000..4816f7239
--- /dev/null
+++ b/Library/Contributions/cmd/brew-aspell-dictionaries.rb
@@ -0,0 +1,36 @@
+require 'open-uri'
+require 'resource'
+require 'formula'
+
+dict_url = "http://ftpmirror.gnu.org/aspell/dict"
+dict_mirror = "http://ftp.gnu.org/gnu/aspell/dict"
+
+resources = {}
+
+open("#{dict_url}/0index.html") do |content|
+ content.each_line do |line|
+ break if %r{^</table} === line
+ next unless /^<tr><td><a/ === line
+
+ fields = line.split('"')
+ lang, path = fields[1], fields[3]
+ lang.gsub!("-", "_")
+ resources[lang] = path
+ end
+end
+
+resources.each_pair do |lang, path|
+ r = Resource.new(lang, "#{dict_url}/#{path}")
+ r.owner = Formula.factory('aspell')
+
+ nostdout { r.fetch }
+
+ puts <<-EOS
+ resource '#{lang}' do
+ url '#{dict_url}/#{path}'
+ mirror '#{dict_mirror}/#{path}'
+ sha1 '#{r.cached_download.sha1}'
+ end
+
+EOS
+end