File: PackageBest.pm

package info (click to toggle)
systeminstaller 1.04-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 748 kB
  • ctags: 261
  • sloc: perl: 5,769; makefile: 70
file content (113 lines) | stat: -rw-r--r-- 3,650 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package SystemInstaller::PackageBest;

#   $Header: /cvsroot/systeminstaller/systeminstaller/lib/SystemInstaller/PackageBest.pm,v 1.4 2002/11/07 20:54:38 mchasal Exp $

#   Copyright (c) 2001 International Business Machines
 
#   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 version 2 of the License, 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
 
#   Michael Chase-Salerno <mchasal@users.sf.net>
#   Sean Dague <sdague@users.sf.net>

use strict;

use Carp;

use vars qw($VERSION @ISA @EXPORT);
use POSIX;

$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);

my @PBMODS=qw(Rpm);

use base qw(Exporter);
@EXPORT = qw(find_files cache_gen);

use SystemInstaller::PackageBest::Rpm;

sub cache_gen {
# Generate/update the cache lists
# Input: dir name, force flag
# Output: boolean success/failure

        my %args = (
                FORCE           => "0",
                CACHEFILE       => ".pkgcache",
                PKGDIR          => "",
                @_,
        );

        foreach my $mod (@PBMODS){
                my $class="SystemInstaller::PackageBest::$mod";
                if ($class->footprint(%args->{PKGDIR})) {
                        return $class->cache_gen(%args->{PKGDIR},%args->{FORCE});
                }
        }
        return 1;

} #cache_gen


sub find_files {
        # Finds the best version of files to use based on an rpm list
        # Input:  a parameter list containing the following:
        #       PKGDIR  The location of the packages
        #       PKGLIST A reference to a list of desired packages
        #   and optionally:
        #       ARCH    The target archtecture, default: current arch
        #       RPMRC   The rpmrc filename, default: /usr/lib/rpm/rpmrc
        #       CACHEFILE The name for the cachefile, default: .pkgcache
        # 
        # Output: A hash whose keys are the package name and whose
        #         values are the filenames.

        my %args = (
                ARCH            => (uname)[4],
                RPMRC           => "/usr/lib/rpm/rpmrc",
                RPMCMD          => "/bin/rpm",
                CACHEFILE       => ".pkgcache",
                FORCE           => 0,
                CACHEONLY       => 0,
                PKGDIR          => "",
                PKGLIST         => [],
                @_,
        );
        # Find a class that footprints
        my $class;
        foreach my $mod (@PBMODS){
                my $tclass="SystemInstaller::PackageBest::$mod";
                if ($tclass->footprint(%args->{PKGDIR})) {
                        $class=$tclass;
                        last;
                }
        }
        unless ($class) { 
                carp("Couldn't find a matching footprint in ". %args->{PKGDIR} . "!");
                return;
        }
        
        # Now do the work

        my $rc=$class->cache_gen(%args);
        unless ($rc) {
                return;
        }
        if (%args->{CACHEONLY}) {
                return $rc;
        }
        return $class->find_files(%args);
}

1;