|
|
e76f14 |
From b7dd708d309d86625e3d6cb2f479bed5e5b55ee1 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Wed, 29 Jun 2016 12:51:39 +0100
|
|
|
e76f14 |
Subject: [PATCH] p2v: Colourize kernel-conversion status messages from
|
|
|
e76f14 |
virt-p2v.
|
|
|
e76f14 |
|
|
|
e76f14 |
The messages that come "through" from virt-v2v are already colourized.
|
|
|
e76f14 |
However the other messages are not. This colourizes the ones
|
|
|
e76f14 |
generated during kernel-mode conversions.
|
|
|
e76f14 |
|
|
|
e76f14 |
Note that because of the way journal/syslog works we have to write the
|
|
|
e76f14 |
ansi_restore before the end of line, thus code like this:
|
|
|
e76f14 |
|
|
|
e76f14 |
ansi_magenta (stdout);
|
|
|
e76f14 |
printf ("%s: %s", guestfs_int_program_name, data);
|
|
|
e76f14 |
ansi_restore (stdout);
|
|
|
e76f14 |
putchar ('\n');
|
|
|
e76f14 |
|
|
|
e76f14 |
This also adds a "Conversion finished successfully" message (in green).
|
|
|
e76f14 |
|
|
|
e76f14 |
Thanks: Ming Xie
|
|
|
e76f14 |
(cherry picked from commit b15b6e69e37cb3b6520d301442a67b9971ae8d51)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
p2v/kernel.c | 23 +++++++++++++++++++----
|
|
|
e76f14 |
p2v/launch-virt-p2v.in | 4 ++--
|
|
|
e76f14 |
p2v/main.c | 12 ++++++++++++
|
|
|
e76f14 |
p2v/p2v.h | 3 +++
|
|
|
e76f14 |
p2v/virt-p2v.pod | 9 +++++++++
|
|
|
e76f14 |
5 files changed, 45 insertions(+), 6 deletions(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/p2v/kernel.c b/p2v/kernel.c
|
|
|
e76f14 |
index 6d9388b..6914ab5 100644
|
|
|
e76f14 |
--- a/p2v/kernel.c
|
|
|
e76f14 |
+++ b/p2v/kernel.c
|
|
|
e76f14 |
@@ -250,6 +250,11 @@ kernel_conversion (struct config *config, char **cmdline, int cmdline_source)
|
|
|
e76f14 |
exit (EXIT_FAILURE);
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
+ ansi_green (stdout);
|
|
|
e76f14 |
+ printf ("Conversion finished successfully.");
|
|
|
e76f14 |
+ ansi_restore (stdout);
|
|
|
e76f14 |
+ putchar ('\n');
|
|
|
e76f14 |
+
|
|
|
e76f14 |
p = get_cmdline_key (cmdline, "p2v.post");
|
|
|
e76f14 |
if (!p) {
|
|
|
e76f14 |
if (geteuid () == 0 && cmdline_source == CMDLINE_SOURCE_PROC_CMDLINE)
|
|
|
e76f14 |
@@ -264,8 +269,12 @@ notify_ui_callback (int type, const char *data)
|
|
|
e76f14 |
{
|
|
|
e76f14 |
switch (type) {
|
|
|
e76f14 |
case NOTIFY_LOG_DIR:
|
|
|
e76f14 |
- printf ("%s: remote log directory location: %s\n",
|
|
|
e76f14 |
- guestfs_int_program_name, data);
|
|
|
e76f14 |
+ ansi_magenta (stdout);
|
|
|
e76f14 |
+ printf ("%s: remote log directory location: ", guestfs_int_program_name);
|
|
|
e76f14 |
+ ansi_red (stdout);
|
|
|
e76f14 |
+ fputs (data, stdout);
|
|
|
e76f14 |
+ ansi_restore (stdout);
|
|
|
e76f14 |
+ putchar ('\n');
|
|
|
e76f14 |
break;
|
|
|
e76f14 |
|
|
|
e76f14 |
case NOTIFY_REMOTE_MESSAGE:
|
|
|
e76f14 |
@@ -273,12 +282,18 @@ notify_ui_callback (int type, const char *data)
|
|
|
e76f14 |
break;
|
|
|
e76f14 |
|
|
|
e76f14 |
case NOTIFY_STATUS:
|
|
|
e76f14 |
- printf ("%s: %s\n", guestfs_int_program_name, data);
|
|
|
e76f14 |
+ ansi_magenta (stdout);
|
|
|
e76f14 |
+ printf ("%s: %s", guestfs_int_program_name, data);
|
|
|
e76f14 |
+ ansi_restore (stdout);
|
|
|
e76f14 |
+ putchar ('\n');
|
|
|
e76f14 |
break;
|
|
|
e76f14 |
|
|
|
e76f14 |
default:
|
|
|
e76f14 |
- printf ("%s: unknown message during conversion: type=%d data=%s\n",
|
|
|
e76f14 |
+ ansi_red (stdout);
|
|
|
e76f14 |
+ printf ("%s: unknown message during conversion: type=%d data=%s",
|
|
|
e76f14 |
guestfs_int_program_name, type, data);
|
|
|
e76f14 |
+ ansi_restore (stdout);
|
|
|
e76f14 |
+ putchar ('\n');
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
fflush (stdout);
|
|
|
e76f14 |
diff --git a/p2v/launch-virt-p2v.in b/p2v/launch-virt-p2v.in
|
|
|
e76f14 |
index 3e4f1f9..ca971a0 100755
|
|
|
e76f14 |
--- a/p2v/launch-virt-p2v.in
|
|
|
e76f14 |
+++ b/p2v/launch-virt-p2v.in
|
|
|
e76f14 |
@@ -23,7 +23,7 @@
|
|
|
e76f14 |
cmdline=$(
|
|
|
e76f14 |
if [[ $cmdline == *p2v.server=* ]]; then
|
|
|
e76f14 |
# Non-GUI mode, don't run X. Just run virt-p2v directly.
|
|
|
e76f14 |
- exec @libexecdir@/virt-p2v --iso
|
|
|
e76f14 |
+ exec @libexecdir@/virt-p2v --iso --colours
|
|
|
e76f14 |
|
|
|
e76f14 |
else
|
|
|
e76f14 |
# GUI mode. Run xinit to start X. To save one script, we invoke
|
|
|
e76f14 |
@@ -32,7 +32,7 @@ else
|
|
|
e76f14 |
cd /
|
|
|
e76f14 |
metacity &
|
|
|
e76f14 |
nm-applet &
|
|
|
e76f14 |
- exec @libexecdir@/virt-p2v --iso
|
|
|
e76f14 |
+ exec @libexecdir@/virt-p2v --iso --colours
|
|
|
e76f14 |
else
|
|
|
e76f14 |
xinit "$0" run
|
|
|
e76f14 |
fi
|
|
|
e76f14 |
diff --git a/p2v/main.c b/p2v/main.c
|
|
|
e76f14 |
index 99d0011..c5ab233 100644
|
|
|
e76f14 |
--- a/p2v/main.c
|
|
|
e76f14 |
+++ b/p2v/main.c
|
|
|
e76f14 |
@@ -43,6 +43,7 @@ char **all_removable;
|
|
|
e76f14 |
char **all_interfaces;
|
|
|
e76f14 |
int is_iso_environment = 0;
|
|
|
e76f14 |
int feature_colours_option = 0;
|
|
|
e76f14 |
+int force_colour = 0;
|
|
|
e76f14 |
|
|
|
e76f14 |
static void udevadm_settle (void);
|
|
|
e76f14 |
static void set_config_defaults (struct config *config);
|
|
|
e76f14 |
@@ -55,6 +56,10 @@ static const char options[] = "Vv";
|
|
|
e76f14 |
static const struct option long_options[] = {
|
|
|
e76f14 |
{ "help", 0, 0, HELP_OPTION },
|
|
|
e76f14 |
{ "cmdline", 1, 0, 0 },
|
|
|
e76f14 |
+ { "color", 0, 0, 0 },
|
|
|
e76f14 |
+ { "colors", 0, 0, 0 },
|
|
|
e76f14 |
+ { "colour", 0, 0, 0 },
|
|
|
e76f14 |
+ { "colours", 0, 0, 0 },
|
|
|
e76f14 |
{ "iso", 0, 0, 0 },
|
|
|
e76f14 |
{ "long-options", 0, 0, 0 },
|
|
|
e76f14 |
{ "short-options", 0, 0, 0 },
|
|
|
e76f14 |
@@ -77,6 +82,7 @@ usage (int status)
|
|
|
e76f14 |
"Options:\n"
|
|
|
e76f14 |
" --help Display brief help\n"
|
|
|
e76f14 |
" --cmdline=CMDLINE Used to debug command line parsing\n"
|
|
|
e76f14 |
+ " --colours Use ANSI colour sequences even if not tty\n"
|
|
|
e76f14 |
" --iso Running in the ISO environment\n"
|
|
|
e76f14 |
" -v|--verbose Verbose messages\n"
|
|
|
e76f14 |
" -V|--version Display version and exit\n"
|
|
|
e76f14 |
@@ -158,6 +164,12 @@ main (int argc, char *argv[])
|
|
|
e76f14 |
cmdline = parse_cmdline_string (optarg);
|
|
|
e76f14 |
cmdline_source = CMDLINE_SOURCE_COMMAND_LINE;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
+ else if (STREQ (long_options[option_index].name, "color") ||
|
|
|
e76f14 |
+ STREQ (long_options[option_index].name, "colour") ||
|
|
|
e76f14 |
+ STREQ (long_options[option_index].name, "colors") ||
|
|
|
e76f14 |
+ STREQ (long_options[option_index].name, "colours")) {
|
|
|
e76f14 |
+ force_colour = 1;
|
|
|
e76f14 |
+ }
|
|
|
e76f14 |
else if (STREQ (long_options[option_index].name, "iso")) {
|
|
|
e76f14 |
is_iso_environment = 1;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
diff --git a/p2v/p2v.h b/p2v/p2v.h
|
|
|
e76f14 |
index 3e75690..52d5ccb 100644
|
|
|
e76f14 |
--- a/p2v/p2v.h
|
|
|
e76f14 |
+++ b/p2v/p2v.h
|
|
|
e76f14 |
@@ -61,6 +61,9 @@ extern int is_iso_environment;
|
|
|
e76f14 |
/* True if virt-v2v supports the --colours option. */
|
|
|
e76f14 |
extern int feature_colours_option;
|
|
|
e76f14 |
|
|
|
e76f14 |
+/* virt-p2v --colours option (used by ansi_* macros). */
|
|
|
e76f14 |
+extern int force_colour;
|
|
|
e76f14 |
+
|
|
|
e76f14 |
/* config.c */
|
|
|
e76f14 |
struct config {
|
|
|
e76f14 |
int verbose;
|
|
|
e76f14 |
diff --git a/p2v/virt-p2v.pod b/p2v/virt-p2v.pod
|
|
|
e76f14 |
index 421925f..247acce 100644
|
|
|
e76f14 |
--- a/p2v/virt-p2v.pod
|
|
|
e76f14 |
+++ b/p2v/virt-p2v.pod
|
|
|
e76f14 |
@@ -591,6 +591,15 @@ Display help.
|
|
|
e76f14 |
This is used for debugging. Instead of parsing the kernel command line
|
|
|
e76f14 |
from F</proc/cmdline>, parse the string parameter C<CMDLINE>.
|
|
|
e76f14 |
|
|
|
e76f14 |
+=item B<--colors>
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+=item B<--colours>
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+Use ANSI colour sequences to colourize messages. This is the default
|
|
|
e76f14 |
+when the output is a tty. If the output of the program is redirected
|
|
|
e76f14 |
+to a file, ANSI colour sequences are disabled unless you use this
|
|
|
e76f14 |
+option.
|
|
|
e76f14 |
+
|
|
|
e76f14 |
=item B<--iso>
|
|
|
e76f14 |
|
|
|
e76f14 |
This flag is passed to virt-p2v when it is launched inside the
|
|
|
e76f14 |
--
|
|
|
7af31e |
1.8.3.1
|
|
|
e76f14 |
|