diff --git a/coursebuilder/__main__.py b/coursebuilder/__main__.py index 996e426..bc36a3d 100644 --- a/coursebuilder/__main__.py +++ b/coursebuilder/__main__.py @@ -11,16 +11,17 @@ actual values are kept in YAML files in order to version them with git. """ from argparse import ArgumentParser -import yaml import string import os,sys +import yaml +import pandas as pd + from tablegenerator import TableGenerator from markdowngenerator import MarkdownGenerator from templategenerator import TemplateGenerator from metagenerator import MetaGenerator - class CourseBuilder: @staticmethod @@ -39,7 +40,10 @@ class CourseBuilder: parser.add_argument('--level',type=int,default=1,help="level of header tags") parser.add_argument('--table-gen',type=str,default=None,help='runs table generator') parser.add_argument('--template',type=str,default=None,help='defines a template to be used with fields') - + parser.add_argument('-o','--out',type=str,default=None,help='set the output type') + + parser.add_argument('--maxcol',type=int,default=28,help='maximum size of left column') + # get arguments args = parser.parse_args() @@ -114,14 +118,21 @@ class CourseBuilder: generator = MetaGenerator() generator.set_schema(actual_schema) - table_items = generator.process(yaml.load(fm,Loader=yaml.Loader),fields=actual_fields,lang=args.lang,pagebreak=args.pagebreak,createTitle=args.title,header_level=args.level,template=args.template) + meta = yaml.load(fm,Loader=yaml.Loader) - if args.template: - TemplateGenerator.generate(table_items) - else: - MarkdownGenerator.generate(table_items,pagebreak=args.pagebreak,title=args.title,header_level=args.level) + table_items = generator.process(meta=meta,fields=actual_fields,lang=args.lang) - # print(table_items) + df = pd.DataFrame(table_items) + df.columns = df.iloc[0] + df = df[1:] + print(df.to_markdown(tablefmt='grid', index=False, maxcolwidths=[args.maxcol,None])) + print('\n') + + if args.pagebreak: + print('\\pagebreak') + + + # MarkdownGenerator.generate(table_items,pagebreak=args.pagebreak,title=args.title,header_level=args.level) else: parser.print_help() diff --git a/coursebuilder/metagenerator.py b/coursebuilder/metagenerator.py index fe70f33..4d3ef52 100644 --- a/coursebuilder/metagenerator.py +++ b/coursebuilder/metagenerator.py @@ -1,5 +1,4 @@ import os,string,sys -import yaml class MetaGenerator: @@ -92,7 +91,7 @@ class MetaGenerator: return [k,', '.join(parts)] - def process(self,meta,fields = [],lang = 'de',pagebreak = False,createTitle=False,header_level=1,template=None): + def process(self,meta,fields = [],lang = 'de'): table_items = [] diff --git a/coursebuilder/tablegenerator.py b/coursebuilder/tablegenerator.py index 3bdc6f5..824e714 100644 --- a/coursebuilder/tablegenerator.py +++ b/coursebuilder/tablegenerator.py @@ -4,6 +4,8 @@ import string import tempfile import subprocess import os +import pandas as pd +import tabulate class TableGenerator: """ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e0f7ee4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +numpy==1.26.4 +pandas==2.2.2 +python-dateutil==2.9.0.post0 +pytz==2024.1 +six==1.16.0 +tabulate==0.9.0 +tzdata==2024.1 diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..1a11f91 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,38 @@ + +build_dir := build +target_en := ${build_dir}/table.en.pdf +target_de := ${build_dir}/table.de.pdf + +target_flags := --template pandoc-template/eisvogel.latex + +coursebuilder := ../coursebuilder + +${target_en}: + @echo "creating English version ..." + mkdir -p ${build_dir} + python ${coursebuilder} -s schema.yaml -m mod.cg.yaml -l en -f fields.yaml | pandoc ${target_flags} -o ${target_en} + +${target_de}: + @echo "creating German version ..." + mkdir -p ${build_dir} + python ${coursebuilder} -s schema.yaml -m mod.cg.yaml -l de -f fields.yaml | pandoc ${target_flags} -o ${target_de} + +all: ${target_de} ${target_en} + +clean: + rm ${target_de} ${target_en} + +# debug-template: +# python ${coursebuilder} -s schema.yaml -m mod.cg.yaml mod.interactsys.yaml -l de -f name credits goal content --template "$$name | $$credits" + +# debug-markdown: +# python ${coursebuilder} -s schema.yaml -m mod.cg.yaml mod.interactsys.yaml -l de -f name credits + +# debug-book: +# python ${coursebuilder} -s schema.yaml -b book.yaml -l de + +debug: + python ${coursebuilder} -s schema.yaml -m mod.cg.yaml mod.interactsys.yaml mod.test.yaml -l de -f name credits goal content | pandoc ${target_flags} -V lang:de -o ${target_de} + + +.PHONY: clean \ No newline at end of file diff --git a/test/simple/book.yaml b/test/book.yaml similarity index 96% rename from test/simple/book.yaml rename to test/book.yaml index 5ec66d5..38011e9 100644 --- a/test/simple/book.yaml +++ b/test/book.yaml @@ -33,5 +33,6 @@ book: en: "## elective courses {.unnumbered}" - modules: - mod.interactsys.yaml + - mod.test.yaml diff --git a/test/simple/fields.yaml b/test/fields.yaml similarity index 100% rename from test/simple/fields.yaml rename to test/fields.yaml diff --git a/test/simple/mod.cg.yaml b/test/mod.cg.yaml similarity index 100% rename from test/simple/mod.cg.yaml rename to test/mod.cg.yaml diff --git a/test/simple/mod.interactsys.yaml b/test/mod.interactsys.yaml similarity index 100% rename from test/simple/mod.interactsys.yaml rename to test/mod.interactsys.yaml diff --git a/test/mod.test.yaml b/test/mod.test.yaml new file mode 100644 index 0000000..c70d8ca --- /dev/null +++ b/test/mod.test.yaml @@ -0,0 +1,103 @@ +name: + de: Test Vorlesung + en: Lecture of Test + + +id: + value: Test + +credits: + value: 5 + +form-of-exam: + value: written + +form-of-instruction: + value: { 'lecture': 2, 'exersise': 1 } + +term: + value: [1, 3] + +duration: + value: 1 + +kind: + value: compulsory + +goal: + de: | + **What is it** + + Lorem Ipsum is simply dummy text of the printing and typesetting + industry. Lorem Ipsum has been the industry's standard dummy text + ever since the 1500s, when an unknown printer took a galley of type + and scrambled it to make a type specimen book. It has survived not only + five centuries, but also the leap into electronic typesetting, remaining + essentially unchanged. It was popularised in the 1960s with the release + of Letraset sheets containing Lorem Ipsum passages, and more recently with + desktop publishing software like Aldus PageMaker including versions of + Lorem Ipsum. + + + + en: | + + +content: + de: | + **Where did it come from** + + Contrary to popular belief, Lorem Ipsum is not simply random text. + It has roots in a piece of classical Latin literature from 45 BC, + making it over 2000 years old. Richard McClintock, a Latin professor + at Hampden-Sydney College in Virginia, looked up one of the more + obscure Latin words, consectetur, from a Lorem Ipsum passage, and + going through the cites of the word in classical literature, + discovered the undoubtable source. Lorem Ipsum comes from sections + 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The + Extremes of Good and Evil) by Cicero, written in 45 BC. This book + is a treatise on the theory of ethics, very popular during the + Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor + sit amet..", comes from a line in section 1.10.32. + + + en: | + + +teaching-material: + de: | + + en: | + + +prerequisites: + de: "" + en: "" + +author-of-indenture: + de: "" + en: "" + +used-in: + de: "Master Applied Computerscience" + en: "Master Applied Computerscience" + +workload: + de: "2SWS Vorlesung 1SWS Übung" + en: "2SWS lecture 1SWS exersise" + +form-of-exam: + value: written + spec: + de: "120min Klausur" + en: "120min exam" + +frequency: + value: once_per_year + +kind: + value: compulsory + +remarks: + de: + en: diff --git a/test/simple/pandoc-template/eisvogel.latex b/test/pandoc-template/eisvogel.latex similarity index 100% rename from test/simple/pandoc-template/eisvogel.latex rename to test/pandoc-template/eisvogel.latex diff --git a/test/simple/schema.yaml b/test/schema.yaml similarity index 100% rename from test/simple/schema.yaml rename to test/schema.yaml diff --git a/test/simple/Makefile b/test/simple/Makefile deleted file mode 100644 index 3047ab0..0000000 --- a/test/simple/Makefile +++ /dev/null @@ -1,28 +0,0 @@ - -coursebuilder := ../../coursebuilder - -table.en.pdf: - @echo "creating English version ..." - python ${coursebuilder} -s schema.yaml -m mod.cg.yaml -l en -f fields.yaml | pandoc --template pandoc-template/eisvogel.latex -o table.en.pdf - -table.de.pdf: - @echo "creating German version ..." - python ${coursebuilder} -s schema.yaml -m mod.cg.yaml -l de -f fields.yaml | pandoc --template pandoc-template/eisvogel.latex -o table.de.pdf - -all: table.en.pdf table.de.pdf - -clean: - rm -f table.en.pdf table.de.pdf - -debug-template: - python ${coursebuilder} -s schema.yaml -m mod.cg.yaml mod.interactsys.yaml -l de -f name credits --template "$$name | $$credits" - -debug-markdown: - python ${coursebuilder} -s schema.yaml -m mod.cg.yaml mod.interactsys.yaml -l de -f name credits - -debug-book: - python ${coursebuilder} -s schema.yaml -b book.yaml -l de - -debug: - python ${coursebuilder} -s schema.yaml -m mod.cg.yaml -l de -f fields.yaml - diff --git a/test/simple/mod.test.yaml b/test/simple/mod.test.yaml deleted file mode 100644 index d600dda..0000000 --- a/test/simple/mod.test.yaml +++ /dev/null @@ -1,98 +0,0 @@ - -name: - en: Test Course - - -test: - - competency-table: - de: - - "Lineare Algebra": 'ABC' - - "Vector Spaces": 'A' - - - -# -# nested lists seem to work in Markdown only in the US style way -# -# reference here: https://meta.stackexchange.com/questions/85474/how-to-write-nested-numbered-lists -# -# note the parser actually corrects 'Tervuren' to 3 in resulting data -# - -content: - en: | - 1. Blah - - 2. Blub - - 1. Blah - - 1. Blub - - 1. Blah - - 1. Blub - - 1. Blah - - 1. Blub - - 1. Blah - - 1. Blub - - 3. Blah - - 4. Blub - - - - 5. Blah - - 6. Blah and Blub - - 1. Blah - - 1. Blub - - 7. Blah and Blub - - - Blah - - - Blub - - - Blah - - - Blub - - 8. Blub and Blah - - - Blah - - - Blub - - - Blah - - - Blub - - - Blah - - - Blub - - - Blah - - - Blub - - 9. Blah, Blub and Blub - - - Blah - - - Blub - - - Blah - - - Blub - - -