-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Atanas Gruev
committed
Nov 30, 2023
1 parent
6c577b8
commit 2cbdc8b
Showing
4 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
__all__ = ["PasteTextJob"] | ||
|
||
from typing import List | ||
from i6_core.util import uopen | ||
from sisyphus import * | ||
|
||
|
||
class PasteTextJob(Job): | ||
"""Merges the lines of text files, similar to the 'paste' command""" | ||
|
||
def __init__(self, text_files: List[tk.Path]): | ||
""" | ||
:param text_files: | ||
""" | ||
self.text_files = text_files | ||
|
||
self.out_txt = self.output_path("pasted.txt") | ||
|
||
def tasks(self): | ||
yield Task("run", mini_task=True) | ||
|
||
def run(self): | ||
file_handles = [uopen(text_file, "rt") for text_file in self.text_files] | ||
|
||
with uopen(self.out_txt.get_path(), "wt") as f: | ||
while True: | ||
lines = [fh.readline().strip() for fh in file_handles] | ||
if any(line == "" for line in lines): | ||
break | ||
|
||
f.write(" ".join(lines)) | ||
if not all(line == "" for line in lines): | ||
f.write("\n") | ||
|
||
for fh in file_handles: | ||
fh.close() |