Skip to content
Snippets Groups Projects
generator.py 1.22 KiB
Newer Older
  • Learn to ignore specific revisions
  • import os
    import re
    
    
    def create_autoilias_script(type, title, author, question, solution,
                                points=9999, answer=None, gapLength=None, number=1):
    
        with open('templates/generic.class.php', 'r', encoding='utf-8') as script:
    
            script = script.read()
    
            if not gapLength:
    
                gapLength = int(gapLength)
            else:
    
    
            script = script.format(
                type=type, title=title, author=author, number=number, points=points,
                gapComment=gapComment, gapLength=gapLength, question=question,
                solution=solution,
            )
    
    
            with open('output/generator__' + title.replace(' ', '_') + '.class.php', 'w', encoding='utf-8') as output:
    
                print(script, file=output)
    
    
    
    def worker():
        # runpy.run_path("src/util.py")
        for script in filter(lambda dat: re.search('\d+_\w+\.py', dat), os.listdir('./src')):
            info('excuting script ' + script)
            meta = runpy.run_module('src.' + script.replace('.py', ''))['meta']
            create_autoilias_script(**meta)
    
    if __name__ == '__main__':
        worker()