added book mode MVP
This commit is contained in:
parent
573018e9e2
commit
5e73a5ff95
4 changed files with 80 additions and 5 deletions
10
README.md
10
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
|
||||
|
|
6
TODO.md
Normal file
6
TODO.md
Normal file
|
@ -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)
|
|
@ -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()
|
||||
|
||||
|
|
26
test/simple/book.yaml
Normal file
26
test/simple/book.yaml
Normal file
|
@ -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
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue