Commit be07ae4e authored by Vinit Veera's avatar Vinit Veera
Browse files

Added a function to reorder the items list bsed on concatenation order and...

Added a function to reorder the items list bsed on concatenation order and made the corresponding changes.
parent e007ca5c
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ DEFAULT_CONFIG = {
    "multiprocessing": True,
    "delete_tmp": False,
    "concatenate_input": False,
    "concatenation_order": None,
    "concat_silence": {
        "pre": 0,
        "post": 0,
+16 −0
Original line number Diff line number Diff line
@@ -59,7 +59,23 @@ class Processing(ABC):
        pass


def reorder_files(items_list: list, concatenation_order: list) -> list:
    name_to_full = {Path(full_file).name: full_file for full_file in items_list}
    ordered_full_files = [
        name_to_full[name] for name in concatenation_order if name in name_to_full
    ]
    return ordered_full_files


def concat_setup(cfg: TestConfig, logger: logging.Logger):
    n_items_list = len(cfg.items_list)
    if cfg.concatenation_order is not None:
        n_concatenation_order = len(cfg.concatenation_order)
        if n_concatenation_order != n_items_list:
            warn(
                f"Warning: Mismatch in specified concatenation order and number of items to process!\nNumber of items specified in concatenation order: {n_concatenation_order}\nNumber of items in the directory: {n_items_list}\nConcatenation will use the following order:\n{cfg.concatenation_order}"
            )
        cfg.items_list = reorder_files(cfg.items_list, cfg.concatenation_order)
    if any([i for i in cfg.items_list if i.suffix == ".txt"]):
        raise SystemExit("Concatenation for text files is unsupported")