Esempio n. 1
0
    def makeTexEquation(self, s, l, t):
        eqn = t[0].strip()
        if len(eqn) == 0:
            return u""

        thumb = Thumbnails(self.parser.page)

        try:
            path = thumb.getThumbPath(True)
        except IOError:
            return u"<b>{}</b>".format(_(u"Can't create thumbnails directory"))

        tex = getTexRender(path)

        try:
            image_fname = tex.makeImage(eqn)
        except IOError:
            return u"<b>{}</b>".format(_(u"Can't create image file"))

        image_path = os.path.join(Thumbnails.getRelativeThumbDir(),
                                  image_fname)
        result = u'<img src="{image}"/>'.format(
            image=image_path.replace("\\", "/"))

        return result
Esempio n. 2
0
    def testThumbnails1_attach (self):
        thumb = Thumbnails (self.parser.page)
        thumbDir = thumb.getThumbPath (create=False)

        self.assertEqual (thumbDir,
                          os.path.join (Attachment (self.parser.page).getAttachPath(), Thumbnails.thumbDir),
                          thumbDir)
Esempio n. 3
0
    def testThumbnailsClear1_attach (self):
        fname = u"accept.png"
        attachPath = os.path.join (self.filesPath, fname)
        Attachment (self.parser.page).attach ([attachPath])

        thumb = Thumbnails (self.parser.page)
        thumb.clearDir ()

        self.assertFalse (os.path.exists (thumb.getThumbPath (create=False)))
Esempio n. 4
0
    def testThumbnails3_attach (self):
        fname = u"accept.png"
        attachPath = os.path.join (self.filesPath, fname)
        Attachment (self.parser.page).attach ([attachPath])

        thumb = Thumbnails (self.parser.page)
        thumbDir = thumb.getThumbPath (create=True)

        self.assertTrue (os.path.exists (thumbDir))
Esempio n. 5
0
    def _copyKatexLibrary(self):
        thumb = Thumbnails(self.parser.page)
        thumb_path = thumb.getThumbPath(True)
        katex_path = os.path.join(thumb_path, u'katex')

        if os.path.exists(katex_path):
            shutil.rmtree(katex_path)

        shutil.copytree(self._getKaTeXPath(), katex_path)
Esempio n. 6
0
    def testThumbnailsClear3(self):
        thumb = Thumbnails(self.parser.page)

        eqn1 = "y = f(x)"
        eqn2 = "y = f_2(x)"

        self.parser.toHtml("{$ %s $}" % (eqn1))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)

        self.parser.toHtml("{$ %s $}" % (eqn2))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)
Esempio n. 7
0
    def testThumbnailsClear2(self):
        thumb = Thumbnails(self.parser.page)

        eqn = "y = f(x)"

        text = "{$ %s $}" % (eqn)
        self.parser.toHtml(text)

        self.assertFalse(len(os.listdir(thumb.getThumbPath(False))) == 0)

        thumb.clearDir()

        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 0)
Esempio n. 8
0
    def testParse2 (self):
        self._attachFiles ()
        # Тест на то, что игнорируется директория __thumb
        thumb = Thumbnails (self.testPage)
        thumb.getThumbPath (True)

        text = u"(:attachlist:)"
        result = self.parser.toHtml (text)

        titles = [u"[dir]", u"[for_sort]", u"add.png", u"anchor.png", u"image.jpg", u"файл с пробелами.tmp"]
        names = [u"dir", u"for_sort", u"add.png", u"anchor.png", u"image.jpg", u"файл с пробелами.tmp"]

        self._compareResult (titles, names, result)
Esempio n. 9
0
    def testThumbnailsClear3_attach(self):
        fname = u"accept.png"
        attachPath = os.path.join(self.filesPath, fname)
        Attachment(self.parser.page).attach([attachPath])

        thumb = Thumbnails(self.parser.page)

        eqn1 = "y = f(x)"
        eqn2 = "y = f_2(x)"

        self.parser.toHtml("{$ %s $}" % (eqn1))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)

        self.parser.toHtml("{$ %s $}" % (eqn2))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)
Esempio n. 10
0
    def testThumbnailsClear2_attach(self):
        fname = u"accept.png"
        attachPath = os.path.join(self.filesPath, fname)
        Attachment(self.parser.page).attach([attachPath])

        thumb = Thumbnails(self.parser.page)

        eqn = "y = f(x)"

        text = "{$ %s $}" % (eqn)
        self.parser.toHtml(text)

        self.assertFalse(len(os.listdir(thumb.getThumbPath(False))) == 0)

        thumb.clearDir()

        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 0)
Esempio n. 11
0
    def _copyScriptFiles(self):
        """
        Копировать дополнительные файлы, необходимые для работы
        скрипта (из папки scripts в __attach/__thumb)
        """
        scriptdir = os.path.join(os.path.dirname(__file__), "scripts")
        thumbDir = Thumbnails(self.parser.page).getThumbPath(True)

        files = [
            "jquery.fancybox.css", "blank.gif", "fancybox_loading.gif",
            "jquery-1.7.2.min.js", "jquery.fancybox.pack.js",
            "fancybox_sprite.png"
        ]

        for fname in files:
            srcPath = os.path.join(scriptdir, fname)
            dstPath = os.path.join(thumbDir, fname)
            shutil.copyfile(srcPath, dstPath)
Esempio n. 12
0
    def testTex1(self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails(self.parser.page)
        texrender = getTexRender(thumb.getThumbPath(True))

        eqn = u"y = f(x)"
        text = u"{$ %s $}" % (eqn)

        fname = texrender.getImageName(eqn)
        path = os.path.join(Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<img src="{0}"/>'.format(path.replace("\\", "/"))

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)
Esempio n. 13
0
    def testTex2(self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails(self.parser.page)
        texrender = getTexRender(thumb.getThumbPath(True))

        eqn1 = u"y = f(x)"
        eqn2 = u"y = e^x"
        eqn3 = u"y = \sum_{i=0}\pi"

        text = u"""бла-бла-бла
* бла-бла-бла {$ %s $} 1111
* бла-бла-бла {$ %s $} 222
* бла-бла-бла {$ %s $} 333""" % (eqn1, eqn2, eqn3)

        fname1 = texrender.getImageName(eqn1)
        fname2 = texrender.getImageName(eqn2)
        fname3 = texrender.getImageName(eqn3)

        path1 = os.path.join(Thumbnails.getRelativeThumbDir(), fname1)
        path2 = os.path.join(Thumbnails.getRelativeThumbDir(), fname2)
        path3 = os.path.join(Thumbnails.getRelativeThumbDir(), fname3)

        result_right = u'''бла-бла-бла
<ul><li>бла-бла-бла <img src="{path1}"/> 1111</li><li>бла-бла-бла <img src="{path2}"/> 222</li><li>бла-бла-бла <img src="{path3}"/> 333</li></ul>'''.format(
            path1=path1.replace("\\", "/"),
            path2=path2.replace("\\", "/"),
            path3=path3.replace("\\", "/"))

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

        full_path1 = os.path.join(self.parser.page.path, path1)
        full_path2 = os.path.join(self.parser.page.path, path2)
        full_path3 = os.path.join(self.parser.page.path, path3)

        self.assertTrue(os.path.exists(full_path1), full_path1)
        self.assertTrue(os.path.exists(full_path2), full_path2)
        self.assertTrue(os.path.exists(full_path3), full_path3)
Esempio n. 14
0
    def execute(self, params, content):
        """
        Запустить команду на выполнение.
        Метод возвращает текст, который будет вставлен на место команды в вики-нотации
        """
        from blockdiag.parser import ParseException
        thumb = Thumbnails(self.parser.page)
        thumbPath = thumb.getThumbPath(True)

        md5 = hashlib.md5(content.encode("utf-8")).hexdigest()
        fname = self._fileNameFormat.format(md5)
        imagePath = os.path.join(thumbPath, fname)

        render = DiagramRender()

        if not os.path.exists(imagePath):
            try:
                render.renderToFile(content, imagePath)
            except (ParseException, AttributeError, TypeError):
                return u"<b>{}</b>".format(_(u"Diagram parsing error"))

        return u'<img src="{}/{}"/>'.format(thumb.getRelativeThumbDir(), fname)
Esempio n. 15
0
    def testThumbnails2 (self):
        thumb = Thumbnails (self.parser.page)
        thumbDir = thumb.getThumbPath (create=False)

        self.assertFalse (os.path.exists (thumbDir))
Esempio n. 16
0
    def testThumbnailsClear1 (self):
        thumb = Thumbnails (self.parser.page)
        thumb.clearDir ()

        self.assertFalse (os.path.exists (thumb.getThumbPath (create=False)))
Esempio n. 17
0
    def testThumbnails3 (self):
        thumb = Thumbnails (self.parser.page)
        thumbDir = thumb.getThumbPath (create=True)

        self.assertTrue (os.path.exists (thumbDir))