From ebe34400325901a43e42c35fb9ad74f6c6ec0a6f Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Thu, 16 Jan 2025 14:48:27 -0800 Subject: [PATCH] Remove all options from cat utility --- micall/drivers/sample.py | 3 +-- micall/utils/cat.py | 38 ++++++++++---------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/micall/drivers/sample.py b/micall/drivers/sample.py index 8f8fd33db..ffa8f4051 100644 --- a/micall/drivers/sample.py +++ b/micall/drivers/sample.py @@ -437,8 +437,7 @@ def run_denovo(self, excluded_seeds): concatenate_files(inputs=[self.unstitched_contigs_fasta, self.merged_contigs_fasta], - output=self.combined_contigs_fasta, - text=True, ignore_not_found=True) + output=self.combined_contigs_fasta) with open(self.combined_contigs_fasta, 'r') as combined_contigs_fasta, \ open(self.stitched_contigs_fasta, 'w') as stitched_contigs_fasta: diff --git a/micall/utils/cat.py b/micall/utils/cat.py index 3edd6e7d5..cd092f218 100644 --- a/micall/utils/cat.py +++ b/micall/utils/cat.py @@ -19,12 +19,7 @@ from typing import Iterable, Sequence -def cat(inputs: Iterable[Path], - output: Path, - text: bool, - ignore_not_found: bool, - ) -> int: - +def cat(inputs: Iterable[Path], output: Path) -> int: """ Concatenates the contents of input inputs and writes the result to an output file. @@ -42,40 +37,27 @@ def cat(inputs: Iterable[Path], for file in inputs: try: with open(file) as f: - if text: - for line in f: - out.write(line) - else: - shutil.copyfileobj(f, out) + shutil.copyfileobj(f, out) except FileNotFoundError: - if ignore_not_found: - continue - else: - print(f"The file {str(file)!r} was not found." - " Please check the file path and try again.", - file=sys.stderr) - raise - return 1 + print(f"The file {str(file)!r} was not found." + " Please check the file path and try again.", + file=sys.stderr) + return 1 except IOError as e: print(f"IO Error while processing the file {str(file)!r}: {e}", file=sys.stderr) - raise return 1 + + return 0 except BaseException as e: print(f"An unexpected error occurred: {e}", file=sys.stderr) - raise - return 1 + return 1 def main(argv: Sequence[str]) -> int: parser = argparse.ArgumentParser( description="Concatenate inputs and write to an output file.") - parser.add_argument('--text', action='store_true', - help='Operate on text inputs.') - parser.add_argument('--ignore-not-found', action='store_true', - help='Treat non-existant inputs as empty.') - parser.add_argument( 'inputs', metavar='FILE', @@ -92,7 +74,7 @@ def main(argv: Sequence[str]) -> int: ) args = parser.parse_args(argv) - return cat(args.inputs, args.output, args.text, args.ignore_not_found) + return cat(args.inputs, args.output) def entry() -> None: