Namazu-devel-ja(旧)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

filter/rpm.pl



RedHat の rpm ファイルをインデックス対象にするようにフィルタを作っ
てみました。rpm -qpi での出力を利用してるので、以下のような出力が
得られます。

| % env LANGUAGE=ja mknmz ~/redhat/SRPMS/
| % env LANGUAGE=ja namazu kakasi .
| 検索結果
| 
| 参考ヒット数:  [ kakasi: 1 ] 
| 
| 検索式にマッチする 1 個の文書が見つかりました。
| 
| 1. KAKASI - kanji kana simple inverter (スコア: 17)
| 著者: (none)
| 日付: Thu Apr 13 23:41:45 2000
| KAKASI は漢字かなまじり文をひらがな文やローマ字文に変換することを目的として作成したプログラムと辞書の総称です。さらに、バージョン2.3.0 からは、分かち書きパッチがマージされました。
| /home/baba/redhat/SRPMS/kakasi-2.3.2-1.src.rpm (1,060,999 bytes)
| 
| 
| 現在のリスト: 1 - 1


使い方にもよるでしょうが、便利な場面もあるのではないかとおもいます。
たぶん同じような感じで、deb ファイルでもできるんじゃないでしょうか。

# なんだかいろいろ遊んでしまっています。
--
馬場  肇 ( Hajime BABA )            E-mail: baba@xxxxxxxxxxxxxxxxxxxxxx
京都大学理学部宇宙物理学教室 博士後期課程
--



#
# -*- Perl -*-
# $Id: rpm.pl,v 1.16 2000/03/23 10:41:04 knok Exp $
# Copyright (C) 2000 Namazu Project All rights reserved ,
#     This is free software with ABSOLUTELY NO WARRANTY.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either versions 2, or (at your option)
#  any later version.
# 
#  This program is distributed in the hope that it will be useful
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#  02111-1307, USA
#
#  This file must be encoded in EUC-JP encoding
#

package rpm;
use strict;
require 'util.pl';
require 'gfilter.pl';

my $rpmpath = undef;

sub mediatype() {
    return ('application/x-rpm');
}

sub status() {
    $rpmpath = util::checkcmd('rpm');
    return 'no' unless (defined $rpmpath);
    return 'yes';
}

sub recursive() {
    return 1;
}

sub pre_codeconv() {
    return 0;
}

sub post_codeconv () {
    return 0;
}

sub add_magic ($) {
    my ($magic) = @_;

    $magic->addFileExts('\\.rpm$', 'application/x-rpm');
    return;
}

sub filter ($$$$$) {
    my ($orig_cfile, $cont, $weighted_str, $headings, $fields)
      = @_;
    my $cfile = defined $orig_cfile ? $$orig_cfile : '';

    my $tmpfile = util::tmpnam('NMZ.rpm');

    util::vprint("Processing rpm file ... (using  '$rpmpath')\n");
    if (util::islang("ja")) {
	system("env LANGUAGE=ja $rpmpath -qpi $cfile > $tmpfile");
    } else {
	system("$rpmpath -qpi $cfile > $tmpfile");
    }

    my $fh = util::efopen("$tmpfile");
    my $size = util::filesize($fh);
    if ($size > $conf::FILE_SIZE_MAX) {
	return 'too_large_rpm_file';
    }
    $$cont = util::readfile($fh);
    undef $fh;
    unlink($tmpfile);

    rpm_filter($cont, $weighted_str, $fields, $headings);

    gfilter::line_adjust_filter($cont);
    gfilter::line_adjust_filter($weighted_str);
    gfilter::white_space_adjust_filter($cont);
#    $fields->{'title'} = gfilter::filename_to_title($cfile, $weighted_str)
#	unless $fields->{'title'};
    gfilter::show_filter_debug_info($cont, $weighted_str,
			   $fields, $headings);

    return undef;
}

sub rpm_filter ($$$$) {
    my ($contref, $weighted_str, $fields, $headings) = @_;

    rpm::get_title($contref, $weighted_str, $fields);
    rpm::get_author($contref, $fields);
    rpm::get_date($contref, $fields);
    rpm::get_size($contref, $fields);
    rpm::get_summary($contref, $fields);

    return;
}


# Below is the sample result of 'rpm -qi rpm'.
#
# Name        : rpm                          Relocations: (not relocateable)
# Version     : 3.0.5                             Vendor: (none)
# Release     : 3k                            Build Date: Fri Jun 30 10:12:19 2000
# Install date: Thu Sep 14 21:32:32 2000      Build Host: omoi.kondara.org
# Group       : System Environment/Base       Source RPM: rpm-3.0.5-3k.nosrc.rpm
# Size        : 3111493                          License: GPL
# URL         : http://www.rpm.org/
# Summary     : The Red Hat package management system.
# Description :
# The RPM Package Manager (RPM) is a powerful command line driven
# package management system capable of installing, uninstalling,
# verifying, querying, and updating software packages.  Each software
# package consists of an archive of files along with information about
# the package like its version, a description, etc.


sub get_title ($$$) {
    my ($contref, $weighted_str, $fields) = @_;

    if ($$contref =~ /Summary     : (.*)/) {
	my $tmp = $1;
	$fields->{'title'} = $tmp;
	my $weight = $conf::Weight{'html'}->{'title'};
	$$weighted_str .= "\x7f$weight\x7f$tmp\x7f/$weight\x7f\n";
    }
}

sub get_author ($$) {
    my ($contref, $fields) = @_;

    if ($$contref =~ /Vendor: (.*)/) {
	my $tmp = $1;
	$fields->{'author'} = $tmp;
    }
}

sub get_date ($$) {
    my ($contref, $fields) = @_;

    if ($$contref =~ /Build Date: (.*)/) {
	my $tmp = $1;
	$fields->{'date'} = $tmp;
    }
}

sub get_size ($$) {
    my ($contref, $fields) = @_;

    if ($$contref =~ /Size\s+: (.*)$/) {
	my $tmp = $1;
	$fields->{'size'} = $tmp;
    }
}

sub get_summary ($$) {
    my ($contref, $fields) = @_;

    $$contref =~ s/^.*Description ://is;
    if ($$contref =~ /Description : (.*)/) {
	my $tmp = $1;
	$fields->{'summary'} = $tmp;
    }
}

1;