pf-tools commit: r694 [ccaillet-guest] - in /trunk: debian/changelog lib/PFTools/Conf.pm lib/PFTools/Packages.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Fri Feb 6 16:23:21 UTC 2009
Author: ccaillet-guest
Date: Fri Feb 6 16:23:21 2009
New Revision: 694
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=694
Log:
Introducing an abstraction layer for packages : Packages.pm. Need to
integrate those functions into Update.pm
Added:
trunk/lib/PFTools/Packages.pm (with props)
Modified:
trunk/debian/changelog
trunk/lib/PFTools/Conf.pm
Modified: trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/trunk/debian/changelog?rev=694&op=diff
==============================================================================
--- trunk/debian/changelog (original)
+++ trunk/debian/changelog Fri Feb 6 16:23:21 2009
@@ -26,8 +26,10 @@
* use strict in Update.pm
* Better regexp for HOSTNAME in Conf.pm which permits number into the
HOSTTYPE part
-
- -- Christophe Caillet <tof at sitadelle.com> Tue, 02 Dec 2008 15:48:30 +0100
+ * Introducing an abstraction layer for packages : Packages.pm. Need to
+ integrate those functions into Update.pm
+
+ -- Christophe Caillet <quadchris at free.fr> Fri, 06 Feb 2009 17:20:22 +0100
pf-tools (0.33.1-1) unstable; urgency=low
Modified: trunk/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/trunk/lib/PFTools/Conf.pm?rev=694&op=diff
==============================================================================
--- trunk/lib/PFTools/Conf.pm (original)
+++ trunk/lib/PFTools/Conf.pm Fri Feb 6 16:23:21 2009
@@ -30,6 +30,8 @@
our @ISA = ('Exporter');
our @EXPORT = qw(
+ $ERR_OPEN
+ $ERR_SYNTAX
$PFTOOLS_VARS
$DEFERREDLOG
%SUBST
@@ -50,8 +52,9 @@
our @EXPORT_OK = qw();
# Error code
-my $ERR_OPEN = 1;
-my $ERR_SYNTAX = 2;
+our $ERR_OPEN = 1;
+our $ERR_SYNTAX = 2;
+
my $DEBUG = 0 ;
# Vars needed by pf-launch
Added: trunk/lib/PFTools/Packages.pm
URL: http://svn.debian.org/wsvn/pf-tools/trunk/lib/PFTools/Packages.pm?rev=694&op=file
==============================================================================
--- trunk/lib/PFTools/Packages.pm (added)
+++ trunk/lib/PFTools/Packages.pm Fri Feb 6 16:23:21 2009
@@ -1,0 +1,257 @@
+package PFTools::Packages;
+##
+## $Id$
+##
+## Copyright (C) 2009 Christophe Caillet <quadchris at free.fr>
+##
+## 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+##
+
+use strict;
+use warnings;
+
+
+use Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+ Cmp_pkg_version
+ Get_pkg_depends
+ Get_pkg_policy
+ Get_pkg_status
+ Install_pkg
+ Purge_pkg
+ Update_pkg_repository
+);
+
+our @EXPORT_OK = qw();
+
+use PFTools::Conf;
+
+my $PKG_CMD = {} ;
+$PKG_CMD->{'deb'}->{'status'} = 'LANG=C LC_ALL=C /usr/bin/dpkg -s' ;
+$PKG_CMD->{'deb'}->{'update'} = 'LANG=C LC_ALL=C /usr/bin/apt-get -y --force-yes update' ;
+$PKG_CMD->{'deb'}->{'depends'} = 'LANG=C LC_ALL=C /usr/bin/apt-cache show' ;
+$PKG_CMD->{'deb'}->{'install'} = 'LANG=C LC_ALL=C /usr/bin/apt-get -y --force-yes install' ;
+$PKG_CMD->{'deb'}->{'purge'} = 'LANG=C LC_ALL=C /usr/bin/dpkg --purge' ;
+$PKG_CMD->{'deb'}->{'policy'} = 'LANG=C LC_ALL=C /usr/bin/apt-cache policy' ;
+$PKG_CMD->{'deb'}->{'compare'} = 'LANG=C LC_ALL=C /usr/bin/dpkg --compare-versions' ;
+$PKG_CMD->{'rpm'} = 'TODO' ;
+
+sub Get_pkg_status ($$) {
+ my ( $pkg_type, $pkg_name ) = @_ ;
+
+ my $result = {} ;
+ if ( ! defined $PKG_CMD->{$pkg_type} ) {
+ Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'rpm' ) {
+ #TODO
+ Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'deb' ) {
+ unless ( open ( PKG, $PKG_CMD->{$pkg_type}->{'status'}.' '.$pkg_name.' 2>/dev/null |' ) ) {
+ Warn ( $ERR_OPEN, "Unable to retrieve status for package ".$pkg_name ) ;
+ return undef ;
+ }
+ while ( <PKG>) {
+ if ( /^Status:\s+/ ) {
+ if ( !/^Status:\s+install\s+ok\s+installed\s*$/ ) {
+ $result->{'installed'} = 0 ;
+ }
+ else {
+ $result->{'installed'} = 1 ;
+ }
+ }
+ if ( /^Version:\s+(.+)\s*$/ ) {
+ $result->{'version'} = $1 ;
+ last ;
+ }
+ }
+ close ( PKG ) ;
+ }
+ return $result ;
+}
+
+sub Update_pkg_repository ($) {
+ my ( $pkg_type ) = @_ ;
+
+ if ( ! defined $PKG_CMD->{$pkg_type} ) {
+ Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) ;
+ return 0 ;
+ }
+ elsif ( $pkg_type eq 'rpm' ) {
+ #TODO
+ Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) ;
+ return 0 ;
+ }
+ elsif ( $pkg_type eq 'deb' ) {
+ if ( deferredlogsystem( $PKG_CMD->{$pkg_type}->{'update'} ) ) {
+ Warn( $ERR_OPEN, "Updating repository failed !" ) ;
+ return 0 ;
+ }
+ }
+ return 1 ;
+}
+
+sub Purge_pkg ($$) {
+ my ( $pkg_type, $pkg_name ) = @_ ;
+
+ if ( ! defined $PKG_CMD->{$pkg_type} ) {
+ Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) ;
+ return 0 ;
+ }
+ elsif ( $pkg_type eq 'rpm' ) {
+ #TODO
+ Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) ;
+ return 0 ;
+ }
+ elsif ( $pkg_type eq 'deb' ) {
+ if ( deferredlogsystem ( $PKG_CMD->{$pkg_type}->{'purge'}." '".$pkg_name."'" ) ) {
+ Warn( $ERR_OPEN, "Purge du package ".$pkg_name." impossible" ) ;
+ return 0 ;
+ }
+ }
+ return 1 ;
+}
+
+sub Get_pkg_depends ($$) {
+ my ( $pkg_type, $pkg_name ) = @_ ;
+ my $dep_list ;
+
+ if ( ! defined $PKG_CMD->{$pkg_type} ) {
+ Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'rpm' ) {
+ #TODO
+ Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'deb' ) {
+ unless ( open( APTDEP, $PKG_CMD->{$pkg_type}->{'depends'}.' '.$pkg_name.' 2>/dev/null |' ) ) {
+ Warn ( $ERR_OPEN, "Unable to get depends for package ".$pkg_name ) ;
+ return undef ;
+ }
+ while (<APTDEP>) {
+ if (m/^Depends: (.*)$/) {
+ foreach my $pkg ( split ( /,/, $1 ) ) {
+ if ( $pkg =~ /|/ ) {
+ $pkg =~ s/\([^\)]+\)//g ;
+ $pkg =~ s/\s+//g ;
+ foreach my $possible_pkg ( split ( /\|/, $pkg ) ) {
+ if ( $possible_pkg ne $pkg_name ) {
+ $dep_list .= " ".$possible_pkg ;
+ }
+ }
+ }
+ elsif ( $pkg ne $pkg_name ) {
+ $dep_list .= " ".$pkg ;
+ }
+ }
+ }
+ }
+ close ( APTDEP ) ;
+ }
+ $dep_list =~ s/^\s*// ;
+ return $dep_list ;
+}
+
+sub Get_pkg_policy ($$) {
+ my ( $pkg_type, $pkg_name ) = @_ ;
+ my ( $installed, $available ) ;
+
+ if ( ! defined $PKG_CMD->{$pkg_type} ) {
+ Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'rpm' ) {
+ #TODO
+ Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'deb' ) {
+ unless ( open( APTPOLICY, $PKG_CMD->{$pkg_type}->{'policy'}.' '.$pkg_name.' 2>/dev/null |' ) ) {
+ Warn ( $ERR_OPEN, "Unable to get policy for package ".$pkg_name ) ;
+ return undef ;
+ }
+ while ( <APTPOLICY> ) {
+ if (m/^ Installed: (.*)$/) {
+ $installed = $1;
+ undef $installed if ( $installed eq '' || $installed eq '(none)' ) ;
+ }
+ elsif (m/^ Candidate: (.*)$/) {
+ $available = $1;
+ }
+ }
+ close(APTPOLICY);
+ return ( $installed, $available ) ;
+ }
+}
+
+sub Cmp_pkg_version ($$$$) {
+ my ( $pkg_type, $pkg_name, $version1, $version2 ) = @_ ;
+
+ if ( ! defined $PKG_CMD->{$pkg_type} ) {
+ Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'rpm' ) {
+ #TODO
+ Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) ;
+ return undef ;
+ }
+ else {
+ if ( $pkg_type eq 'deb' ) {
+ if ( ! deferredlogsystem ( $PKG_CMD->{$pkg_type}->{'compare'}.' '.$version1.' lt '.$version2 ) ) {
+ return -1 ;
+ }
+ elsif ( ! deferredlogsystem ( $PKG_CMD->{$pkg_type}->{'compare'}.' '.$version1.' eq '.$version2 ) ) {
+ return 0 ;
+ }
+ else {
+ return 1 ;
+ }
+ }
+ }
+}
+
+sub Install_pkg ($$) {
+ my ( $pkg_type, $pkg_name ) = @_ ;
+
+ if ( ! defined $PKG_CMD->{$pkg_type} ) {
+ Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) ;
+ return undef ;
+ }
+ elsif ( $pkg_type eq 'rpm' ) {
+ #TODO
+ Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) ;
+ return undef ;
+ }
+ else {
+ if ( $pkg_type eq 'deb' ) {
+ if ( deferredlogsystem ( $PKG_CMD->{$pkg_type}->{'install'}." '".$pkg_name."'" ) ) {
+ Warn( $ERR_OPEN, "Installation de ".$pkg_name." impossible" ) ;
+ return 0 ;
+ }
+ return 1 ;
+ }
+ }
+}
+
+1;
Propchange: trunk/lib/PFTools/Packages.pm
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Feb 6 16:23:21 2009
@@ -1,0 +1,2 @@
+Id
+Revision
More information about the pf-tools-commits
mailing list