all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager v2] vzdump mail: Refactor text part
@ 2020-11-17 10:46 Dominic Jäger
  2020-11-17 13:27 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Dominic Jäger @ 2020-11-17 10:46 UTC (permalink / raw)
  To: pve-devel; +Cc: Thomas Lamprecht

Less lines exeeding the character limit, less nesting, less duplicate code,
more readable sprintf arguments.

Co-authored-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
---
Middle ground sounds good to me :) And separate lines for arguments look nice.
 PVE/VZDump.pm | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index fa387299..59062d2b 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -258,24 +258,26 @@ sub sendmail {
 
     # text part
     my $text = $err ? "$err\n\n" : '';
-    $text .= sprintf ("%-10s %-20s %-6s %10s %10s  %s\n", qw(VMID NAME STATUS TIME SIZE FILENAME));
+    my $namelength = 20;
+    $text .= sprintf (
+	"%-10s %-${namelength}s %-6s %10s %10s  %s\n",
+	qw(VMID NAME STATUS TIME SIZE FILENAME)
+    );
     foreach my $task (@$tasklist) {
-	my $vmid = $task->{vmid};
-	if  ($task->{state} eq 'ok') {
-
-	    $text .= sprintf ("%-10s %-20s %-6s %10s %10s  %s\n", $vmid,
-				substr($task->{hostname}, 0, 20),
-				$task->{state},
-				format_time($task->{backuptime}),
-				format_size ($task->{size}),
-				$task->{target});
-	} else {
-	    $text .= sprintf ("%-10s %-20s %-6s %10s %8.2fMB  %s\n", $vmid,
-				substr($task->{hostname}, 0, 20),
-				$task->{state},
-				format_time($task->{backuptime}),
-				0, '-');
-	}
+	my $name = substr($task->{hostname}, 0, $namelength);
+	my $successful = $task->{state} eq 'ok';
+	my $size = $successful ? format_size ($task->{size}) : 0;
+	my $filename = $successful ? $task->{target} : '-';
+	my $size_fmt = $successful ? "%10s": "%8.2fMB";
+	$text .= sprintf(
+	    "%-10s %-${namelength}s %-6s %10s $size_fmt  %s\n",
+	    $task->{vmid},
+	    $name,
+	    $task->{state},
+	    format_time($task->{backuptime}),
+	    $size,
+	    $filename,
+	);
     }
 
     my $text_log_part;
-- 
2.20.1




^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH manager v2] vzdump mail: Refactor text part
  2020-11-17 10:46 [pve-devel] [PATCH manager v2] vzdump mail: Refactor text part Dominic Jäger
@ 2020-11-17 13:27 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2020-11-17 13:27 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominic Jäger

On 17.11.20 11:46, Dominic Jäger wrote:
> Less lines exeeding the character limit, less nesting, less duplicate code,
> more readable sprintf arguments.
> 
> Co-authored-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
> Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
> ---
> Middle ground sounds good to me :) And separate lines for arguments look nice.
>  PVE/VZDump.pm | 36 +++++++++++++++++++-----------------
>  1 file changed, 19 insertions(+), 17 deletions(-)
> 
>

applied, thanks!





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-17 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 10:46 [pve-devel] [PATCH manager v2] vzdump mail: Refactor text part Dominic Jäger
2020-11-17 13:27 ` [pve-devel] applied: " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal