-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_watch
executable file
·98 lines (85 loc) · 2.78 KB
/
file_watch
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
92
93
94
95
96
97
98
#!/usr/bin/python3
import latex_watch
import pandoc_watch
import sys
import os
from threading import Thread
from typing import List, Tuple, Dict, Any, Callable
ProcessedArgs = Dict[str, Any]
MainForFileMethod = Callable[[ProcessedArgs], None]
FilePair = Tuple[MainForFileMethod, ProcessedArgs]
def processargs(
argv: List[str],
) -> List[FilePair]:
output = list() # type: List[FilePair]
dashArguments = False
markdownFiles = False
latexFiles = False
# Skip the name of the program
for arg in argv[1:]:
if arg[0] == '-':
dashArguments = True
elif '.md' in arg[-3:]:
markdownFiles = True
elif '.tex' in arg[-4:]:
latexFiles = True
if not dashArguments and len(argv) > 1:
for arg in argv[1:]:
if '.md' in arg[-3:]:
output.append(
(
pandoc_watch.main_for_file,
pandoc_watch.processargs([argv[0], arg])
)
)
elif '.tex' in arg[-4:]:
output.append(
(
latex_watch.main_for_file,
latex_watch.processargs([argv[0], arg])
)
)
elif markdownFiles and latexFiles:
exit(1)
elif markdownFiles:
output.append(
(
pandoc_watch.main_for_file,
pandoc_watch.processargs(argv)
)
)
elif latexFiles:
output.append(
(
latex_watch.main_for_file,
latex_watch.processargs(argv)
)
)
else:
# No file name given
for file_name in os.listdir():
if len(file_name) > 9 and file_name[0] == '.' and \
file_name[-8:] == '.tex.swp':
output.append(
(
latex_watch.main_for_file,
latex_watch.processargs(argv + [file_name[1:-4]])
)
)
if len(file_name) > 8 and file_name[0] == '.' and \
file_name[-7:] == '.md.swp':
output.append(
(
pandoc_watch.main_for_file,
pandoc_watch.processargs(argv + [file_name[1:-4]])
)
)
return output
def launchWatches(mainsAndArgs: List[FilePair]) -> None:
for mainAndArgPair in mainsAndArgs:
Thread(
target=mainAndArgPair[0],
args=tuple([mainAndArgPair[1]]),
).start()
if __name__ == '__main__':
launchWatches(processargs(sys.argv))