These 2 patches are mostly code motion. They were prompted by an apparent augeas error in BZ 613967 which didn't display useful error message. The error seems to happen in Converter::Linux. GuestOS::RedHat had a handy function which displayed verbose augeas error messages. This function moves into the new module where it can be used by both modules. The second patch is an consequential tidy up. UserMessage moves into the new module. * [PATCH 1/2] Move augeas error reporting into new Sys::VirtV2V::Util * [PATCH 2/2] Move user_message into Sys::VirtV2V::Util
Matthew Booth
2010-Jul-28 13:56 UTC
[Libguestfs] [PATCH 1/2] Move augeas error reporting into new Sys::VirtV2V::Util
_augeas_error from GuestOS::RedHat is useful in other modules which use augeas. Pull it into a new module, Sys::VirtV2V::Util, and update all uses. Additionally, use the new function in Converter::Linux. --- MANIFEST | 21 ++++---- lib/Sys/VirtV2V/Converter/Linux.pm | 6 ++- lib/Sys/VirtV2V/GuestOS/RedHat.pm | 99 +++++++---------------------------- 3 files changed, 36 insertions(+), 90 deletions(-) diff --git a/MANIFEST b/MANIFEST index fb6a2fc..0673eb7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2,26 +2,27 @@ Build.PL ChangeLog COPYING COPYING.LIB -lib/Sys/VirtV2V.pm +lib/Sys/VirtV2V/Config.pm +lib/Sys/VirtV2V/Connection/LibVirt.pm +lib/Sys/VirtV2V/Connection/LibVirtXML.pm +lib/Sys/VirtV2V/Connection.pm +lib/Sys/VirtV2V/Converter/Linux.pm +lib/Sys/VirtV2V/Converter.pm +lib/Sys/VirtV2V/Converter/Windows.pm lib/Sys/VirtV2V/ExecHelper.pm lib/Sys/VirtV2V/GuestfsHandle.pm lib/Sys/VirtV2V/GuestOS.pm lib/Sys/VirtV2V/GuestOS/RedHat.pm -lib/Sys/VirtV2V/Config.pm -lib/Sys/VirtV2V/Converter.pm -lib/Sys/VirtV2V/Converter/Linux.pm -lib/Sys/VirtV2V/Converter/Windows.pm -lib/Sys/VirtV2V/Connection.pm -lib/Sys/VirtV2V/Connection/LibVirt.pm -lib/Sys/VirtV2V/Connection/LibVirtXML.pm -lib/Sys/VirtV2V/UserMessage.pm +lib/Sys/VirtV2V.pm lib/Sys/VirtV2V/Target/LibVirt.pm lib/Sys/VirtV2V/Target/RHEV.pm lib/Sys/VirtV2V/Transfer/ESX.pm lib/Sys/VirtV2V/Transfer/LocalCopy.pm lib/Sys/VirtV2V/Transfer/SSH.pm -MANIFEST This list of files +lib/Sys/VirtV2V/UserMessage.pm +lib/Sys/VirtV2V/Util.pm MANIFEST.SKIP +MANIFEST This list of files META.yml po/es.po po/it.po diff --git a/lib/Sys/VirtV2V/Converter/Linux.pm b/lib/Sys/VirtV2V/Converter/Linux.pm index ffcf9eb..82e7ba4 100644 --- a/lib/Sys/VirtV2V/Converter/Linux.pm +++ b/lib/Sys/VirtV2V/Converter/Linux.pm @@ -27,6 +27,7 @@ use XML::DOM; use XML::DOM::XPath; use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(augeas_error); use Carp; @@ -236,7 +237,10 @@ sub _configure_console } } - $g->aug_save(); + eval { + $g->aug_save(); + }; + augeas_error($g, $@) if ($@); } sub _configure_display_driver diff --git a/lib/Sys/VirtV2V/GuestOS/RedHat.pm b/lib/Sys/VirtV2V/GuestOS/RedHat.pm index 563e6f1..54ae483 100644 --- a/lib/Sys/VirtV2V/GuestOS/RedHat.pm +++ b/lib/Sys/VirtV2V/GuestOS/RedHat.pm @@ -26,6 +26,8 @@ use Sys::Guestfs::Lib qw(inspect_linux_kernel); use Sys::VirtV2V::GuestOS; use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(augeas_error); + use Locale::TextDomain 'virt-v2v'; @Sys::VirtV2V::GuestOS::RedHat::ISA = qw(Sys::VirtV2V::GuestOS); @@ -93,67 +95,6 @@ sub new return $self; } -sub _augeas_error -{ - my $self = shift; - my ($err) = @_; # The original error message. We will emit this if there - # were no augeas errors. - - my $g = $self->{g}; - - my $msg = ""; - - eval { - foreach my $error ($g->aug_match('/augeas/files//error')) { - $error =~ /^\/augeas\/files(\/.*)\/error$/ - or die("Unexpected return from aug_match: $error"); - my $file = $1; - - my %detail; - foreach my $detail_path ($g->aug_match("$error//*")) { - $detail_path =~ /^$error\/(.*)$/ - or die("Unexpected return from aug_match: $detail_path"); - $detail{$1} = $g->aug_get($detail_path); - } - - if (defined($detail{message})) { - $msg .= __x("augeas error for {file}: {error}", - file => $file, - error => $detail{message})."\n"; - } else { - $msg .= __x("augeas error for {file}", - file => $file)."\n"; - } - - if (defined($detail{pos}) && defined($detail{line}) && - defined($detail{char})) - { - $msg .= __x("error at line {line}, char {char}, file ". - "position {pos}", - line => $detail{line}, - char => $detail{char}, - pos => $detail{pos})."\n"; - } - - if (defined($detail{lens})) { - $msg .= __x("augeas lens: {lens}", - lens => $detail{lens})."\n"; - } - } - }; - - # Check for failures above - if ($@) { - die("error generating pretty augeas error: $@\n". - "Original error was: $err"); - } - - chomp($msg); - - die(user_message($msg)) if (length($msg) > 0); - die($err); -} - # Handle SELinux for the guest sub _init_selinux { @@ -246,7 +187,7 @@ sub _init_augeas }; # The augeas calls will die() on any error. - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } =item enable_kernel_module(device, module) @@ -270,7 +211,7 @@ sub enable_kernel_module }; # Propagate augeas errors - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } =item update_kernel_module(device, module) @@ -303,7 +244,7 @@ sub update_kernel_module }; # Propagate augeas errors - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } =item disable_kernel_module(device) @@ -336,7 +277,7 @@ sub disable_kernel_module }; # Propagate augeas errors - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } =item update_display_driver(driver) @@ -364,7 +305,7 @@ sub update_display_driver }; # Propagate augeas errors - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } # We can't rely on the index in the augeas path because it will change if @@ -394,7 +335,7 @@ sub _check_augeas_device }; # Propagate augeas errors - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); return $augeas; } @@ -430,7 +371,7 @@ sub list_kernels if defined($default); push(@paths, $g->aug_match('/files/boot/grub/menu.lst/title/kernel')); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); my @kernels; my %checked; @@ -442,7 +383,7 @@ sub list_kernels eval { $kernel = $g->aug_get($path); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); # Prepend the grub filesystem to the kernel path $kernel = "$grub$kernel" if(defined($grub)); @@ -737,7 +678,7 @@ sub _install_any eval { $g->aug_load(); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); return $success; } @@ -986,7 +927,7 @@ sub _check_grub return if ($g->aug_get($augpath) eq $kernel); } }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); my $prefix; if ($self->{desc}->{boot}->{grub_fs} eq "/boot") { @@ -1074,7 +1015,7 @@ sub _check_grub $g->aug_save(); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } # Inspect the guest description to work out what kernel package is in use @@ -1159,7 +1100,7 @@ sub remove_kernel eval { $g->aug_load(); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } sub _get_nevra @@ -1457,7 +1398,7 @@ sub remove_application $g->aug_load(); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); } =item get_application_owner(file) @@ -1500,7 +1441,7 @@ sub _install_rpms $g->aug_load(); }; - $self->_augeas_error($@) if($@); + augeas_error($g, $@) if($@); } =item remap_block_devices(devices, virtio) @@ -1568,7 +1509,7 @@ sub remap_block_devices } }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); # If guest config contains references to sdX, these could refer to IDE # or SCSI devices. We may need to update them. @@ -1661,7 +1602,7 @@ sub remap_block_devices $g->aug_save(); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); # Delete cached (and now out of date) blkid info if it exists foreach my $blkidtab ('/etc/blkid/blkid.tab', '/etc/blkid.tab') { @@ -1742,7 +1683,7 @@ sub prepare_bootable }; # Propagate augeas failure - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); if(!defined($initrd)) { warn user_message(__x("WARNING: Kernel version {version} ". @@ -1766,7 +1707,7 @@ sub prepare_bootable $g->aug_save(); }; - $self->_augeas_error($@) if ($@); + augeas_error($g, $@) if ($@); # We explicitly modprobe ext2 here. This is required by mkinitrd on RHEL # 3, and shouldn't hurt on other OSs. We don't care if this fails. -- 1.7.2
Matthew Booth
2010-Jul-28 13:56 UTC
[Libguestfs] [PATCH 2/2] Move user_message into Sys::VirtV2V::Util
This change moves user_message from Sys::VirtV2V::UserMessage into Sys::VirtV2V::Util and removes the former. This involves touching everywhere that imports UserMessage, which is quite a lot of places. The change also removes UserMessage's set_identifier method, and instead hard-codes the message identifier. This involves a significant amount of churn as all the translations must be updated. --- MANIFEST | 1 - lib/Sys/VirtV2V/Config.pm | 2 +- lib/Sys/VirtV2V/Connection.pm | 2 +- lib/Sys/VirtV2V/Connection/LibVirt.pm | 2 +- lib/Sys/VirtV2V/Connection/LibVirtXML.pm | 2 +- lib/Sys/VirtV2V/Converter.pm | 2 +- lib/Sys/VirtV2V/Converter/Linux.pm | 3 +- lib/Sys/VirtV2V/Converter/Windows.pm | 2 +- lib/Sys/VirtV2V/GuestOS.pm | 2 +- lib/Sys/VirtV2V/GuestOS/RedHat.pm | 4 +- lib/Sys/VirtV2V/GuestfsHandle.pm | 2 +- lib/Sys/VirtV2V/Target/LibVirt.pm | 4 +- lib/Sys/VirtV2V/Target/RHEV.pm | 6 +- lib/Sys/VirtV2V/Transfer/ESX.pm | 4 +- lib/Sys/VirtV2V/Transfer/LocalCopy.pm | 2 +- lib/Sys/VirtV2V/Transfer/SSH.pm | 2 +- lib/Sys/VirtV2V/UserMessage.pm | 104 ------------------------------ po/POTFILES.in | 5 +- po/es.po | 4 +- po/it.po | 2 +- po/or.po | 2 +- po/pl.po | 4 +- po/ru.po | 4 +- po/te.po | 2 +- po/uk.po | 4 +- po/virt-v2v.pot | 2 +- po/zh_CN.po | 2 +- v2v/virt-v2v.pl | 5 +- 28 files changed, 36 insertions(+), 146 deletions(-) delete mode 100644 lib/Sys/VirtV2V/UserMessage.pm diff --git a/MANIFEST b/MANIFEST index 0673eb7..619ad75 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,7 +19,6 @@ lib/Sys/VirtV2V/Target/RHEV.pm lib/Sys/VirtV2V/Transfer/ESX.pm lib/Sys/VirtV2V/Transfer/LocalCopy.pm lib/Sys/VirtV2V/Transfer/SSH.pm -lib/Sys/VirtV2V/UserMessage.pm lib/Sys/VirtV2V/Util.pm MANIFEST.SKIP MANIFEST This list of files diff --git a/lib/Sys/VirtV2V/Config.pm b/lib/Sys/VirtV2V/Config.pm index 2e26a77..f703152 100644 --- a/lib/Sys/VirtV2V/Config.pm +++ b/lib/Sys/VirtV2V/Config.pm @@ -26,7 +26,7 @@ use XML::DOM; use XML::DOM::XPath; use Sys::VirtV2V::ExecHelper; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Connection.pm b/lib/Sys/VirtV2V/Connection.pm index 4dc659d..8029230 100644 --- a/lib/Sys/VirtV2V/Connection.pm +++ b/lib/Sys/VirtV2V/Connection.pm @@ -25,7 +25,7 @@ use Sys::Virt; use Sys::VirtV2V::Transfer::ESX; use Sys::VirtV2V::Transfer::LocalCopy; use Sys::VirtV2V::Transfer::SSH; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Connection/LibVirt.pm b/lib/Sys/VirtV2V/Connection/LibVirt.pm index e5675e1..b83a10d 100644 --- a/lib/Sys/VirtV2V/Connection/LibVirt.pm +++ b/lib/Sys/VirtV2V/Connection/LibVirt.pm @@ -29,7 +29,7 @@ use XML::DOM; use Sys::Virt; use Sys::VirtV2V; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Connection/LibVirtXML.pm b/lib/Sys/VirtV2V/Connection/LibVirtXML.pm index ac3e82b..7dc122f 100644 --- a/lib/Sys/VirtV2V/Connection/LibVirtXML.pm +++ b/lib/Sys/VirtV2V/Connection/LibVirtXML.pm @@ -24,7 +24,7 @@ use XML::DOM; use XML::DOM::XPath; use Sys::VirtV2V::Connection; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Converter.pm b/lib/Sys/VirtV2V/Converter.pm index db90b17..42f0e70 100644 --- a/lib/Sys/VirtV2V/Converter.pm +++ b/lib/Sys/VirtV2V/Converter.pm @@ -28,7 +28,7 @@ use Module::Pluggable sub_name => 'modules', use Locale::TextDomain 'virt-v2v'; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); =pod diff --git a/lib/Sys/VirtV2V/Converter/Linux.pm b/lib/Sys/VirtV2V/Converter/Linux.pm index 82e7ba4..1734a58 100644 --- a/lib/Sys/VirtV2V/Converter/Linux.pm +++ b/lib/Sys/VirtV2V/Converter/Linux.pm @@ -26,8 +26,7 @@ use Locale::TextDomain 'virt-v2v'; use XML::DOM; use XML::DOM::XPath; -use Sys::VirtV2V::UserMessage qw(user_message); -use Sys::VirtV2V::Util qw(augeas_error); +use Sys::VirtV2V::Util qw(augeas_error user_message); use Carp; diff --git a/lib/Sys/VirtV2V/Converter/Windows.pm b/lib/Sys/VirtV2V/Converter/Windows.pm index 7f4604d..90822dd 100644 --- a/lib/Sys/VirtV2V/Converter/Windows.pm +++ b/lib/Sys/VirtV2V/Converter/Windows.pm @@ -32,7 +32,7 @@ use Win::Hivex; use Win::Hivex::Regedit qw(reg_import); use Locale::TextDomain 'virt-v2v'; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Carp; diff --git a/lib/Sys/VirtV2V/GuestOS.pm b/lib/Sys/VirtV2V/GuestOS.pm index 57311ec..e07671b 100644 --- a/lib/Sys/VirtV2V/GuestOS.pm +++ b/lib/Sys/VirtV2V/GuestOS.pm @@ -25,7 +25,7 @@ use File::Spec; use File::Temp; use Sys::VirtV2V::ExecHelper; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Module::Pluggable sub_name => 'modules', search_path => 'Sys::VirtV2V::GuestOS', diff --git a/lib/Sys/VirtV2V/GuestOS/RedHat.pm b/lib/Sys/VirtV2V/GuestOS/RedHat.pm index 54ae483..3d8c1c7 100644 --- a/lib/Sys/VirtV2V/GuestOS/RedHat.pm +++ b/lib/Sys/VirtV2V/GuestOS/RedHat.pm @@ -24,9 +24,7 @@ use File::Spec; use Sys::Guestfs::Lib qw(inspect_linux_kernel); use Sys::VirtV2V::GuestOS; -use Sys::VirtV2V::UserMessage qw(user_message); - -use Sys::VirtV2V::Util qw(augeas_error); +use Sys::VirtV2V::Util qw(augeas_error user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/GuestfsHandle.pm b/lib/Sys/VirtV2V/GuestfsHandle.pm index 8720744..953d774 100644 --- a/lib/Sys/VirtV2V/GuestfsHandle.pm +++ b/lib/Sys/VirtV2V/GuestfsHandle.pm @@ -23,7 +23,7 @@ use warnings; use Carp; use Sys::Guestfs::Lib qw(open_guest); -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Target/LibVirt.pm b/lib/Sys/VirtV2V/Target/LibVirt.pm index ca69b96..574590c 100644 --- a/lib/Sys/VirtV2V/Target/LibVirt.pm +++ b/lib/Sys/VirtV2V/Target/LibVirt.pm @@ -22,7 +22,7 @@ package Sys::VirtV2V::Target::LibVirt::Vol; use POSIX; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; @@ -145,7 +145,7 @@ sub close package Sys::VirtV2V::Target::LibVirt; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Target/RHEV.pm b/lib/Sys/VirtV2V/Target/RHEV.pm index 00d5e7d..330b52e 100644 --- a/lib/Sys/VirtV2V/Target/RHEV.pm +++ b/lib/Sys/VirtV2V/Target/RHEV.pm @@ -41,7 +41,7 @@ use Carp; use File::Temp qw(tempfile); use POSIX qw(:sys_wait_h setuid setgid); -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; @@ -164,7 +164,7 @@ use File::Path; use File::Temp qw(tempdir); use POSIX; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; @@ -411,7 +411,7 @@ use File::Temp qw(tempdir); use Time::gmtime; use Sys::VirtV2V::ExecHelper; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Transfer/ESX.pm b/lib/Sys/VirtV2V/Transfer/ESX.pm index f9ddbe1..798285b 100644 --- a/lib/Sys/VirtV2V/Transfer/ESX.pm +++ b/lib/Sys/VirtV2V/Transfer/ESX.pm @@ -24,7 +24,7 @@ use Sys::Virt::Error; use Sys::VirtV2V; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; @@ -284,7 +284,7 @@ package Sys::VirtV2V::Transfer::ESX; use Sys::Virt; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Transfer/LocalCopy.pm b/lib/Sys/VirtV2V/Transfer/LocalCopy.pm index 75ca039..cdff97e 100644 --- a/lib/Sys/VirtV2V/Transfer/LocalCopy.pm +++ b/lib/Sys/VirtV2V/Transfer/LocalCopy.pm @@ -21,7 +21,7 @@ use POSIX; use File::Spec; use File::stat; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/Transfer/SSH.pm b/lib/Sys/VirtV2V/Transfer/SSH.pm index c78edc6..66ec294 100644 --- a/lib/Sys/VirtV2V/Transfer/SSH.pm +++ b/lib/Sys/VirtV2V/Transfer/SSH.pm @@ -21,7 +21,7 @@ use POSIX; use File::Spec; use File::stat; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); use Locale::TextDomain 'virt-v2v'; diff --git a/lib/Sys/VirtV2V/UserMessage.pm b/lib/Sys/VirtV2V/UserMessage.pm deleted file mode 100644 index 432f63e..0000000 --- a/lib/Sys/VirtV2V/UserMessage.pm +++ /dev/null @@ -1,104 +0,0 @@ -# Sys::VirtV2V::UserMessage -# Copyright (C) 2009 Red Hat Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -package Sys::VirtV2V::UserMessage; - -use strict; -use warnings; - -use Locale::TextDomain 'virt-v2v'; - -require Exporter; - -use vars qw(@EXPORT_OK @ISA); - - at ISA = qw(Exporter); - at EXPORT_OK = qw(user_message); - -=pod - -=head1 NAME - -Sys::VirtV2V::UserMessage - Create consistent user messages - -=head1 SYNOPSIS - - use Sys::VirtV2V::UserMessage qw(user_message); - - Sys::VirtV2V::UserMessage->set_identifier(__'virt-v2v'); - - warn user_message(__x("Couldn't open {file}: {error}", - file => $file, error => $error)); - -=head1 DESCRIPTION - -Sys::VirtV2V::UserMessage provides an interface for displaying consistently -formatted messages to a user. The string passed to user_message() should not -contain a trailing newline. In English, the output will have the identifier -prefixed if one was specified, and a newline appended. - -=head1 METHODS - -=over - -=item Sys::VirtV2V::UserMessage->set_identifier(identifier) - -Set an identifier which will identify messages from this source from other -sources. In English, this identifier will be prefixed to all messages with a -colon and trailing space. - -=cut - -our $identifier; - -sub set_identifier -{ - my $class = shift; - my ($new_identifier) = @_; - - $identifier = $new_identifier; -} - -=item user_message(message) - -Return a formatted user message. - -I<message> should not contain a prefix or a trailing newline. - -=cut - -sub user_message -{ - my ($msg) = (@_); - - return __x("{identifier}: {message}\n", - identifier => $identifier, message => $msg); -} - -=back - -=head1 COPYRIGHT - -Copyright (C) 2009 Red Hat Inc. - -=head1 LICENSE - -Please see the file COPYING.LIB for the full license. - -=cut - -1; diff --git a/po/POTFILES.in b/po/POTFILES.in index 052f747..6dddbfe 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -3,9 +3,10 @@ ../lib/Sys/VirtV2V/Connection/LibVirtXML.pm ../lib/Sys/VirtV2V/Connection.pm ../lib/Sys/VirtV2V/Converter/Linux.pm -../lib/Sys/VirtV2V/Converter/Windows.pm ../lib/Sys/VirtV2V/Converter.pm +../lib/Sys/VirtV2V/Converter/Windows.pm ../lib/Sys/VirtV2V/ExecHelper.pm +../lib/Sys/VirtV2V/GuestfsHandle.pm ../lib/Sys/VirtV2V/GuestOS.pm ../lib/Sys/VirtV2V/GuestOS/RedHat.pm ../lib/Sys/VirtV2V.pm @@ -14,5 +15,5 @@ ../lib/Sys/VirtV2V/Transfer/ESX.pm ../lib/Sys/VirtV2V/Transfer/LocalCopy.pm ../lib/Sys/VirtV2V/Transfer/SSH.pm -../lib/Sys/VirtV2V/UserMessage.pm +../lib/Sys/VirtV2V/Util.pm ../v2v/virt-v2v.pl diff --git a/po/es.po b/po/es.po index f459ea2..c014aca 100644 --- a/po/es.po +++ b/po/es.po @@ -597,8 +597,8 @@ msgstr "Error no esperado obteniendo {path}: {output}" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" -msgstr "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" +msgstr "virt-v2v: {message}\n" #: ../v2v/virt-v2v.pl:240 msgid "Use -ic or -oc to specify an input or an output connection" diff --git a/po/it.po b/po/it.po index a2f4c15..b98e49f 100644 --- a/po/it.po +++ b/po/it.po @@ -541,7 +541,7 @@ msgstr "" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" msgstr "" #: ../v2v/virt-v2v.pl:240 diff --git a/po/or.po b/po/or.po index 48de7ae..a0cc509 100644 --- a/po/or.po +++ b/po/or.po @@ -539,7 +539,7 @@ msgstr "" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" msgstr "" #: ../v2v/virt-v2v.pl:240 diff --git a/po/pl.po b/po/pl.po index a0b6439..da85df8 100644 --- a/po/pl.po +++ b/po/pl.po @@ -585,8 +585,8 @@ msgstr "Nieoczekiwany b??d podczas otrzymywania {path}: {output}" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" -msgstr "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" +msgstr "virt-v2v: {message}\n" #: ../v2v/virt-v2v.pl:240 msgid "Use -ic or -oc to specify an input or an output connection" diff --git a/po/ru.po b/po/ru.po index d17ab8d..9bc1055 100644 --- a/po/ru.po +++ b/po/ru.po @@ -552,8 +552,8 @@ msgstr "" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" -msgstr "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" +msgstr "virt-v2v: {message}\n" #: ../v2v/virt-v2v.pl:240 msgid "Use -ic or -oc to specify an input or an output connection" diff --git a/po/te.po b/po/te.po index acd622c..ec8c707 100644 --- a/po/te.po +++ b/po/te.po @@ -537,7 +537,7 @@ msgstr "" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" msgstr "" #: ../v2v/virt-v2v.pl:240 diff --git a/po/uk.po b/po/uk.po index ad7f0ec..749510c 100644 --- a/po/uk.po +++ b/po/uk.po @@ -547,8 +547,8 @@ msgstr "" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" -msgstr "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" +msgstr "virt-v2v: {message}\n" #: ../v2v/virt-v2v.pl:240 msgid "Use -ic or -oc to specify an input or an output connection" diff --git a/po/virt-v2v.pot b/po/virt-v2v.pot index 31672ec..5095a56 100644 --- a/po/virt-v2v.pot +++ b/po/virt-v2v.pot @@ -526,7 +526,7 @@ msgstr "" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" msgstr "" #: ../v2v/virt-v2v.pl:240 diff --git a/po/zh_CN.po b/po/zh_CN.po index 0f69b06..1259a44 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -535,7 +535,7 @@ msgstr "" #: ../lib/Sys/VirtV2V/UserMessage.pm:88 #, perl-brace-format -msgid "{identifier}: {message}\n" +msgid "virt-v2v: {message}\n" msgstr "" #: ../v2v/virt-v2v.pl:240 diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl index 988308c..38b69b5 100755 --- a/v2v/virt-v2v.pl +++ b/v2v/virt-v2v.pl @@ -39,7 +39,7 @@ use Sys::VirtV2V::Target::RHEV; use Sys::VirtV2V::ExecHelper; use Sys::VirtV2V::GuestfsHandle; use Sys::VirtV2V::GuestOS; -use Sys::VirtV2V::UserMessage qw(user_message); +use Sys::VirtV2V::Util qw(user_message); =encoding utf8 @@ -224,9 +224,6 @@ $SIG{'QUIT'} = \&signal_exit; # from or writing to a pipe. $SIG{'PIPE'} = 'IGNORE'; -# Initialise the message output prefix -Sys::VirtV2V::UserMessage->set_identifier('virt-v2v'); - GetOptions ("help|?" => sub { pod2usage(0); }, -- 1.7.2
On Wed, Jul 28, 2010 at 02:56:34PM +0100, Matthew Booth wrote:> These 2 patches are mostly code motion. They were prompted by an apparent augeas > error in BZ 613967 which didn't display useful error message. The error seems to > happen in Converter::Linux. GuestOS::RedHat had a handy function which displayed > verbose augeas error messages. This function moves into the new module where it > can be used by both modules. > > The second patch is an consequential tidy up. UserMessage moves into the new > module. > > * [PATCH 1/2] Move augeas error reporting into new Sys::VirtV2V::Util > * [PATCH 2/2] Move user_message into Sys::VirtV2V::UtilYes, looks like a code tidy-up. ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
Seemingly Similar Threads
- [FOR REVIEW ONLY] ESX work in progress
- [ESX support] Working ESX conversion for RHEL 5
- Refactor virt-v2v to be more like a 'big script'
- [PATCH 1/2] Refactor guest and volume creation into Sys::VirtV2V::Target::LibVirt
- [PATCH 1/6] Convert config file to XML, and translate networks/bridge for all connections