Bugzilla – Attachment 164908 Details for
Bug 35681
Add support for colored messages in the output of updatedatabase
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35681: Add Koha::Installer::Output
Bug-35681-Add-KohaInstallerOutput.patch (text/plain), 5.11 KB, created by
Martin Renvoize (ashimema)
on 2024-04-16 11:23:58 UTC
(
hide
)
Description:
Bug 35681: Add Koha::Installer::Output
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-04-16 11:23:58 UTC
Size:
5.11 KB
patch
obsolete
>From 400ee7568077b9d27b3297245c1a059b5d0eec3d Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 16 Apr 2024 12:06:54 +0100 >Subject: [PATCH] Bug 35681: Add Koha::Installer::Output > >--- > Koha/Installer/Output.pm | 98 +++++++++++++++++++++++++++++++++++++++ > t/Koha/Installer/Output.t | 55 ++++++++++++++++++++++ > 2 files changed, 153 insertions(+) > create mode 100644 Koha/Installer/Output.pm > create mode 100755 t/Koha/Installer/Output.t > >diff --git a/Koha/Installer/Output.pm b/Koha/Installer/Output.pm >new file mode 100644 >index 00000000000..6cb3d6a78d8 >--- /dev/null >+++ b/Koha/Installer/Output.pm >@@ -0,0 +1,98 @@ >+package Koha::Installer::Output; >+ >+# Copyright 2024 Koha Development Team >+# >+# This file is part of Koha. >+# >+# Koha 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 3 of the License, or >+# (at your option) any later version. >+# >+# Koha 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 Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Exporter qw(import); >+use Term::ANSIColor qw(:constants); >+ >+our @EXPORT_OK = qw(say_warning say_failure say_success say_info); >+ >+=head1 NAME >+ >+Koha::Installer::Output - Module to provide colored output for Koha installer >+ >+=head1 SYNOPSIS >+ >+ use Koha::Installer::Output qw(say_warning say_failure say_success say_info); >+ >+ # Output messages with appropriate colors >+ say_warning($fh, "This is a warning message"); >+ say_failure($fh, "This is a failure message"); >+ say_success($fh, "This is a success message"); >+ say_info($fh, "This is an info message"); >+ >+=head1 DESCRIPTION >+ >+This module provides methods to output messages with appropriate colors for different types of messages: >+warnings, failures, successes, and informational messages. >+ >+=head1 EXPORTS >+ >+The following functions can be exported upon request: >+ >+=over 4 >+ >+=item * say_warning($fh, $msg) >+ >+Output a warning message in yellow. >+ >+=item * say_failure($fh, $msg) >+ >+Output a failure message in red. >+ >+=item * say_success($fh, $msg) >+ >+Output a success message in green. >+ >+=item * say_info($fh, $msg) >+ >+Output an informational message in blue. >+ >+=back >+ >+=cut >+ >+sub say_warning { >+ my ( $fh, $msg ) = @_; >+ say $fh YELLOW, "$msg", RESET; >+} >+ >+sub say_failure { >+ my ( $fh, $msg ) = @_; >+ say $fh RED, "$msg", RESET; >+} >+ >+sub say_success { >+ my ( $fh, $msg ) = @_; >+ say $fh GREEN, "$msg", RESET; >+} >+ >+sub say_info { >+ my ( $fh, $msg ) = @_; >+ say $fh BLUE, "$msg", RESET; >+} >+ >+=head1 AUTHORS >+ >+Martin Renvoize <martin.renvoize@ptfs-europe.com> >+ >+=cut >+ >+1; >diff --git a/t/Koha/Installer/Output.t b/t/Koha/Installer/Output.t >new file mode 100755 >index 00000000000..b78b2cd85e5 >--- /dev/null >+++ b/t/Koha/Installer/Output.t >@@ -0,0 +1,55 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha 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 3 of the License, or >+# (at your option) any later version. >+# >+# Koha 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 Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 4; >+ >+use Koha::Installer::Output qw(say_warning say_failure say_success say_info); >+ >+# Set up a temporary file for testing output >+my $temp_file = "test_output.log"; >+open my $fh, '>', $temp_file or die "Cannot open $temp_file: $!"; >+ >+# Redirect output to the temporary file >+my $old_fh = select $fh; >+ >+# Test the output functions >+say_warning( $fh, "Testing warning message" ); >+say_failure( $fh, "Testing failure message" ); >+say_success( $fh, "Testing success message" ); >+say_info( $fh, "Testing info message" ); >+ >+# Restore the previous output filehandle >+select $old_fh; >+ >+# Close the temporary file >+close $fh; >+ >+# Read the contents of the temporary file for testing >+open my $test_fh, '<', $temp_file or die "Cannot open $temp_file: $!"; >+my @lines = <$test_fh>; >+close $test_fh; >+ >+# Test the output content >+like( $lines[0], qr/\e\[\d+mTesting warning message\e\[0m/, "Warning message output with ANSI color code" ); >+like( $lines[1], qr/\e\[\d+mTesting failure message\e\[0m/, "Failure message output with ANSI color code" ); >+like( $lines[2], qr/\e\[\d+mTesting success message\e\[0m/, "Success message output with ANSI color code" ); >+like( $lines[3], qr/\e\[\d+mTesting info message\e\[0m/, "Info message output with ANSI color code" ); >+ >+# Remove the temporary file >+unlink $temp_file; >-- >2.44.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35681
:
160439
|
160440
|
160443
|
160444
|
160445
|
160447
|
160448
|
160449
|
160473
|
160503
|
160504
|
160505
|
160506
|
160750
|
160751
|
160772
|
164903
|
164904
|
164905
|
164906
|
164907
|
164908
|
164909
|
164942
|
164943
|
164944
|
164945
|
164946
|
164947
|
164948
|
164949