File 0001-Bugfix-for-summary.patch of Package flac2all

From a7d367928c9e22b3bc2d27359b64de5d169d7e75 Mon Sep 17 00:00:00 2001
From: zv <info@ziva-vatra.com>
Date: Thu, 27 Feb 2020 14:46:51 +0000
Subject: [PATCH 1/5] Bugfix for summary

---
 flac2all_pkg/core.py                | 60 +++++++++++++++++------------
 flac2all_pkg/multiprocess_encode.py | 25 ++++++------
 flac2all_pkg/shell.py               |  3 +-
 3 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/flac2all_pkg/core.py b/flac2all_pkg/core.py
index 86dd185..572edf0 100755
--- a/flac2all_pkg/core.py
+++ b/flac2all_pkg/core.py
@@ -6,23 +6,23 @@ if __name__ == '__main__' and __package__ is None:
     sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
 
 try:
-	from aac import aacplus
-	from vorbis import vorbis
-	from flac import flac
-	from mp3 import lameMp3 as mp3
-	from opus import opus
-	from ffmpeg import ffmpeg
-	from shell import filecopy
-	from logging import console
+    from aac import aacplus
+    from vorbis import vorbis
+    from flac import flac
+    from mp3 import lameMp3 as mp3
+    from opus import opus
+    from ffmpeg import ffmpeg
+    from shell import filecopy
+    from logging import console
 except ImportError:
-	from .aac import aacplus
-	from .vorbis import vorbis
-	from .flac import flac
-	from .mp3 import lameMp3 as mp3
-	from .opus import opus
-	from .ffmpeg import ffmpeg
-	from .shell import filecopy
-	from .logging import console
+    from .aac import aacplus
+    from .vorbis import vorbis
+    from .flac import flac
+    from .mp3 import lameMp3 as mp3
+    from .opus import opus
+    from .ffmpeg import ffmpeg
+    from .shell import filecopy
+    from .logging import console
 
 import threading as mt
 
@@ -76,7 +76,10 @@ def signal_handler(signal, frame):
     terminate = True
 
 
-def print_summary(count, total, percentage_execution_rate, successes, failures, percentage_fail, modes):
+def print_summary(count, total, successes, failures, modes, percentage_fail, total_execution_time, percentage_execution_rate):
+    percentage_fail = float(percentage_fail)
+    percentage_execution_rate = float(percentage_execution_rate)
+
     out = "\n\n"
     out += ("=" * 80)
     out += "| Summary "
@@ -89,13 +92,15 @@ Execution rate: %.2f%%
 Files we managed to convert successfully: %d
 Files we failed to convert due to errors: %d
 --
-Conversion error rate: %.2f%%
-""" % (count, total, (
+Conversion error rate: %s%%
+""" % (
+        count,
+        total,
         percentage_execution_rate,
         successes,
         failures,
-        (percentage_fail)
-    ))
+        percentage_fail
+    )
     for mode in modes:
         execT, esum, emean, emedian = modes[mode]
         log.print("For mode: " + mode)
@@ -107,13 +112,13 @@ Conversion error rate: %.2f%%
         else:
             etime += "%.4f hours" % (esum / 60 / 60)
         out += "\tTotal execution time: %s" % etime
-    out += """
+        out += """
 Per file conversion:
 \tMean execution time: %.4f seconds
 \tMedian execution time: %.4f seconds
 """ % (emean, emedian)
 
-    return out
+    print(out)
 
 
 def generate_summary(start_time, end_time, count, results):
@@ -135,6 +140,9 @@ def generate_summary(start_time, end_time, count, results):
     for mode in list(modes):
         # 1. find all the logs corresponding to a particular mode
         x = [x for x in results if x[2] == mode]
+        # 1.1  If no results, just continue
+        if len(x) == 0:
+            continue
         # 2. Get the execution time for all relevant logs.
         #    -1 times are events which were no-ops (either due to errors or
         #    file already existing when overwrite == false), and are filtered out
@@ -146,6 +154,9 @@ def generate_summary(start_time, end_time, count, results):
             esum = 0
             emean = 0
         execT.sort()
+        # If we have no execution times that are valid, skip
+        if len(execT) == 0:
+            continue
         if len(execT) % 2 != 0:
             # Odd number, so median is middle
             emedian = execT[int((len(execT) - 1) / 2)]
@@ -158,6 +169,7 @@ def generate_summary(start_time, end_time, count, results):
 
     total_execution_time = (end_time - start_time)
     return (
+        count,
         total,
         successes,
         failures,
@@ -169,7 +181,7 @@ def generate_summary(start_time, end_time, count, results):
 
 
 def write_logfile(outdir, results):
-    errout_file = outdir + "/conversion_results.log"
+    errout_file = os.path.join(outdir, "conversion_results.log")
     log.info("Writing log file (%s)" % errout_file)
     fd = open(errout_file, "w")
     fd.write(
diff --git a/flac2all_pkg/multiprocess_encode.py b/flac2all_pkg/multiprocess_encode.py
index d8f0841..8644f4a 100755
--- a/flac2all_pkg/multiprocess_encode.py
+++ b/flac2all_pkg/multiprocess_encode.py
@@ -30,7 +30,6 @@
 
 
 import multiprocessing as mp
-from shutil import copy as copytarget
 import sys
 import os
 import time
@@ -41,16 +40,15 @@ if __name__ == '__main__' and __package__ is None:
     sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
 
 try:
-	from config import opts
-	from core import encode_thread, generate_summary
-	from shell import shell
-	from logging import console
+    from config import opts
+    from core import encode_thread, generate_summary, print_summary, write_logfile
+    from shell import shell
+    from logging import console
 except ImportError:
-	from .config import opts
-	from .core import encode_thread, generate_summary
-	from .shell import shell
-	from .logging import console
-
+    from .config import opts
+    from .core import encode_thread, generate_summary
+    from .shell import shell
+    from .logging import console
 
 
 log = console(stderr=True)
@@ -138,7 +136,6 @@ def encode():
             command = cQ.get(timeout=10)
             srcfile, srcroot, dest, encformat = command
             outdir = sh.generateoutdir(srcfile, os.path.join(dest, encformat), srcroot)
-            copytarget(srcfile, outdir)
             log.info(("%s => %s" % (srcfile, outdir)))
         except mp.TimeoutError as e:
             sflags[1] = 1
@@ -185,9 +182,11 @@ def encode():
     while not lQ.empty():
         result_log.append(lQ.get(timeout=2))
 
-    failures = generate_summary(start_time, end_time, len(files), result_log, opts['outdir'])
+    results = generate_summary(start_time, end_time, len(files), result_log)
+    print_summary(*results)
+    write_logfile(opts['outdir'], result_log)
 
-    if failures != 0:
+    if results[3] != 0:
         log.crit("We had some failures in encoding :-(")
         log.crit("Check conversion log file for info.")
         log.crit("Done! Returning non-zero exit status! ")
diff --git a/flac2all_pkg/shell.py b/flac2all_pkg/shell.py
index 18f6e3e..3f17332 100644
--- a/flac2all_pkg/shell.py
+++ b/flac2all_pkg/shell.py
@@ -1,7 +1,6 @@
 # -*- coding: utf-8 -*-
 # vim ts=4 expandtab si
 import os
-import string
 
 from shutil import copyfile
 
@@ -42,7 +41,7 @@ class shell:
 		# it with the new output path. (so that we don't get
 		# /mnt/convertedfromflac/mnt/flac/[file].mp3, in this case
 		# "/mnt/" exist in both)
-		if (string.find(os.path.split(indir)[0], dirpath) != -1):
+		if (str.find(os.path.split(indir)[0], dirpath) != -1):
 			return os.path.split(indir)[0].replace(dirpath, outdir)
 		else:
 			# if we do not find an instance of dir path in output
-- 
2.25.1

openSUSE Build Service is sponsored by