def create_chapters(self, chapters=None): if not chapters: chapters = self.chapters logger.debug(chapters) for chapter in chapters: logger.debug('[%s]' % chapter.path) chapter_dir = os.path.join(self.config.root, os.path.dirname(chapter.path)) if not os.path.exists(chapter_dir): logger.info('Creating %s' % chapter_dir) os.mkdir(chapter_dir) chapter_path = os.path.join(self.config.root, chapter.path) if not os.path.exists(chapter_path): logger.info('Creating %s' % chapter_path) with open(chapter_path, 'w') as f: f.write("# %s\n\n" % chapter.title) f.write("Content goes here.\n") if chapter.articles: self.create_chapters(chapter.articles)
def init(self): logger.info('Start Initializing ...') self.read_config() if not os.path.exists(self.config.root): logger.info('Creating Root Directory') os.mkdir(self.config.root) if not os.path.exists(self.config.build): logger.info('Creating Build Directory') os.mkdir(self.config.build) if not os.path.exists(self.config.summary_abs): logger.debug("Creating Default SUMMARY.md") with open(self.config.summary_abs, 'w') as f: f.write('# Summary\n') f.write('\n') f.write('- [Introduction](./README.md)\n') self.read_summary() self.create_chapters() logger.info('Initialization Finished')
def build(self): logger.info('Start Building ...') self.read_config_and_summary() for (name, renderer) in self.renderers.items(): renderer.render() logger.info('Building is Finished')