def process_metagraph_blocks(self, block) -> str: self.logger.debug( f'Processing metagraph tag in {self.current_filepath}') meta = load_meta(self.config.get('chapters', [])) graph = ChaptersGraph(meta, self.options) return graph.draw()
def setUp(self): md_root = 'test/test_data/load_meta' chapters = [ 'chapter_only_yfm.md', 'chapter_with_meta.md', 'chapter_with_one_meta_tag.md', 'chapter_without_meta.md' ] self.meta = load_meta(chapters, md_root)
def make(self, target: str) -> str: self.meta = load_meta(self.config.get('chapters', []), self.working_dir) with spinner(f'Making {target} with Pandoc', self.logger, self.quiet, self.debug): result = [] if self._pandoc_config['build_whole_project']: result.append(self._build_flat(target)) result.extend(self._build_separate(target)) return '\n' + '\n'.join(result)
def test_folder(self): md_root = 'test/test_data/load_meta' chapters = [ 'chapter_only_yfm.md', 'chapter_with_meta.md', 'chapter_with_one_meta_tag.md', 'chapter_without_meta.md' ] with open('test/test_data/load_meta.yml') as f: expected = yaml.load(f, yaml.Loader) meta = load_meta(chapters, md_root) self.assertEqual(meta.dump(), expected)
def run(self, config_file_name='foliant.yml', project_path=Path('.')): self.logger.debug('Meta command collect_test_data started') self.meta = load_meta(self.config['chapters'], self.project_path / self.config['src_dir']) test_data = self.collect_data() with open(self.options['filename'], 'w') as f: yaml.dump({'data': test_data}, f, default_flow_style=False, allow_unicode=True, sort_keys=False) self.logger.debug('Meta command collect_test_data finished')
def _gen_meta(self): '''Generate meta yaml and return it as string''' if 'chapters' not in self.config: return '' self.meta = load_meta(self.config['chapters'])
def apply(self): self.meta = load_meta(self.config.get('chapters', [])) self._process_tags_for_all_files(self.process_template_tag) self.logger.info('Preprocessor applied')
def _build(self): ''' Main method. Builds confluence XHTML document from flat md source and uploads it into the confluence server. ''' host = self.options['host'] credentials = self._get_credentials(host) self.logger.debug(f'Got credentials for host {host}: login {credentials[0]}, ' f'password {credentials[1]}') self._connect(host, *credentials, self.options['verify_ssl']) result = [] if 'id' in self.options or ('title' in self.options and 'space_key' in self.options): self.logger.debug('Uploading flat project to confluence') output(f'Building main project', self.quiet) flatten.Preprocessor( self.context, self.logger, self.quiet, self.debug, {'flat_src_file_name': self._flat_src_file_name, 'keep_sources': True} ).apply() unescapecode.Preprocessor( self.context, self.logger, self.quiet, self.debug, {} ).apply() shutil.move(self.working_dir / self._flat_src_file_name, self._flat_src_file_path) with open(self._flat_src_file_path, encoding='utf8') as f: md_source = f.read() options = self._get_options(self.options) self.logger.debug(f'Options: {options}') uploader = PageUploader( self._flat_src_file_path, options, self.con, self._cachedir, self._debug_dir, self._attachments_dir, self.logger ) try: result.append(uploader.upload(md_source)) except HTTPError as e: # reraising HTTPError with meaningful message raise HTTPError(e.response.text, e.response) self.logger.debug('Searching metadata for confluence properties') chapters = self.config['chapters'] meta = load_meta(chapters, self.working_dir) for section in meta.iter_sections(): if not isinstance(section.data.get('confluence'), dict): self.logger.debug(f'No "confluence" section in {section}), skipping.') continue self.logger.debug(f'Found "confluence" section in {section}), preparing to build.') # getting common options from foliant.yml and merging them with meta fields common_options = {} uncommon_options = ['title', 'id', 'space_key', 'parent_id', 'attachments'] common_options = {k: v for k, v in self.options.items() if k not in uncommon_options} try: options = self._get_options(common_options, section.data['confluence'], fallback_title=section.title) except Exception as e: # output(f'Skipping section {section}, wrong params: {e}', self.quiet) self.logger.debug(f'Skipping section {section}, wrong params: {e}') continue self.logger.debug(f'Building {section.chapter.filename}: {section.title}') output(f'Building {section.title}', self.quiet) md_source = section.get_source() self.logger.debug(f'Options: {options}') original_file = self.project_path / section.chapter.filename uploader = PageUploader( original_file, options, self.con, self._cachedir, self._debug_dir, self._attachments_dir, self.logger ) try: result.append(uploader.upload(md_source)) except HTTPError as e: # reraising HTTPError with meaningful message raise HTTPError(e.response.text, e.response) if result: return '\n' + '\n'.join(result) else: return 'nothing to upload'