496 incFile = Utilities.normjoinpath(baseDir, incMatch.group(2)) |
495 incFile = Utilities.normjoinpath(baseDir, incMatch.group(2)) |
497 else: |
496 else: |
498 incFile = "" |
497 incFile = "" |
499 if os.path.exists(incFile): |
498 if os.path.exists(incFile): |
500 try: |
499 try: |
501 f = open(incFile, "r") |
500 with open(incFile, "r") as f: |
502 incTxt = f.read() |
501 incTxt = f.read() |
503 f.close() |
|
504 except (IOError, OSError): |
502 except (IOError, OSError): |
505 # remove SSI include |
503 # remove SSI include |
506 incTxt = "" |
504 incTxt = "" |
507 else: |
505 else: |
508 # remove SSI include |
506 # remove SSI include |
584 outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-") |
582 outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-") |
585 doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-") |
583 doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-") |
586 try: |
584 try: |
587 filename = 'sphinx_preview' |
585 filename = 'sphinx_preview' |
588 basePath = os.path.join(srcTempDir, filename) |
586 basePath = os.path.join(srcTempDir, filename) |
589 fh = open(basePath + '.rst', 'w', encoding='utf-8') |
587 with open(basePath + '.rst', 'w', encoding='utf-8') as fh: |
590 fh.write(text) |
588 fh.write(text) |
591 fh.close() |
589 |
592 |
|
593 overrides = {'html_add_permalinks': False, |
590 overrides = {'html_add_permalinks': False, |
594 'html_copy_source': False, |
591 'html_copy_source': False, |
595 'html_title': 'Sphinx preview', |
592 'html_title': 'Sphinx preview', |
596 'html_use_index': False, |
593 'html_use_index': False, |
597 'html_use_modindex': False, |
594 'html_use_modindex': False, |
602 confoverrides=overrides, status=None, |
599 confoverrides=overrides, status=None, |
603 warning=io.StringIO()) |
600 warning=io.StringIO()) |
604 app.build(force_all=True, filenames=None) |
601 app.build(force_all=True, filenames=None) |
605 |
602 |
606 basePath = os.path.join(outTempDir, filename) |
603 basePath = os.path.join(outTempDir, filename) |
607 fh = open(basePath + '.html', 'r', encoding='utf-8') |
604 with open(basePath + '.html', 'r', encoding='utf-8') as fh: |
608 html = fh.read() |
605 html = fh.read() |
609 fh.close() |
|
610 finally: |
606 finally: |
611 shutil.rmtree(srcTempDir) |
607 shutil.rmtree(srcTempDir) |
612 shutil.rmtree(outTempDir) |
608 shutil.rmtree(outTempDir) |
613 shutil.rmtree(doctreeTempDir) |
609 shutil.rmtree(doctreeTempDir) |
614 |
610 |