Author: glen Date: Mon Apr 28 21:12:43 2008 GMT Module: SOURCES Tag: HEAD ---- Log message: - parse opera language page and create template for spec
---- Files affected: SOURCES: opera-i18n.pl (NONE -> 1.1) (NEW) ---- Diffs: ================================================================ Index: SOURCES/opera-i18n.pl diff -u /dev/null SOURCES/opera-i18n.pl:1.1 --- /dev/null Mon Apr 28 23:12:43 2008 +++ SOURCES/opera-i18n.pl Mon Apr 28 23:12:37 2008 @@ -0,0 +1,67 @@ +#! /usr/bin/perl -w +use strict; +use HTML::TreeBuilder; +use LWP::UserAgent; +use URI::URL; +use Encode; + +use constant URL => 'http://www.opera.com/download/languagefiles/?platform=linux&lng=9'; + +$| = 1; + +my $ua = new LWP::UserAgent; +my $res = $ua->get(URL); +die "Get URL failed: ", $res->status_line, "\n" unless $res->is_success; + +my $root = new HTML::TreeBuilder; +my $content = $res->content; +#my $content = decode('utf8', $res->content); +$root->parse($content); + +# HTML::Element +my $table = $root->look_down('_tag' => 'table', 'class' => 'grid'); +die unless defined $table; + +# (p)arse +my @lang; +my $i = 0; +for my $tr ($table->find('tr')) { + my @th = $tr->find('td') or next; + my $lang = $th[0]->as_text; + my $v; + for (reverse @th) { + $v = $_,last if $_->as_text; + } + my $url = new URI::URL($v->find('a')->attr('href'), URL); + my ($lc) = ($url =~ /_(\S+).lng/); + # skip english. duplicate and in main pkg + next if $lc eq 'en'; + $lc = 'es' if $lc eq 'es-ES'; + + # glibc locale name + (my $l = $lc) =~ s/-(\S+)/'_'.uc $1/e; + + # collect it + push(@lang, [ $i++, $url->abs, $lc, $lang, $v->as_text, $l ]); +} + +# output +# print preamble +for (@lang) { + my ($i, $url) = @$_[0,1]; + printf "Source%d:\t%s\n", $i, $url; + printf "# Source%d-md5: -\n", $i; +} + +print "\n\n%install\n"; +for (@lang) { + my ($i, $lc, $lang, $ver) = @$_[0,2,3,4]; + printf "# %s (%s)\n", $lang, $ver; + printf "install %%{SOURCE%d} \$RPM_BUILD_ROOT%%{_datadir}/opera/locale/%s.lng\n", $i, $lc; +} + +print "\n\n%files\n"; +for (@lang) { + my ($i, $lc, $l) = @$_[0,2,5]; + printf "%%lang(%s) %%{_datadir}/opera/locale/%s.lng\n", $l, $lc; +} ================================================================ _______________________________________________ pld-cvs-commit mailing list [email protected] http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit
