def main(args, configs): if args.source: if not file_exists(args.source): log.warn('File ' + args.source + ' does not exist.') exit(1) elif not os.path.isfile(args.source): log.warn(args.source + ' is not a valid file') exit(1) result = link.link(args.source) if args.markdown: markdown_obj = Markdown(result) for k, v in markdown_obj.variables.items(): configs['VARIABLES'][k] = v result = markdown_obj.text result = link.substitutions(result, configs.get('SUBSTITUTIONS', []), args) result, cache = link.retrieve_blocks(result) if 'TOC_BUILDER' in configs: configs['VARIABLES']['table-of-contents'] = link.scrape_headers(result, configs['TOC_BUILDER']) for import_stmt in ( 'from datetime import datetime', ): exec(import_stmt, configs) for k, v in cache.items(): configs['VARIABLES'][k] = v result = compile(args.template, configs) if not args.destination: log.log(result) return file_write(args.destination, result) log.info('Result can be found at ' + args.destination)
def main(args, configs): if args.source: if not file_exists(args.source): log.warn('File ' + args.source + ' does not exist.') exit(1) elif not os.path.isfile(args.source): log.warn(args.source + ' is not a valid file') exit(1) result = link.link(args.source) if args.markdown: markdown_obj = Markdown(result) for k, v in markdown_obj.variables.items(): configs['VARIABLES'][k] = v result = markdown_obj.text result = link.substitutions(result, configs.get('SUBSTITUTIONS', []), args) result, cache = link.retrieve_blocks(result) if 'TOC_BUILDER' in configs: configs['VARIABLES']['table-of-contents'] = link.scrape_headers( result, configs['TOC_BUILDER']) for import_stmt in ('from datetime import datetime', ): exec(import_stmt, configs) for k, v in cache.items(): configs['VARIABLES'][k] = v result = compile(args.template, configs) if not args.destination: log.log(result) return file_write(args.destination, result) log.info('Result can be found at ' + args.destination)
def assertHeaders(self, text, regex, translate, build, expect): toc_builder = make_mock_toc_builder(regex, translate, build) expect = self.dedent(expect) self.assertEqual(expect, link.scrape_headers(text, toc_builder))