From 467727392a82919c46b118207a0850551d9b84d6 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 8 Nov 2023 21:23:24 +0100 Subject: [PATCH] Update with loading field files --- coursebuilder/__main__.py | 18 +++++++-- test/simple/Makefile | 14 ++++--- test/simple/mod.cg.yaml | 4 +- test/simple/schema.yaml | 82 +++++---------------------------------- 4 files changed, 36 insertions(+), 82 deletions(-) diff --git a/coursebuilder/__main__.py b/coursebuilder/__main__.py index 5d14d3a..e61952f 100644 --- a/coursebuilder/__main__.py +++ b/coursebuilder/__main__.py @@ -15,6 +15,7 @@ import itertools import yaml import textwrap import string +import os class MarkdownGenerator: @@ -39,6 +40,9 @@ class MarkdownGenerator: for k,v in ti: + if v == None: + v = '' + h = textwrap.wrap(k, h_len, break_long_words=False) wrapper = textwrap.TextWrapper(d_len) t = [wrapper.wrap(i) for i in v.split('\n') if i != ''] @@ -147,18 +151,26 @@ def main(): # get arguments args = parser.parse_args() - # only run debug - if args.schema and args.meta: + if args.schema and args.meta and len(args.fields) > 0: cb = CourseBuilder() + actual_fields = [] + + if os.path.isfile(args.fields[0]): + with open(args.fields[0]) as ff: + actual_fields = yaml.load(ff,Loader=yaml.Loader)['fields'] + else: + actual_fields = args.fields + + with open(args.schema) as f: cb.set_schema(yaml.load(f,Loader=yaml.Loader)) for m in args.meta: with open(m) as fm: - cb.process(yaml.load(fm,Loader=yaml.Loader),fields=args.fields,lang=args.lang,pagebreak=args.pagebreak) + cb.process(yaml.load(fm,Loader=yaml.Loader),fields=actual_fields,lang=args.lang,pagebreak=args.pagebreak) else: parser.print_help() diff --git a/test/simple/Makefile b/test/simple/Makefile index 465b9cd..1c46c26 100644 --- a/test/simple/Makefile +++ b/test/simple/Makefile @@ -1,8 +1,12 @@ -table.pdf: - @echo "creating english version ..." - python ../../coursebuilder -s schema.yaml -m mod.cg.yaml -l en -f name id | pandoc -o table.pdf +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 -all: table.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 table.pdf \ No newline at end of file + rm table.en.pdf table.de.pdf \ No newline at end of file diff --git a/test/simple/mod.cg.yaml b/test/simple/mod.cg.yaml index 5a3e670..d054d2f 100644 --- a/test/simple/mod.cg.yaml +++ b/test/simple/mod.cg.yaml @@ -1,5 +1,7 @@ name: - value: Computer Graphics + de: Computergrafik + en: Computer Graphics + id: value: CG diff --git a/test/simple/schema.yaml b/test/simple/schema.yaml index cfc5a6e..d3a8858 100644 --- a/test/simple/schema.yaml +++ b/test/simple/schema.yaml @@ -6,7 +6,6 @@ # name: type: str - translatable: false label: { de: "Modulname", en: "name of course" @@ -186,12 +185,12 @@ form-of-exam: term: label: { de: "Semester", - en: "Term" + en: "term" } type: int template: - de: "$value$. Semester" - en: "$value$ semester" + de: " ${value}. Semester" + en: " ${value}. semester" # # Häufigkeit des Angebots @@ -199,7 +198,7 @@ term: frequency: label: { de: "Häufigkeit des Angebots", - en: "Frequency of Offer" + en: "frequency of Offer" } type: "enum" values: { @@ -215,6 +214,9 @@ frequency: duration: type: int + label: + de: Dauer + en: duration template: de: "$value Semester" en: "$value term(s)" @@ -240,71 +242,5 @@ remarks: type: str label: { de: "Bemerkungen", - en: "Remarks" - } - -# test: -# label: { de: "Name", en: "A Test" } -# type: enum -# values: { -# 'brand' : { de: "Marke", en: "Brand" }, -# 'new' : { de: "Neu", en: "New" } -# } - - -# # German -# de: -# name: Modulname -# id: Kürzel -# instructor: Modulverantwortlicher -# goal: Qualifikationsziele -# content: Modulinhalte -# form: Lehrformen -# prerequisites: Voraussetzungen für die Teilnahme -# media-of-instruction: Literatur/ multimediale Lehr- und Lernprogramme -# author-of-indenture: Lehrbriefautor -# used-in: Verwendbarkeit -# workload: Arbeitsaufwand/ Gesamtworkload -# credits: ECTS und Gewichtung der Note in der Gesamtnote -# form-of-exam: Leistungsnachweis -# term: Semester -# frequency: Häufigkeit des Angebots -# duration: Dauer -# kind: Art der Veranstaltung (Pflicht, Wahl, etc.) -# remarks: Bemerkungen - -# # English -# en: -# name: Coursename -# id: Code -# instructor: Instructor -# goal: Goals of Qualification -# content: Content and Topics -# form: Form of Instruction -# prerequisites: Prerequisites -# media-of-instruction: Media of Instruction -# author-of-indenture: Author of Indenture -# used-in: Viable for Course -# workload: Workload -# credits: Credits and Weight of Mark -# form-of-exam: Form of Examination -# term: Term -# frequency: Frequency -# duration: Duration -# kind: Compulsory / Elective -# remarks: Remarks - -# # validators for enum-fields -# enums: -# form: -# - lecture -# - seminar -# - project -# form-of-exam: -# - written -# - oral -# - alternative -# term: -# - summer -# - winter -# - both + en: "remarks" + } \ No newline at end of file