2 # Convert Debtags vocabulary.gz files into Sleepycat db files
4 # Copyright (C) 2006 Frank Lichtenheld <djpig@debian.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 use Packages::Template;
34 use Packages::Config qw( $TOPDIR @LANGUAGES );
35 use Packages::I18N::Locale;
36 &Packages::Config::init( './' );
37 my $debtagsdir = "$TOPDIR/files/debtags";
38 my $wwwdir = "$TOPDIR/www/about";
39 my $voc_file = "$debtagsdir/vocabulary";
48 $desc = encode_entities($desc);
50 $desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
52 $desc =~ s/\n /\n/sgo;
53 $desc =~ s/\n.\n/\n<p>\n/go;
54 $desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
59 print "Parsing Vocabulary...\n";
60 tie %voc_db, "DB_File", "$debtagsdir/vocabulary.db.new",
61 O_RDWR|O_CREAT, 0666, $DB_BTREE
62 or die "Error creating DB: $!";
63 open VOC, '<', $voc_file or die "Error opening vocabulary: $!";
71 while (/^(\S+):\s*(.*)\s*$/mg) {
72 my ($key, $value) = ($1, $2);
73 $value =~ s/\377/\n /g;
74 $key =~ tr [A-Z] [a-z];
77 my $voc_key = $data{facet} || $data{tag};
79 warn "No key found in ".Dumper(\%data);
83 warn "Duplicated key found: $voc_key\n";
86 my ($sdesc,$ldesc) = split /\n/, $data{description}, 2;
88 $data{html_description} = [ encode_entities($sdesc), process_desc($ldesc)||"" ];
89 $voc_db{$voc_key} = $sdesc || "";
91 foreach my $lang (@LANGUAGES) {
92 next if $lang eq 'en';
94 my $cat = Packages::I18N::Locale->get_handle($lang)
95 or die "get_handle failed for $lang";
97 my $sdesc_trans = $cat->maketext($sdesc);
98 $voc_db{"$voc_key-$lang"} = $sdesc_trans
99 if $sdesc_trans and $sdesc_trans ne $sdesc;
102 $voc{$voc_key} = \%data;
105 close VOC or warn "Couldn't close vocabulary: $!";
107 #print Dumper(\%voc,\%voc_db);
109 print "Creating tag list...\n";
111 -d $wwwdir || mkpath( $wwwdir );
112 open TAGLST, '>', "$wwwdir/debtags.en.html.new"
113 or die "Error creating tag list: $!";
115 my $template = new Packages::Template( "$TOPDIR/templates", 'html', {} );
116 my @facets = sort( grep { exists $voc{$_}{facet} } keys %voc );
117 my @tags = sort( grep { exists $voc{$_}{tag} } keys %voc );
120 my ($facet, $tag) = split m/::/, $_, 2;
121 warn "No facet data available for $facet\n"
122 unless exists $voc{$facet};
123 $tags_by_facet{$facet} ||= [];
124 push @{$tags_by_facet{$facet}}, $_;
126 my %content = ( vocabulary => \%voc,
127 facets => \@facets, tags => \@tags,
128 tags_by_facet => \%tags_by_facet,
129 used_langs => [ 'en' ]);
130 print TAGLST $template->page( 'tag_index', \%content );
131 close TAGLST or warn "Couldn't close tag list: $!";
133 rename( "$wwwdir/debtags.en.html.new",
134 "$wwwdir/debtags.en.html" );
137 rename( "$debtagsdir/vocabulary.db.new",
138 "$debtagsdir/vocabulary.db" );