aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-05-19 10:25:18 +0300
committerFrederick Muriuki Muriithi2022-05-19 15:23:47 +0300
commit27f6e9e28f2a3244bdd00336cf918de97b2ceed6 (patch)
tree35ad7aeea324b0cbe60c44d652b4a5387321f4bd /scripts
parent6865d8621e6fadb915813951068ee950c781ee0d (diff)
downloadgn-uploader-27f6e9e28f2a3244bdd00336cf918de97b2ceed6.tar.gz
Extract progress indication from the parsing
Since progress indication is not part of the parsing, this commit extracts the progress indication into functions with well defined input arguments that hide the progress indication logic from the parsing function.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qc.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/scripts/qc.py b/scripts/qc.py
index 9d57f4b..9bad55e 100644
--- a/scripts/qc.py
+++ b/scripts/qc.py
@@ -2,10 +2,12 @@
import os
import sys
import argparse
+from typing import Union, Callable
import magic
from quality_control.errors import InvalidValue
+from quality_control.utils import make_progress_calculator
from quality_control.parsing import (
take,
FileType,
@@ -54,10 +56,18 @@ def cli_argument_parser():
default=False, action="store_true")
return parser
-def progress_indicator(msg):
+def make_progress_indicator(
+ verbose: bool, progress_calc_fn: Callable) -> Union[Callable, None]:
"""Utility to display the progress"""
- print(f"LINE: {msg['line_number']} ({msg['percent']:.2f}%)", end="\r")
- return msg
+ if not verbose:
+ return None
+
+ def __indicator__(linenumber, linetext):
+ msg = progress_calc_fn(linenumber, linetext)
+ print(f"LINE: {msg.currentline} ({msg.percent:.2f}%)", end="\r")
+ return msg
+
+ return __indicator__
def print_errors(errors, verbose):
"""Print out the errors"""
@@ -78,8 +88,8 @@ def print_errors(errors, verbose):
def check(filepath, filetype, strains, count, verbose=False):
"""Check the file and print out results"""
- if verbose:
- updater = progress_indicator
+ updater = make_progress_indicator(
+ verbose, make_progress_calculator(os.stat(filepath).st_size))
if count > 0:
return print_errors(