forked from suchow/Dissertate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdissertate-word.py
41 lines (29 loc) · 1.06 KB
/
dissertate-word.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
#!/usr/bin/env python
import optparse
import importlib
def main():
"""A command line interface for creating Dissertate Word templates."""
p = optparse.OptionParser()
p.add_option("--school", "-s",
action="store", type="string", dest="school")
p.add_option("--name", "--n",
action="store", type="string", dest="name")
options, arguments = p.parse_args()
if not options.name:
options.name = "Firstname M. Lastname"
if not options.school:
options.school = "Generic"
createTemplate(options.school, options.name)
def createTemplate(school, name):
SchoolPackage = importlib.import_module("schools." + school + ".word")
template = SchoolPackage.Template()
template.fill()
for paragraph in template.document.paragraphs:
if "Firstname M. Lastname" in paragraph.text:
style = paragraph.style
template.clear_paragraph(paragraph)
paragraph.add_run(name)
paragraph.style = style
template.save()
if __name__ == "__main__":
main()