-
Notifications
You must be signed in to change notification settings - Fork 0
/
spellcheck.py
executable file
·91 lines (71 loc) · 2.17 KB
/
spellcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
from os import listdir, chdir, system
from subprocess import check_output, Popen, PIPE
from os.path import isdir, join, dirname, realpath
from dataclasses import dataclass
from typing import List
@dataclass
class Files:
tex_files: List[str]
dirs: List[str]
pass
def list_tex_files(root: str) -> List[str]:
files = []
for file in listdir(root):
file_path = join(root, file)
if isdir(file_path):
files = files + list_tex_files(file_path)
elif file_path.endswith(".tex"):
files.append(file_path)
return files
chdir(dirname(realpath(__file__)))
tex_files = list_tex_files("content")
tex_files.append("master_thesis.tex")
en_aspell_dicts = [
"technical/spelling/aspell.en.prepl",
"technical/spelling/aspell.en.pws"
]
pl_aspell_dicts = [
"technical/spelling/aspell.pl.prepl"
]
errors = []
print("Spell checking:\n" + "\n".join(tex_files))
print("\n")
all_errors = ""
for tex_file in tex_files:
get_file_content = Popen([
"cat",
tex_file
], stdout=PIPE)
first_check_english = Popen([
"aspell",
"list",
"--mode=tex",
"--lang=en",
"--add-extra-dicts", "./technical/spelling/aspell.en.prepl",
"--add-extra-dicts", "./technical/spelling/aspell.en.pws"
], stdout=PIPE, stdin=get_file_content.stdout)
then_check_polish = Popen([
"aspell",
"list",
"--mode=tex",
"--lang=pl",
"--add-extra-dicts", "./technical/spelling/special.pl.pws"
], stdin=first_check_english.stdout, stdout=PIPE)
errors = then_check_polish.communicate()[0].decode()
all_errors = all_errors + errors
if len(errors) == 0: continue
print(f"File: {tex_file}")
print(errors)
print("\n")
system(" ".join([
"aspell",
"check",
"--mode=tex",
"--add-extra-dicts", "./technical/spelling/aspell.en.prepl",
"--add-extra-dicts", "./technical/spelling/aspell.en.pws",
"--add-extra-dicts", "./technical/spelling/special.enpl.pws",
tex_file
]))
if len(all_errors) == 0:
print("Project spelling is correct. No mistakes found")