Skip to content

Commit

Permalink
Remove all options from cat utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Jan 16, 2025
1 parent 8fb4f7d commit ebe3440
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 30 deletions.
3 changes: 1 addition & 2 deletions micall/drivers/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 10 additions & 28 deletions micall/utils/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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',
Expand All @@ -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:
Expand Down

0 comments on commit ebe3440

Please sign in to comment.