-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeslides.py
executable file
·68 lines (59 loc) · 2.4 KB
/
makeslides.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
#!/usr/bin/env python3
from __future__ import print_function
from plumbum import local, cli, FG, colors, ProcessExecutionError
from plumbum.path.utils import gui_open
class Doc(object):
def __init__(self, filename, ext):
self.filename = filename
self.input = filename.with_suffix(ext)
self.output = filename.with_suffix('.pdf')
self.name = filename.with_suffix('').basename
def exists(self):
return self.input.exists()
def needs_update(self):
if not self.output.exists():
return True
return self.input.stat().st_mtime > self.output.stat().st_mtime
def open(self):
try:
gui_open(self.output)
except ProcessExecutionError:
pass
class MakeSlides(cli.Application):
'Make slides from all available files in current directory'
@cli.positional(cli.ExistingFile)
def main(self, *filenames):
if not filenames:
filenames = local.cwd // ('*.md', '*.tex')
filenames = [f for f in filenames if 'README.md' != f.name]
auto = True
else:
auto = False
for fname in filenames:
document = Doc(fname, '.md')
if document.exists() and (document.needs_update() or not auto):
colors.info.print("Making", document.name, "with pandoc")
local['pandoc']['-t', 'beamer',
'--template=presentation.beamer',
'--pdf-engine=lualatex',
document.input,
'-o', document.output] & FG
document.open()
else:
document = Doc(fname, '.tex')
if document.exists() and (document.needs_update() or not auto):
colors.info.print("Making", document.name, "with latex")
local['latexmk']['-pdf', document.input] & FG
document.open()
generated = ('*.aux', '*.bcf', '*.fls', '*.idx', '*.ind', '*.lof', '*.lot',
'*.out', '*.toc', '*.blg', '*.ilg', '*.log',
'aux.bak', 'idx.bak', 'texput.log', 'texput.aux',
'*.synctex.gz*', '*.nav', '*.snm',
'*.fdb_latexmk')
for gen in generated:
files = (local.cwd // gen)
if files:
for f in files:
f.delete()
if __name__ == '__main__':
MakeSlides()