def _makeHtml(self, page): style = Style() stylepath = style.getPageStyle(page) try: tpl = HtmlTemplate(readTextFile(stylepath)) except EnvironmentError: tpl = HtmlTemplate(readTextFile(style.getDefaultStyle())) content = self._changeContentByEvent( page, PreprocessingParams(page.content), self._application.onPreprocessing) if page.autoLineWrap: content = self._changeContentByEvent( page, PreHtmlImprovingParams(content), self._application.onPreHtmlImproving) config = HtmlRenderConfig(self._application.config) improverFactory = HtmlImproverFactory(self._application) text = improverFactory[config.HTMLImprover.value].run(content) else: text = content result = tpl.substitute(content=text, title=page.display_title) result = self._changeContentByEvent(page, PostprocessingParams(result), self._application.onPostprocessing) return result
def __loadPluginInfo(self, plugin_fname): if not os.path.exists(plugin_fname): return None xml_content = readTextFile(plugin_fname) appinfo = XmlVersionParser().parse(xml_content) return appinfo
def _print_changelog(path_to_xml, lang): xml_content = readTextFile(path_to_xml) parser = XmlVersionParser([lang]) appinfo = parser.parse(xml_content) generator = SiteChangelogGenerator(appinfo) changelog = generator.make() print(changelog)
def testLinkToPageByProticolLongNames(self): """ Тест на проверку того, что заменяются ссылки вида page://... """ from export2html.longnamegenerator import LongNameGenerator from export2html.branchexporter import BranchExporter Application.wikiroot = self.root namegenerator = LongNameGenerator(self.root) branchExporter = BranchExporter(self.root, namegenerator, Application) branchExporter.export( outdir=self.outputdir, imagesonly=False, alwaysOverwrite=False ) text = readTextFile( os.path.join( self.outputdir, "samplewiki_Страница 1.html")) self.assertIn( '<a href="samplewiki_Страница 1_Страница 2_Страница 6_Страница 7_Страница 2.html">', text)
def testBranchContentTitleNames2(self): """ Экспорт дерева с короткими именами """ from export2html.titlenamegenerator import TitleNameGenerator from export2html.branchexporter import BranchExporter pagename = "Страница 1" namegenerator = TitleNameGenerator(self.outputdir) branchExporter = BranchExporter( self.root[pagename], namegenerator, Application) branchExporter.export( outdir=self.outputdir, imagesonly=False, alwaysOverwrite=False ) text = readTextFile( os.path.join( self.outputdir, "Страница 2 (2).html")) self.assertTrue('<img src="Страница 2 (2)/cd.png"/>' in text) self.assertTrue( '<a href="Страница 2 (2)/cd_go.png">cd_go.png</a>' in text)
def testLinkToFilesWiki(self): """ Тест на то, что ссылки на прикрепленные файлы изменяютcя. Проверка на вики-странице """ from export2html.exporterfactory import ExporterFactory fullpagename = "Типы страниц/wiki-страница" pagename = "wiki-страница" exporter = ExporterFactory.getExporter(self.root[fullpagename]) exporter.export(outdir=self.outputdir, exportname=pagename, imagesonly=True, alwaysOverwrite=False) text = readTextFile(os.path.join(self.outputdir, pagename + ".html")) self.assertTrue( '<img src="{pagename}/add.png"/>'.format(pagename=pagename) in text) self.assertTrue( '<a href="{pagename}/wall1.gif">ссылка на файл</a>'.format(pagename=pagename) in text) self.assertTrue('А этот __attach/ содержится в тексте' in text) self.assertTrue( '<a href="{pagename}/image.jpg"><img src="{pagename}/__thumb/th_maxsize_250_image.jpg"/></a>'.format( pagename=pagename) in text)
def testPostprocessing_01 (self): """ Тест на работу постпроцессинга """ Application.wikiroot = self.wikiroot Application.selectedPage = self.wikiroot[u"HTML-страница"] Application.onPostprocessing += self._onPostProcessing pageView = Application.mainWindow.pagePanel.pageView # В начале по умолчанию выбирается вкладка с просмотром wx.GetApp().Yield() # Переключимся на вкладку с кодом pageView.selectedPageIndex = HtmlPageView.CODE_PAGE_INDEX wx.GetApp().Yield() pageView.codeEditor.SetText (u"Абырвалг") # Переключимся на результирующий HTML pageView.selectedPageIndex = HtmlPageView.RESULT_PAGE_INDEX wx.GetApp().Yield() Application.onPostprocessing -= self._onPostProcessing result = readTextFile (os.path.join (self.wikiroot[u"HTML-страница"].path, PAGE_RESULT_HTML)) self.assertTrue (result.endswith (u" 111"))
def testPreprocessing_01(self): """ Тест на работу препроцессинга """ self.application.wikiroot = self.wikiroot self.application.selectedPage = self.wikiroot["HTML-страница"] self.application.onPreprocessing += self._onPreProcessing pageView = self.application.mainWindow.pagePanel.pageView # Сначала по умолчанию выбирается вкладка с просмотром wx.GetApp().Yield() # Переключимся на вкладку с кодом pageView._selectedPageIndex = HtmlPageView.CODE_PAGE_INDEX wx.GetApp().Yield() pageView.codeEditor.SetText("Абырвалг") # Переключимся на результирующий HTML pageView._selectedPageIndex = HtmlPageView.RESULT_PAGE_INDEX wx.GetApp().Yield() self.application.onPreprocessing -= self._onPreProcessing result = readTextFile(os.path.join(self.wikiroot["HTML-страница"].path, PAGE_RESULT_HTML)) self.assertIn("Абырвалг 000", result)
def _build_installer(self): if not self._create_installer: return print_info(u'Create installer...') if self.is_stable: installerName = u'outwiker_{}_win'.format(self.facts.version_items[0]) else: installerName = u'outwiker_win_unstable'.format(self.facts.version) installer_path = os.path.join(self.facts.temp_dir, installerName) installer_template = readTextFile(os.path.join(NEED_FOR_BUILD_DIR, u'windows', u'outwiker_setup.iss.tpl')) installer_text = Template(installer_template).safe_substitute( version=self.facts.version, resultname=installerName ) installer_script_path = os.path.join(self.facts.temp_dir, u'outwiker_setup.iss') writeTextFile(installer_script_path, installer_text) with lcd(self.facts.temp_dir): local("iscc outwiker_setup.iss") shutil.move(installer_path + u'.exe', self.build_dir)
def _updateHtmlWindow(self): """ Подготовить и показать HTML текущей страницы """ assert self._currentpage is not None setStatusText(_(u"Page loading. Please wait…"), self._statusbar_item) try: path = self._currentpage.getHtmlPath() if not os.path.exists(path): self._updatePage() html = readTextFile(path) if(self._oldPage != self._currentpage or self._oldHtmlResult != html): self.htmlWindow.LoadPage(path) self._oldHtmlResult = html self._oldPage = self._currentpage except EnvironmentError as e: logger.error(str(e)) MessageBox(_(u'Page loading error: {}').format( self._currentpage.title), _(u'Error'), wx.ICON_ERROR | wx.OK) setStatusText(u"", self._statusbar_item)
def testImproved1(self): src = u"""<ul><li>Несортированный список. Элемент 1</li><li>Несортированный список. Элемент 2</li><li>Несортированный список. Элемент 3</li><ol><li>Вложенный сортированный список. Элемент 1</li><li>Вложенный сортированный список. Элемент 2</li><li>Вложенный сортированный список. Элемент 3</li><li>Вложенный сортированный список. Элемент 4</li><ul><li>Совсем вложенный сортированный список. Элемент 1</li><li>Совсем вложенный сортированный список. Элемент 2</li></ul><li>Вложенный сортированный список. Элемент 5</li></ol><ul><li>Вложенный несортированный список. Элемент 1</li></ul></ul>""" expectedResult = u"""<ul> <li>Несортированный список. Элемент 1</li> <li>Несортированный список. Элемент 2</li> <li>Несортированный список. Элемент 3</li> <ol> <li>Вложенный сортированный список. Элемент 1</li> <li>Вложенный сортированный список. Элемент 2</li> <li>Вложенный сортированный список. Элемент 3</li> <li>Вложенный сортированный список. Элемент 4</li> <ul> <li>Совсем вложенный сортированный список. Элемент 1</li> <li>Совсем вложенный сортированный список. Элемент 2</li> </ul> <li>Вложенный сортированный список. Элемент 5</li> </ol> <ul> <li>Вложенный несортированный список. Элемент 1</li> </ul> </ul>""" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(BrHtmlImprover().run(src)) self.assertIn(expectedResult, result)
def _showSnippet(self, info): try: text = readTextFile(info.path).rstrip() self._dialog.snippetEditor.SetText(text) except EnvironmentError: MessageBox( _(u"Can't read the snippet\n{}").format(info.path), _(u"Error"), wx.ICON_ERROR | wx.OK)
def load(self): try: text = readTextFile(self._fname) items = json.loads(text) except (IOError, json.JSONDecodeError): logger.error('Error reading a notes tree registry') items = {} return items
def testChangeFontSize(self): self.config.fontSize.value = 20 content = u"бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn(u"font-size:20pt;", result)
def getCurrentVersion(): path = os.path.join(getCurrentDir(), VERSION_FILE_NAME) try: text = readTextFile(path) versionInfo = XmlVersionParser([_(VERSIONS_LANG), u'en']).parse(text) except EnvironmentError: return None return versionInfo.currentVersion
def testChangeFontName(self): self.config.fontName.value = "Arial" content = "бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn("font-family:Arial;", result)
def _getVariables(self, text, var_set): ast = self._jinja_env.parse(text) var_set.update(meta.find_undeclared_variables(ast)) for tpl_fname in meta.find_referenced_templates(ast): fname = os.path.join(self._dirname, tpl_fname) try: text = readTextFile(fname) self._getVariables(text, var_set) except EnvironmentError: pass
def createHTMLContent(self, appInfoDict, updatedAppInfo, installerInfoDict): currentVersion = self._getCurrentVersionStr() currentVersionsDict = self._getCurrentVersionsDict() appInfoDict = self.filterUpdatedApps(currentVersionsDict, appInfoDict) updateAppInfo = self.filterUpdatedApps(currentVersionsDict, updatedAppInfo) installedAppInfo = { x: y for x, y in updatedAppInfo.items() if x not in updateAppInfo } template = readTextFile(self._updateTemplatePath) templateData = { u'outwiker_current_version': currentVersion, u'outwikerAppInfo': appInfoDict, u'updatedAppInfo': updateAppInfo, u'installedAppInfo': installedAppInfo, u'otherAppInfo': installerInfoDict, u'currentVersionsDict': currentVersionsDict, u'str_outwiker_current_version': _(u'Installed OutWiker version'), u'str_outwiker_latest_stable_version': _(u'Latest stable OutWiker version'), u'str_outwiker_latest_unstable_version': _(u'Latest unstable OutWiker version'), u'str_version_history': _(u'Version history'), u'str_more_info': _(u'More info'), u'str_update': _(u'Update'), u'str_install': _(u'Install'), u'str_uninstall': _(u'Uninstall'), u'data_path': self._dataPath, u'escape': html.escape, } contentGenerator = ContentGenerator(template) HTMLContent = contentGenerator.render(templateData) return HTMLContent
def _loadCustomDict (self): """ Load and show custom dictionary """ self.customDict.SetValue (u'') try: text = readTextFile (self._getCustomDictFileName()) except (IOError, SystemError): return self.customDict.SetValue (self._sanitizeDictText (text))
def _loadCustomDict(self): """ Load and show custom dictionary """ self.customDict.SetValue(u'') try: text = readTextFile(self._getCustomDictFileName()) except (IOError, SystemError): return self.customDict.SetValue(self._sanitizeDictText(text))
def makeHtml(self, stylepath): parser = Parser() css = parser.getCSS() head = u'<style>\n{}\n</style>'.format(css) html = parser.convert(self.page.content) tpl = HtmlTemplate(readTextFile(stylepath)) result = tpl.substitute(content=html, userhead=head, title=self.page.display_title) return result
def loadTemplate(fname): """ Загрузить шаблон. """ templatedir = u"templates" currentdir = str((os.path.dirname(__file__))) templateFileName = os.path.join(currentdir, templatedir, fname) template = readTextFile(templateFileName) return Template(template)
def _getHTML(self, equation): try: template_str = readTextFile(self._template_fname) except IOError as e: logger.error("Can't read template file: {}".format(self._template_fname)) logger.error(str(e)) return template = MyTemplate(template_str) katexdir = self._katexdir return template.safe_substitute(katexdir=katexdir, equation=equation)
def makeHtml (self, stylepath): parser = Parser() content = parser.convert (self.page.content) text = BrHtmlImprover().run (content) head = u"" tpl = HtmlTemplate (readTextFile (stylepath)) result = tpl.substitute (content=text, userhead=head) return result
def __getStyleContent(self, page): """ Возвращает содержимое шаблона """ style = Style() try: stylecontent = readTextFile(style.getPageStyle(page)) except (IOError, UnicodeDecodeError): stylecontent = "" return stylecontent
def makeHtml(self, stylepath): parser = Parser() content = parser.convert(self.page.content) text = BrHtmlImprover().run(content) head = u"" tpl = HtmlTemplate(readTextFile(stylepath)) result = tpl.substitute(content=text, userhead=head) return result
def loadTemplate (fname): """ Загрузить шаблон. """ templatedir = u"templates" currentdir = str ((os.path.dirname (__file__))) templateFileName = os.path.join (currentdir, templatedir, fname) template = readTextFile(templateFileName) return Template (template)
def __replacePageLinks(self, outdir): """ Скорректировать ссылки на страницы """ for page in list(self.__renames.keys()): fullname = os.path.join(outdir, self.__renames[page] + u".html") try: text = readTextFile(fullname) newtext = self.__replacePageLinksInText(text, page, outdir) writeTextFile(fullname, newtext) except BaseException as error: self.__log.append(u"{0}: {1}".format(page.title, str(error)))
def __replacePageLinks (self, outdir): """ Скорректировать ссылки на страницы """ for page in list(self.__renames.keys()): fullname = os.path.join (outdir, self.__renames[page] + u".html") try: text = readTextFile(fullname) newtext = self.__replacePageLinksInText (text, page, outdir) writeTextFile(fullname, newtext) except BaseException as error: self.__log.append (u"{0}: {1}".format (page.title, str(error)))
def _getHTML(self, equation): try: template_str = readTextFile(self._template_fname) except IOError as e: logger.error("Can't read template file: {}".format( self._template_fname)) logger.error(str(e)) return template = MyTemplate(template_str) katexdir = self._katexdir return template.safe_substitute(katexdir=katexdir, equation=equation)
def testChangeUserStyle(self): style = "p {background-color: maroon; color: white; }" self.config.userStyle.value = style content = "бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertTrue(style in result, result)
def testDefault(self): content = "бла-бла-бла" result_right = r"""<body> бла-бла-бла </body> </html>""" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn(result_right, result.replace("\r\n", "\n"))
def testChangeUserStyle(self): style = u"p {background-color: maroon; color: white; }" self.config.userStyle.value = style content = u"бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertTrue(style in result, result)
def loadCustomStyles(dir_list): styles = {} extension = '.css' for folder in dir_list: for fname in os.listdir(folder): if fname.endswith(extension): name = fname[:-len(extension)] try: css = readTextFile(os.path.join(folder, fname)) styles[name] = css except IOError: pass return styles
def makeHtml(self, stylepath): parser = Parser() css = parser.getCSS() head = u'<style>\n{}\n</style>'.format(css) html = parser.convert(self.page.content) tpl = HtmlTemplate(readTextFile(stylepath)) if Version(*outwiker.core.__version__) >= Version(1, 5): result = tpl.substitute(content=html, userhead=head, title=self.page.display_title) else: result = tpl.substitute(content=html, userhead=head) return result
def testDefault(self): content = u"бла-бла-бла" result_right = ur"""<body> бла-бла-бла </body> </html>""" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn(result_right, result.replace("\r\n", "\n"))
def upload_plugin(*args): ''' Upload plugin to site ''' if len(args) == 0: args = PLUGINS_LIST version_str = getOutwikerVersionStr() for pluginname in args: path_to_plugin_local = os.path.join(BUILD_DIR, version_str, PLUGINS_DIR, pluginname) if not os.path.exists(path_to_plugin_local): continue path_to_xml_local = os.path.join(path_to_plugin_local, PLUGIN_VERSIONS_FILENAME) xml_content_local = readTextFile(path_to_xml_local) appinfo_local = XmlVersionParser().parse(xml_content_local) url = appinfo_local.updatesUrl try: appinfo_remote = downloadAppInfo(url) except Exception: appinfo_remote = None if (appinfo_remote is not None and appinfo_local.currentVersion < appinfo_remote.currentVersion): print_error(u'Error. New version < Prev version') sys.exit(1) elif (appinfo_remote is not None and appinfo_local.currentVersion == appinfo_remote.currentVersion): print_warning(u'Warning: Uploaded the same version') print_info(u'Uploading...') path_to_upload = os.path.dirname( appinfo_local.updatesUrl.replace(DEPLOY_SITE + u'/', DEPLOY_HOME_PATH)) version_local = str(appinfo_local.currentVersion) archive_name = u'{}-{}.zip'.format(pluginname, version_local) path_to_archive_local = os.path.join(path_to_plugin_local, archive_name) with cd(path_to_upload): put(path_to_archive_local, archive_name) put(path_to_xml_local, PLUGIN_VERSIONS_FILENAME) site_versions()
def testChangeUserStyleRussian(self): style = ("p {background-color: maroon; " + "/* Цвет фона под текстом параграфа */ color: white; " + "/* Цвет текста */ }") self.config.userStyle.value = style content = "бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertTrue(style in result, result)
def _executeFromFile(self, params_dict, content): snippet_file = params_dict[WIKI_COMMAND_PARAM_FILE] snippet_path = os.path.join(self._snippets_dir, snippet_file) current_dir = os.path.dirname(snippet_path) try: snippet_text = readTextFile(snippet_path) except EnvironmentError: text = (_(u'Snippet error: \n') + _(u"Can't read file '{}'").format(snippet_path)) return self._format_error(text) return self._parseSnippet(snippet_text, current_dir, params_dict, content)
def load(self, url): """ Метод может бросать исключения urllib2.HTTPError и urllib2.URLError """ if os.path.isfile(url): return readTextFile(url) fp = urllib2.urlopen(url) try: text = unicode(fp.read(), 'utf8') finally: fp.close() return text
def _getHTML(self, equation: str, blockMode: bool): try: template_str = readTextFile(self._template_fname) except IOError as e: logger.error("Can't read template file: {}".format(self._template_fname)) logger.error(str(e)) return template = MyTemplate(template_str) katexdir = self._katexdir blockModeStr = str(blockMode).lower() return template.safe_substitute(katexdir=katexdir, equation=equation, blockMode=blockModeStr)
def _updateHtmlCode(self): if self.htmlcodePageIndex == -1: # Нет вкладки с кодом HTML. Ничего не делаем return try: path = self._currentpage.getHtmlPath() html = readTextFile(path) self.htmlCodeWindow.SetReadOnly(False) self.htmlCodeWindow.SetText(html) self.htmlCodeWindow.SetReadOnly(True) except IOError as e: showError(self._application.mainWindow, _(u"Can't load file %s") % (unicode(e.filename)))
def plugins_list(lang): appinfo_list = [] for plugin_name in PLUGINS_LIST: path_to_xml = os.path.join(PLUGINS_DIR, plugin_name, plugin_name, PLUGIN_VERSIONS_FILENAME) xml_content = readTextFile(path_to_xml) parser = XmlVersionParser([lang]) appinfo = parser.parse(xml_content) appinfo_list.append(appinfo) generator = SitePluginsTableGenerator(appinfo_list) text = generator.make() print(text)
def load(self, url): """ Метод может бросать исключения urllib2.HTTPError и urllib2.URLError """ if os.path.isfile(url): return readTextFile(url) fp = urllib.request.urlopen(url, timeout=10) text = None try: text = fp.read().decode('utf-8') finally: fp.close() return text
def _getHTML(self, equation: str, blockMode: bool): try: template_str = readTextFile(self._template_fname) except IOError as e: logger.error("Can't read template file: {}".format( self._template_fname)) logger.error(str(e)) return template = MyTemplate(template_str) katexdir = self._katexdir blockModeStr = str(blockMode).lower() return template.safe_substitute(katexdir=katexdir, equation=equation, blockMode=blockModeStr)
def testImproved2(self): src = r"""<h2>Attach links</h2>Attach:file.odt<br><a href="__attach/file.odt">file.odt</a><br><a href="__attach/file.odt">alternative text</a><br><a href="__attach/file with spaces.pdf">file with spaces.pdf</a><h2>Images</h2>""" expectedResult = r"""<h2>Attach links</h2> Attach:file.odt<br> <a href="__attach/file.odt">file.odt</a><br> <a href="__attach/file.odt">alternative text</a><br> <a href="__attach/file with spaces.pdf">file with spaces.pdf</a> <h2>Images</h2>""" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(BrHtmlImprover().run(src)) self.assertIn(expectedResult, result)
def LoadPage(self, fname): self.render.Stop() try: html = readTextFile(fname) except IOError: text = _(u"Can't read file %s") % (fname) self.canOpenUrl += 1 self.SetPage(text, os.path.dirname(fname)) basepath = os.path.dirname(fname) if not basepath.endswith('/'): basepath += '/' self.SetPage(html, basepath, anchor=None)
def _updateHtmlCode(self): if self.htmlcodePageIndex == -1: # Нет вкладки с кодом HTML. Ничего не делаем return try: path = self._currentpage.getHtmlPath() html = readTextFile(path) self.htmlCodeWindow.SetReadOnly(False) self.htmlCodeWindow.SetText(html) self.htmlCodeWindow.SetReadOnly(True) except IOError, e: MessageBox( _(u"Can't load file %s") % (unicode(e.filename)), _(u"Error"), wx.ICON_ERROR | wx.OK)
def _check_outwiker_errors(): print_info('Start OutWiker information checking...') changelog_outwiker_fname = os.path.join(NEED_FOR_BUILD_DIR, OUTWIKER_VERSIONS_FILENAME) versions_outwiker = readTextFile(changelog_outwiker_fname) linter = LinterForOutWiker() status_outwiker, reports_outwiker = linter.check_all(versions_outwiker) for report in reports_outwiker: _print_linter_report(report) if status_outwiker == LinterStatus.OK: print_info('OutWiker information is OK') else: print_error('Outwiker information problems found') return status_outwiker
def export(self, outdir, exportname, imagesonly, alwaysOverwrite): """ Экспорт HTML-страниц """ self.__htmlFileName = u"__content.html" # Чтение файла с содержимым try: content = readTextFile( os.path.join(self._page.path, self.__htmlFileName)) except IOError: content = u"" changedContent = self.__prepareHtmlContent(content, exportname) self._exportContent(self._page, changedContent, exportname, outdir, imagesonly, alwaysOverwrite)
def testLinkToPagesHtmlLongNames(self): """ Тест для проверки того, как исправляются ссылки на страницы """ from export2html.longnamegenerator import LongNameGenerator from export2html.branchexporter import BranchExporter pagename = u"Страница 1" namegenerator = LongNameGenerator(self.root[pagename]) branchExporter = BranchExporter(self.root[pagename], namegenerator, Application) branchExporter.export(outdir=self.outputdir, imagesonly=False, alwaysOverwrite=False) text = readTextFile( os.path.join(self.outputdir, u"Страница 1_Страница 2_Страница 6.html")) self.assertTrue(u'<A HREF="/Типы страниц">/Типы страниц</A>' in text) self.assertTrue( u'<A HREF="Страница 1_Страница 2_Страница 6_Страница 7_Страница 2.html">/Страница 1/Страница 2/Страница 6/Страница 7/Страница 2</A>' in text) self.assertTrue( u'<A HREF="Страница 1_Страница 2_Страница 6_Страница 7_Страница 2.html">Страница 7/Страница 2</A>' in text) self.assertTrue( u'<A HREF="Страница 1_Страница 2_Страница 6_Страница 7_Страница 2.html">Еще одна ссылка</A>' in text) self.assertTrue( u'<A HREF="Страница 1_Страница 2_Страница 6_Страница 7.html">Страница 7</A>' in text) self.assertTrue( u'<A HREF="Страница 1_Страница 2_Страница 6_Страница 7_Страница 2.html" title="бла-бла-бла">Ссылка на /Страница 1/Страница 2/Страница 6/Страница 7/Страница 2</A>' in text) self.assertTrue( u'<A HREF="Страница 1_Страница 2_Страница 6_Страница 7.html" title="бла-бла-бла">Ссылка на Страницу 7</A>' in text)
def testLinkToPageByProticolTitleNames_01(self): """ Тест на проверку того, что заменяются ссылки вида page://... """ from export2html.titlenamegenerator import TitleNameGenerator from export2html.branchexporter import BranchExporter Application.wikiroot = self.root namegenerator = TitleNameGenerator(self.outputdir) branchExporter = BranchExporter(self.root, namegenerator, Application) branchExporter.export(outdir=self.outputdir, imagesonly=False, alwaysOverwrite=False) text = readTextFile(os.path.join(self.outputdir, u"Страница 1.html")) self.assertIn(u'<a href="Страница 2 (2).html">', text)