Skip to content

Commit 55be044

Browse files
committed
Additional changes for consistency with Machine
1 parent 7a284d9 commit 55be044

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

machine/corpora/file_paratext_project_file_handler.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,29 @@ def __init__(self, project_dir: StrPath) -> None:
1212
self._project_dir = Path(project_dir)
1313

1414
def exists(self, file_name: str) -> bool:
15-
for actual_file_name in os.listdir(self._project_dir):
16-
if actual_file_name.lower() == file_name.lower():
17-
return True
18-
return False
15+
return self._get_file_name(file_name) is not None
1916

2017
def open(self, file_name: str) -> BinaryIO:
21-
for actual_file_name in os.listdir(self._project_dir):
22-
if actual_file_name.lower() == file_name.lower():
23-
return open(self._project_dir / actual_file_name, "rb")
18+
actual_file_name = self._get_file_name(file_name)
19+
if actual_file_name is not None:
20+
file_name = actual_file_name
2421
return open(self._project_dir / file_name, "rb")
2522

2623
def find(self, extension: str) -> Optional[Path]:
2724
return next(self._project_dir.glob(f"*{extension}"), None)
2825

2926
def create_stylesheet(self, file_name: str) -> UsfmStylesheet:
30-
custom_stylesheet_file_name = "custom.sty"
31-
for actual_file_name in os.listdir(self._project_dir):
32-
if actual_file_name.lower() == custom_stylesheet_file_name:
33-
custom_stylesheet_file_name = actual_file_name
34-
break
27+
custom_stylesheet_file_name = self._get_file_name("custom.sty")
28+
if custom_stylesheet_file_name is None:
29+
custom_stylesheet_file_name = "custom.sty"
3530
custom_stylesheet_path = self._project_dir / custom_stylesheet_file_name
3631
return UsfmStylesheet(
3732
file_name,
3833
custom_stylesheet_path if custom_stylesheet_path.is_file() else None,
3934
)
35+
36+
def _get_file_name(self, case_insensitive_file_name: str) -> Optional[str]:
37+
for actual_file_name in os.listdir(self._project_dir):
38+
if actual_file_name.lower() == case_insensitive_file_name.lower():
39+
return actual_file_name
40+
return None

machine/corpora/paratext_backup_terms_corpus.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ def __init__(self, filename: StrPath, term_categories: Sequence[str], use_term_g
2929
text = MemoryText(
3030
text_id,
3131
[
32-
TextRow(text_id, key_term.id, key_term.renderings, content_type=TextRowContentType.WORD)
32+
TextRow(text_id, key_term.id, [rendering], content_type=TextRowContentType.WORD)
3333
for key_term in key_terms
34+
for rendering in key_term.renderings
3435
],
3536
)
3637
self._add_text(text)

0 commit comments

Comments
 (0)