Newer
Older
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
from typing import Dict
import click
TEMPLATE_START = '{%'
TEMPLATE_END = '%}'
GERMAN = {
'DOCUMENT_CLASS_LANG': ', ngerman',
'DOCUMENT_LANGUAGE': 'ngerman',
'TITLE_PAGE_COMMENT': 'TITELSEITE',
'TITLE_DEPARTEMENT_NAME': 'Institut für Informatik',
'TITLE_GROUP_NAME': 'Datenbanken und Informationssysteme',
'TITLE_FOOTER_MASTER': 'Masterarbeit',
'TITLE_FOOTER_BACHELOR': 'Bachelorarbeit',
'TITLE_SUPERVISED_BY': 'betreut von',
'STATUTORY_DECLARATION_COMMENT': 'Eidesstattliche Erklärung',
'GERMAN_ABSTRACT_COMMENT': 'ZUSAMMENFASSUNG',
'ENGLISH_ABSTRACT_COMMENT': 'ABSTRACT',
'ACKNOWLEDGEMENTS_COMMENT': 'DANKSAGUNG',
'TABLE_OF_CONTENTS_COMMENT': 'INHALTSVERZEICHNIS',
'CHAPTER_COMMENT': 'KAPITEL',
'CHAPTER_1_NAME': 'Einleitung',
'CHAPTER_2_NAME': 'Kapitel 2',
'SECTION_COMMENT': 'ABSCHNITT',
'SECTION_NAME': 'Abschnitt',
'SUB_SECTION_NAME': 'Teilabschnitt',
'APPENDIX_COMMENT': 'ANHANG',
'APPENDIX_TITLE': 'Anhang',
'APPENDIX_SECTION_NAME': 'Anhang Abschnitt',
'BIBLIOGRAPHY_COMMENT': 'LITERATURVERZEICHNIS',
'BIBLIOGRAHPY_TITLE': 'Literaturverzeichnis',
}
ENGLISH = {
'DOCUMENT_CLASS_LANG': '',
'DOCUMENT_LANGUAGE': 'english',
'TITLE_PAGE_COMMENT': 'TITLEPAGE',
'TITLE_DEPARTEMENT_NAME': 'Department of Computer Science',
'TITLE_GROUP_NAME': 'Databases and Information Systems',
'TITLE_FOOTER_MASTER': 'Master Thesis',
'TITLE_FOOTER_BACHELOR': 'Bachelor Thesis',
'TITLE_SUPERVISED_BY': 'supervised by',
'STATUTORY_DECLARATION_COMMENT': 'STATUTORY DECLARATION',
'GERMAN_ABSTRACT_COMMENT': 'german ABSTRACT',
'ENGLISH_ABSTRACT_COMMENT': 'ABSTRACT',
'ACKNOWLEDGEMENTS_COMMENT': 'ACKNOWLEDGEMENTS',
'TABLE_OF_CONTENTS_COMMENT': 'TABLE OF CONTENTS',
'CHAPTER_COMMENT': 'CHAPTER',
'CHAPTER_1_NAME': 'Introduction',
'CHAPTER_2_NAME': 'Chapter 2',
'SECTION_COMMENT': 'SECTION',
'SECTION_NAME': 'Section',
'SUB_SECTION_NAME': 'Subsection',
'APPENDIX_COMMENT': 'APPENDIX',
'APPENDIX_TITLE': 'Appendix',
'APPENDIX_SECTION_NAME': 'Appendix Section',
'BIBLIOGRAPHY_COMMENT': 'BIBLIOGRAPHY',
'BIBLIOGRAHPY_TITLE': 'Bibliography',
}
THESIS_TITLE = 'THESIS_TITLE'
STUDENT_NAME = 'STUDENT_NAME'
STUDENT_NAME_TITLE = 'STUDENT_NAME_TITLE'
SUPERVISOR_NAME = 'SUPERVISORS'
def __load_template() -> str:
with open(f"./templates/template.tex", 'r') as fp:
return ''.join(fp.readlines())
def _load_statutory_declaration(type: str) -> str:
file = 'master_statutory_declaration.tex' if type == 'master' else 'bachelor_statutory_declaration.tex'
with open(f"./templates/{file}", 'r') as fp:
return ''.join(fp.readlines())
def _template_replace(template: str, key: str, value: str) -> str:
return template.replace(f"{TEMPLATE_START} {key} {TEMPLATE_END}", value)
def _insert_translations(template: str, translations: Dict[str, str]) -> str:
_template = template
for key, translation in translations.items():
_template = _template_replace(_template, key, translation)
return _template
def _insert_title_page_content(students: str, template: str, title: str) -> str:
template = _template_replace(template, THESIS_TITLE, title)
template = _template_replace(template, STUDENT_NAME, students)
template = _template_replace(template, STUDENT_NAME_TITLE, ('\\\\').join(students.split(',')))
return template
def _title_footer(type: str, language: str) -> str:
if language == 'en':
return ENGLISH['TITLE_FOOTER_MASTER'] if type == 'master' else ENGLISH['TITLE_FOOTER_BACHELOR']
else:
return GERMAN['TITLE_FOOTER_MASTER'] if type == 'master' else GERMAN['TITLE_FOOTER_BACHELOR']
def _insert_type_specific_content(template: str, type: str, language: str) -> str:
thesis_type = 'MASTER' if type == 'master' else 'BACHELOR'
template = _template_replace(template, 'THESIS_TYPE', thesis_type)
template = _template_replace(template, 'STATUTORY_DECLARATION', _load_statutory_declaration(type))
template = _template_replace(template, 'TITLE_FOOTER', _title_footer(type, language))
return template
def _create_thesis_template(language: str, type: str, title: str, students: str, supervisors: str) -> str:
translations = ENGLISH if language == 'en' else GERMAN
template = _insert_translations(__load_template(), translations)
template = _insert_title_page_content(students, template, title)
template = _insert_type_specific_content(template, type, language)
return _template_replace(template, SUPERVISOR_NAME, supervisors)
@click.command()
@click.option('--lang', default='en', prompt='Language of the Thesis', help='Language of thesis template',
type=click.Choice(['en', 'de']))
@click.option('--type', default='bachelor', prompt='Thesis type', help='Select type of thesis',
type=click.Choice(['bachelor', 'master']))
@click.option('--title', default='title', prompt='Thesis title', help='Title of the thesis')
@click.option('--student', prompt='Name(s) of Student(s) (comma separated)',
help='Names of contributing students comma separated')
@click.option('--supervisor', prompt='Name(s) of Supervisor(s) (comma separated)',
help='Names of supervisor comma separated')
@click.option('-o', '--output', required=False, help='Name of outputfile')
def create_template(lang, type, title, student, supervisor, output=None) -> None:
template = _create_thesis_template(lang, type, title, student, supervisor)
if output is None:
print(_create_thesis_template(lang, type, title, student, supervisor))
else:
with open(output, 'w+') as fp:
fp.writelines(template)
if __name__ == '__main__':
create_template()