This is an automated email from the git hooks/post-receive script. gregoa pushed a commit to annotated tag v0.22 in repository liblinux-distribution-perl.
commit d42d2bb5806ccd2453ff2ad117f6ed065b11e00c Author: Re Alberto <kerbe...@accidia.net> Date: Mon Jan 16 23:29:13 2006 -0800 import Linux::Distribution 0.13 from CPAN git-cpan-module: Linux::Distribution git-cpan-version: 0.13 --- Changes | 53 +++++----------------- META.yml | 4 +- README | 15 ++++-- lib/Linux/Distribution.pm | 113 +++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 127 insertions(+), 58 deletions(-) diff --git a/Changes b/Changes index 37d8700..f7cc07f 100644 --- a/Changes +++ b/Changes @@ -1,59 +1,30 @@ ------------------------------------------------------------------------- -r13 | kerberus | 2005-03-10 08:37:58 +0100 (Thu, 10 Mar 2005) | 2 lines +* 2006-16-01 +Thanks to Judith Lebzelter now the module gets advantage of the LSB's /etc/lsb-release file. +Added support for Ubuntu and version information retrieval for gentoo, debian, suse, fedora, +redhat and slackware. +* 2005-03-10 Added support for yoper, arch-linux and libranet. ------------------------------------------------------------------------- -r12 | kerberus | 2005-03-09 20:04:12 +0100 (Wed, 09 Mar 2005) | 3 lines - +* 2005-03-09 Cleaned code. - ------------------------------------------------------------------------- -r10 | kerberus | 2005-03-08 12:16:11 +0100 (Tue, 08 Mar 2005) | 1 line - - ------------------------------------------------------------------------- -r9 | kerberus | 2005-03-08 12:15:48 +0100 (Tue, 08 Mar 2005) | 4 lines - +* 2005-03-08 Version 0.03. - Added support for Adamantix and Trustix. ------------------------------------------------------------------------- -r8 | kerberus | 2005-03-07 23:03:50 +0100 (Mon, 07 Mar 2005) | 4 lines - +* 2005-03-07 Reduced needed perl version to 5.6.0. - Removed copyright line from pod documentation. ------------------------------------------------------------------------- -r6 | kerberus | 2005-03-06 20:29:33 +0100 (Sun, 06 Mar 2005) | 1 line - - ------------------------------------------------------------------------- -r5 | kerberus | 2005-03-06 20:27:46 +0100 (Sun, 06 Mar 2005) | 4 lines - +* 2005-03-06 Version 0.02. -Updated changelog. - ------------------------------------------------------------------------- -r4 | kerberus | 2005-03-06 20:25:16 +0100 (Sun, 06 Mar 2005) | 3 lines - +* 2005-03-06 Added support for immunix, conectiva, tinysofa and va-linux. - ------------------------------------------------------------------------- -r2 | kerberus | 2005-03-06 20:16:36 +0100 (Sun, 06 Mar 2005) | 2 lines - +* 2005-03-06 Updated changelog ------------------------------------------------------------------------- -r1 | kerberus | 2005-03-06 20:14:28 +0100 (Sun, 06 Mar 2005) | 4 lines - +* 2005-03-06 20:14:28 +0100 Version 0.01. - -Imported original source tree. - ------------------------------------------------------------------------- diff --git a/META.yml b/META.yml index 1302898..1e65e95 100644 --- a/META.yml +++ b/META.yml @@ -1,10 +1,10 @@ # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Linux-Distribution -version: 0.11 +version: 0.13 version_from: lib/Linux/Distribution.pm installdirs: site requires: distribution_type: module -generated_by: ExtUtils::MakeMaker version 6.30 +generated_by: ExtUtils::MakeMaker version 6.17 diff --git a/README b/README index 9eaa1cd..37e4100 100644 --- a/README +++ b/README @@ -1,8 +1,15 @@ -Linux-Distribution version 0.11 +Linux-Distribution version 0.13 =============================== -This is a module that guess on what kind of linux distribution we are running looking for distro's specific release file into /etc. -It currently recognize slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet and gentoo. +This is a simple module that tries to guess on what linux distribution we are running by looking +for release's files in /etc. It now looks for 'lsb-release' first as that should be the most cor- +rect and adds ubuntu support. Secondly, it will look for the distro specific files. + +It currently recognizes slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, +mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet, +gentoo and ubuntu. + +It has function to get the version for debian, suse, redhat, gentoo, slackware and ubuntu(lsb). INSTALLATION @@ -19,7 +26,7 @@ This module has no dependencies. COPYRIGHT AND LICENCE -Copyright (C) 2005 by Alberto Re <kerbe...@accidia.net> +Copyright (C) 2006 by Alberto Re <kerbe...@accidia.net> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, diff --git a/lib/Linux/Distribution.pm b/lib/Linux/Distribution.pm index 8821f38..76db669 100644 --- a/lib/Linux/Distribution.pm +++ b/lib/Linux/Distribution.pm @@ -8,9 +8,11 @@ require Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw( distribution_name ); +our @EXPORT_OK = qw( distribution_name distribution_version ); -our $VERSION = '0.11'; +our $VERSION = '0.13'; + +our $standard_release_file = 'lsb-release'; our %release_files = ( 'gentoo-release' => 'gentoo', @@ -38,42 +40,130 @@ our %release_files = ( 'va-release' => 'va-linux' ); +our %version_match = ( + 'gentoo' => 'Gentoo Base System version (.*)', + 'debian' => '(.+)', + 'suse' => 'VERSION = (.*)', + 'fedora' => 'Fedora Core release (\d+) \(', + 'redhat' => 'Red Hat Linux release (.*) \(', + 'slackware' => '^Slackware (.+)$' +); + if ($^O ne 'linux') { require Carp; Carp::croak 'you are trying to use a linux specific module on a different OS'; } +sub new { + my %self = ( + 'DISTRIB_ID' => '', + 'DISTRIB_RELEASE' => '', + 'DISTRIB_CODENAME' => '', + 'DISTRIB_DESCRIPTION' => '', + 'release_file' => '', + 'pattern' => '' + ); + + return bless \%self; +} + sub distribution_name { + my $self = shift || new(); + my $distro; + if ($distro = $self->_get_lsb_info()){ + $self->{'DISTRIB_ID'} = $distro; + return $distro if ($distro = $self->_get_lsb_info()); + } foreach (keys %release_files) { - return $release_files{$_} if -f "/etc/$_" && !-l "/etc/$_" + if (-f "/etc/$_" && !-l "/etc/$_"){ + if (-f "/etc/$_" && !-l "/etc/$_"){ + $self->{'DISTRIB_ID'} = $release_files{$_}; + $self->{'release_file'} = $_; + return $self->{'DISTRIB_ID'}; + } + } } undef } +sub distribution_version { + my $self = shift || new(); + my $release; + return $release if ($release = $self->_get_lsb_info('DISTRIB_RELEASE')); + if (! $self->{'DISTRIB_ID'}){ + $self->distribution_name() or die 'No version because no distro.'; + } + $self->{'pattern'} = $version_match{$self->{'DISTRIB_ID'}}; + return $self->_get_file_info(); + undef +} + +sub _get_lsb_info { + my $self = shift; + my $field = shift || "DISTRIB_ID"; + my $tmp = $self->{'release_file'}; + if ( -f '/etc/' . $standard_release_file ) { + $self->{'release_file'} = $standard_release_file; + $self->{'pattern'} = $field . '=(.+)'; + my $info = $self->_get_file_info(); + return $info if $info; + } + $self->{'release_file'} = $tmp; + $self->{'pattern'} = ''; + undef; +} + +sub _get_file_info { + my $self = shift; + open FH, '/etc/' . $self->{'release_file'} or die 'Cannot open file: /etc/' . $self->{'release_file'}; + my $info = ''; + while (<FH>){ + chomp $_; + ($info) = $_ =~ m/$self->{'pattern'}/; + return "\L$info" if $info; + } + undef; +} + 1; __END__ =head1 NAME -Linux::Distribution - Perl extension to guess on what linux distribution we are running on. +Linux::Distribution - Perl extension to guess on which Linux distribution we are running. =head1 SYNOPSIS - use Linux::Distribution qw(distribution_name); + use Linux::Distribution qw(distribution_name distribution_version); if(my $distro = distribution_name) { - print "you are running $distro\n"; + my $version = distribution_version(); + print "you are running $distro, version $version\n"; } else { print "distribution unknown\n"; } + Or else do it OO: + + use Linux::Distribution qw(distribution_name distribution_version); + + $linux = new Linux::Distribution; + if(my $distro = $linux->distribution_name()) { + my $version = $linux->distribution_version(); + print "you are running $distro, version $version\n"; + } else { + print "distribution unknown\n"; + } + =head1 DESCRIPTION -This is a simple module that try to guess on what linux distribution we are running looking for release's files in /etc. +This is a simple module that tries to guess on what linux distribution we are running by looking for release's files in /etc. It now looks for 'lsb-release' first as that should be the most correct and adds ubuntu support. Secondly, it will look for the distro specific files. + +It currently recognizes slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet, gentoo and ubuntu. -It currently recognize slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet and gentoo. +It has function to get the version for debian, suse, redhat, gentoo, slackware and ubuntu(lsb). People running unsupported distro's are greatly encouraged to submit patches :-) =head2 EXPORT @@ -81,11 +171,12 @@ None by default. =head1 TODO -Add the capability of recognize the version of the distribution. +Add the capability of recognize the version of the distribution for all recognized distributions. -=head1 AUTHOR +=head1 AUTHORS -Alberto Re, E<lt>kerbe...@accidia.nete<gt> +Alberto Re, E<lt>albe...@accidia.nete<gt> +Judith Lebzelter, E<lt>jud...@osdl.orge<gt> =head1 COPYRIGHT AND LICENSE -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/liblinux-distribution-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits