From 5e73a5ff9578f377e4b6cdbba02ad320d1a220a0 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Sat, 11 Nov 2023 22:47:12 +0100 Subject: [PATCH] added book mode MVP --- README.md | 10 ++++++--- TODO.md | 6 ++++++ coursebuilder/__main__.py | 43 +++++++++++++++++++++++++++++++++++++-- test/simple/book.yaml | 26 +++++++++++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 TODO.md create mode 100644 test/simple/book.yaml diff --git a/README.md b/README.md index 393195e..fd5b767 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ actual values are kept in YAML files in order to version them with git. ```sh $> python coursebuilder -coursebuilder [-h] [-m META [META ...]] [-l LANG] [-f FIELDS [FIELDS ...]] [-s SCHEMA] +usage: [-h] [-m META [META ...]] [-l LANG] [-f FIELDS [FIELDS ...]] [-s SCHEMA] [-p] [-t] [-b BOOK] + +versatile curricula generator options: -h, --help show this help message and exit @@ -18,9 +20,12 @@ options: course description(s) as YAML file(s) -l LANG, --lang LANG Language to parse from meta file (use de or en) -f FIELDS [FIELDS ...], --fields FIELDS [FIELDS ...] - Fields to be used + Fields to be used, the table will be build accordingly -s SCHEMA, --schema SCHEMA using provided schema + -p, --pagebreak add a pagebreak after each module + -t, --title take first value in list as title + -b BOOK, --book BOOK process a whole curriculum book with sections ``` # Author @@ -28,7 +33,6 @@ options: (c) Copyright 2020-2023 Hartmut Seichter - # Licence Coursebuilder is licensed under the terms of the MIT License. For details consult https://opensource.org/license/mit/ or the attached license file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..c073484 --- /dev/null +++ b/TODO.md @@ -0,0 +1,6 @@ +# Must Haves + +* [ ] proper referencing of tables +* [ ] custom python code in tables +* [x] fix overlong table cells (pandoc longtable only deals with overlong tables but not cells) +* [ ] add a book mode for mixing input and headers (# Blah -m mod.cg.yaml) diff --git a/coursebuilder/__main__.py b/coursebuilder/__main__.py index 8abd14c..27f6574 100644 --- a/coursebuilder/__main__.py +++ b/coursebuilder/__main__.py @@ -179,6 +179,31 @@ class CourseBuilder: mdg = MarkdownGenerator() mdg.generate_markdown(table_items,pagebreak,createTitle) + def process_book_section(self,section,lang='de'): + pass + + def process_book(self,book,bookpath,create_title,pagebreak,lang='de'): + + actual_fields = [] + + for bi in book['book']: + if 'fields' in bi: + actual_fields = bi['fields'] + if 'sections' in bi: + for section in bi['sections']: + if 'text' in section: + print(section['text'][lang]) + if 'modules' in section: + for m in section['modules']: + mod_path = os.path.join(os.path.dirname(bookpath),m) + + with open(mod_path) as fm: + self.process(yaml.load(fm,Loader=yaml.Loader),fields=actual_fields,lang=lang,pagebreak=pagebreak,createTitle=create_title) + + pass + + + def main(): @@ -191,12 +216,26 @@ def main(): parser.add_argument('-s','--schema',help="using provided schema") parser.add_argument('-p','--pagebreak',action="store_true",help="add a pagebreak after each module") parser.add_argument('-t','--title',action="store_true",help="take first value in list as title") + parser.add_argument('-b','--book',type=str,help="process a whole curriculum book with sections") + # get arguments args = parser.parse_args() - # only run debug - if args.schema and args.meta and len(args.fields) > 0: + # book mode with predefined setting from a book file + if args.book and args.schema: + + cb = CourseBuilder() + + with open(args.schema) as sf: + cb.set_schema(yaml.load(sf,Loader=yaml.Loader)) + + with open(args.book) as bf: + cb.process_book(yaml.load(bf,Loader=yaml.Loader),os.path.abspath(args.book),lang=args.lang,pagebreak=args.pagebreak,create_title=args.title) + + + # verbose command line mode + elif args.schema and args.meta and len(args.fields) > 0: cb = CourseBuilder() diff --git a/test/simple/book.yaml b/test/simple/book.yaml new file mode 100644 index 0000000..3243fdb --- /dev/null +++ b/test/simple/book.yaml @@ -0,0 +1,26 @@ +book: + - fields: + - name + - id + - goal + - content + - form-of-instruction + - prerequisites + - media-of-instruction + - author-of-indenture + - used-in + - workload + - credits + - form-of-exam + - term + - frequency + - duration + - kind + - remarks + - sections: + - text: + de: "## Pflichtbereich {.unnumbered}" + en: "## compulsory courses {.unnumbered}" + - modules: + - mod.cg.yaml +