コード例 #1
0
 def convertToFreeText(self):
     """
     Actually do the Converting of 
           ImageWithTextIdevice -> FreeTextIdevice,
     now that FreeText can hold embeddded images.
     """
     new_content = ""
     imageResource_exists = False
     if self.image.imageResource:
         self.image.imageResource.checksumCheck()
         if os.path.exists(self.image.imageResource.path) and \
         os.path.isfile(self.image.imageResource.path): 
             imageResource_exists = True
         else:
             log.warn("Couldn't find ImageWithText image when upgrading "\
                     + self.image.imageResource.storageName)
     if imageResource_exists:
         new_content += "<img src=\"resources/" \
                 + self.image.imageResource.storageName + "\" " 
         if self.image.height:
             new_content += "height=\"" + self.image.height + "\" " 
         if self.image.width:
             new_content += "width=\"" + self.image.width + "\" " 
         new_content += "/> \n"
     elif self.image.imageResource:
         new_content += "<BR>\n[WARNING: missing image: " \
                 + self.image.imageResource.storageName + "]\n"
     if self.caption != "": 
         new_content += "<BR>\n[" + self.caption + "]\n"
     if self.text.content != "": 
         new_content += "<P>\n" + self.text.content + "\n"
     replacementIdev = FreeTextIdevice(new_content)
     replacementIdev.content.content_wo_resourcePaths = \
             replacementIdev.content.MassageContentForRenderView( \
                 replacementIdev.content.content_w_resourcePaths)
     self.parentNode.addIdevice(replacementIdev)
     replacementIdev.content.setParentNode()
     if imageResource_exists:
         from exe.engine.galleryidevice  import GalleryImage 
         full_image_path = self.image.imageResource.path
         new_GalleryImage = GalleryImage(replacementIdev.content, \
                 self.caption,  full_image_path, mkThumbnail=False)
     while ( self.parentNode.idevices.index(replacementIdev) \
             > ( (self.parentNode.idevices.index(self) + 1))):
         replacementIdev.movePrev()
     self.delete()
コード例 #2
0
    def convertToFreeText(self):
        """
        Actually do the Converting of 
              ImageWithTextIdevice -> FreeTextIdevice,
        now that FreeText can hold embeddded images.
        """
        new_content = ""

        # ensure that an image resource still exists on this ImageWithText,
        # before trying to add it into the FreeText idevice.
        # Why?  corrupt packages have been seen missing resources...
        # (usually in with extra package objects as well, probably
        # from old code doing faulty Extracts, or somesuch nonesense)
        imageResource_exists = False
        if self.image.imageResource:
            # also ensure that it has the correct md5 checksum, since there was 
            # a period in which resource checksums were being created before
            # the resource zip file was fully closed, and not flushed out:
            self.image.imageResource.checksumCheck()

            if os.path.exists(self.image.imageResource.path) and \
            os.path.isfile(self.image.imageResource.path): 
                imageResource_exists = True
            else:
                log.warn("Couldn't find ImageWithText image when upgrading "\
                        + self.image.imageResource.storageName)

        if imageResource_exists:
            new_content += "<img src=\"resources/" \
                    + self.image.imageResource.storageName + "\" " 
            if self.image.height:
                new_content += "height=\"" + self.image.height + "\" " 
            if self.image.width:
                new_content += "width=\"" + self.image.width + "\" " 
            new_content += "/> \n"
        elif self.image.imageResource:
            new_content += "<BR>\n[WARNING: missing image: " \
                    + self.image.imageResource.storageName + "]\n"


        if self.caption != "": 
            new_content += "<BR>\n[" + self.caption + "]\n"

        if self.text.content != "": 
            new_content += "<P>\n" + self.text.content + "\n"
        # note: this is given a text field which itself did NOT yet have
        # any embedded media! easier, eh?

        replacementIdev = FreeTextIdevice(new_content)


        ###########
        # now, copy that content field's content into its _w_resourcePaths,
        # and properly remove the resource directory via Massage....
        # for its _wo_resourcePaths:
        # note that replacementIdev's content field's content 
        # is automatically set at its constructor (above),
        # as is the default content_w_resourcePaths (a copy of content)
        # AND the default content_wo_resourcePaths (a copy of content),
        # so only need to update the content_wo_resourcePaths:
        replacementIdev.content.content_wo_resourcePaths = \
                replacementIdev.content.MassageContentForRenderView( \
                    replacementIdev.content.content_w_resourcePaths)
        # Design note: ahhhhh, the above is a good looking reason to possibly
        # have the MassageContentForRenderView() method
        # just assume its content_w_resourcePaths as the input
        # and write the output to its content_wo_resourcePaths.....
        #######
        
        # next step, add the new IDevice into the same node as this one
        self.parentNode.addIdevice(replacementIdev)
        
        # in passing GalleryImage into the FieldWithResources, 
        # that content field needs to be sure to have an updated 
        # parentNode, courtesy of its idevice: 
        replacementIdev.content.setParentNode()

        # and semi-manually add/create the current image
        # resource into the FreeTextIdevice's TextAreaField, content.
        # the content text will have already been taken care of above,
        # including the ideal <img src=...> including resources path,
        # but still need the actual image resource:
        
        if imageResource_exists:
            # Not sure why this can't be imported up top, but it gives 
            # ImportError: cannot import name GalleryImages, 
            # so here it be: 
            from exe.engine.galleryidevice  import GalleryImage 
            
            full_image_path = self.image.imageResource.path
            new_GalleryImage = GalleryImage(replacementIdev.content, \
                    self.caption,  full_image_path, mkThumbnail=False)

        # and move it up to the position following this node!
        while ( self.parentNode.idevices.index(replacementIdev) \
                > ( (self.parentNode.idevices.index(self) + 1))):
            replacementIdev.movePrev()

        # finally: delete THIS idevice itself, deleting it from the node
        self.delete()
コード例 #3
0
    def convertToFreeText(self):
        """
        Actually do the Converting of 
              MathsIdevice -> FreeTextIdevice,
        now that FreeText can hold embeddded images.
        """
        new_content = ""

        # ensure that an image resource still exists on this ImageWithText,
        # before trying to add it into the FreeText idevice.
        # Why?  corrupt packages have been seen missing resources...
        # (usually in with extra package objects as well, probably
        # from old code doing faulty Extracts, or somesuch nonesense)
        imageResource_exists = False

        if not self.content.gifResource is None:
            if os.path.exists(self.content.gifResource.path) and \
            os.path.isfile(self.content.gifResource.path):
                imageResource_exists = True
            else:
                log.warn("Couldn't find Maths image when upgrading "\
                        + self.content.gifResource.storageName)

        if imageResource_exists:
            new_content += "<img src=\"resources/" \
                    + self.content.gifResource.storageName + "\" "
            # create the expected math resource url for comparison later,
            # once we do actually create it:
            math_resource_url="resources/" \
                    + self.content.gifResource.storageName + ".tex\" "
            new_content += "exe_math_latex=\"" + math_resource_url + "\" "
            new_content += "exe_math_size=\"" + repr(self.content.fontsize) \
                    + "\" "
            # no height or width for math images, eh? nope.
            new_content += "/> \n"

        elif self.content.gifResource:
            new_content += "<BR>\n[WARNING: missing image: " \
                    + self.content.gifResource.storageName + "]\n"

        replacementIdev = FreeTextIdevice(new_content)

        ###########
        # now, copy that content field's content into its _w_resourcePaths,
        # and properly remove the resource directory via Massage....
        # for its _wo_resourcePaths:
        # note that replacementIdev's content field's content
        # is automatically set at its constructor (above),
        # as is the default content_w_resourcePaths (a copy of content)
        # AND the default content_wo_resourcePaths (a copy of content),
        # so only need to update the content_wo_resourcePaths:
        replacementIdev.content.content_wo_resourcePaths = \
                replacementIdev.content.MassageContentForRenderView( \
                    replacementIdev.content.content_w_resourcePaths)
        # Design note: ahhhhh, the above is a good looking reason to possibly
        # have the MassageContentForRenderView() method
        # just assume its content_w_resourcePaths as the input
        # and write the output to its content_wo_resourcePaths.....
        #######

        # next step, add the new IDevice into the same node as this one
        self.parentNode.addIdevice(replacementIdev)

        # in passing GalleryImage into the FieldWithResources,
        # that content field needs to be sure to have an updated
        # parentNode, courtesy of its idevice:
        replacementIdev.content.setParentNode()

        # and semi-manually add/create the current image
        # resource into the FreeTextIdevice's TextAreaField, content.
        # the content text will have already been taken care of above,
        # including the ideal <img src=...> including resources path,
        # but still need the actual image resource:

        if imageResource_exists:
            # Not sure why this can't be imported up top, but it gives
            # ImportError: cannot import name GalleryImages,
            # so here it be:
            from exe.engine.galleryidevice import GalleryImage

            full_image_path = self.content.gifResource.path
            # with empty caption:
            new_GalleryImage = GalleryImage(replacementIdev.content, \
                    '',  full_image_path, mkThumbnail=False)

            # and....  write the latex_source out into the preview_math_srcfile
            # such that it can then be passed into the compile command.
            # Using the desired name (image.gif.tex), write it into tempWebDir:
            webDir = Path(G.application.tempWebDir)
            source_tex_name = self.content.gifResource.storageName + ".tex"
            math_path = webDir.joinpath(source_tex_name)
            math_filename_str = math_path.abspath().encode('utf-8')

            log.debug("convertToFreeText: writing LaTeX source into \'" \
                                        + math_filename_str + "\'.")
            math_file = open(math_filename_str, 'wb')
            # do we need to append a \n here?:
            math_file.write(self.content.latex)
            math_file.flush()
            math_file.close()

            # finally, creating a resource for the latex_source as well:
            new_GalleryLatex = GalleryImage(replacementIdev.content, \
                    '', math_filename_str, mkThumbnail=False)
            new_GalleryLatexResource = new_GalleryLatex._imageResource
            mathsrc_resource_path = new_GalleryLatexResource._storageName
            # and re-concatenate from the global resources name,
            # to build the webUrl to the resource:
            mathsrc_resource_url = new_GalleryLatex.resourcesUrl \
                    + mathsrc_resource_path

            # AND compare with the newly built resource_url from above,
            # to ensure that we've got what we had expected, jah!
            if (mathsrc_resource_url != math_resource_url):
                log.warn('The math source was resource-ified differently ' \
                        + 'than expected, to: ' + mathsrc_resource_url \
                        + '; the source will need to be recreated.')
                # right. we COULD go ahead and change the exe_math_latex
                # attribute to point to the actual mathsrc_resource_url,
                # EXCEPT that the entire exemath plugin is currently built
                # with the idea that the source .tex file will always be named
                # as the mathimage.gif.tex, and this exe_math_latex tag
                # is really just letting the rest of the world know that
                # there IS corresponding source expected there.
                # If exemath is to ever change and use the actual contents
                # of this exe_math_latex tag (rather than just appended .tex),
                # then this could be revisited here.

            else:
                log.debug('math source was resource-ified properly to: ' \
                        + mathsrc_resource_url)

        # and move the new idevice up to the position following this node!
        while ( self.parentNode.idevices.index(replacementIdev) \
                > ( (self.parentNode.idevices.index(self) + 1))):
            replacementIdev.movePrev()

        # finally: delete THIS idevice itself, deleting it from the node
        self.delete()
コード例 #4
0
    def convertToFreeText(self):
        """
        Actually do the Converting of 
              MathsIdevice -> FreeTextIdevice,
        now that FreeText can hold embeddded images.
        """
        new_content = ""

        # ensure that an image resource still exists on this ImageWithText,
        # before trying to add it into the FreeText idevice.
        # Why?  corrupt packages have been seen missing resources...
        # (usually in with extra package objects as well, probably
        # from old code doing faulty Extracts, or somesuch nonesense)
        imageResource_exists = False

        if not self.content.gifResource is None:
            if os.path.exists(self.content.gifResource.path) and \
            os.path.isfile(self.content.gifResource.path): 
                imageResource_exists = True
            else:
                log.warn("Couldn't find Maths image when upgrading "\
                        + self.content.gifResource.storageName)

        if imageResource_exists:
            new_content += "<img src=\"resources/" \
                    + self.content.gifResource.storageName + "\" " 
            # create the expected math resource url for comparison later,
            # once we do actually create it:
            math_resource_url="resources/" \
                    + self.content.gifResource.storageName + ".tex\" " 
            new_content += "exe_math_latex=\"" + math_resource_url + "\" "
            new_content += "exe_math_size=\"" + repr(self.content.fontsize) \
                    + "\" "
            # no height or width for math images, eh? nope.
            new_content += "/> \n"

        elif self.content.gifResource:
            new_content += "<BR>\n[WARNING: missing image: " \
                    + self.content.gifResource.storageName + "]\n"


        replacementIdev = FreeTextIdevice(new_content)


        ###########
        # now, copy that content field's content into its _w_resourcePaths,
        # and properly remove the resource directory via Massage....
        # for its _wo_resourcePaths:
        # note that replacementIdev's content field's content 
        # is automatically set at its constructor (above),
        # as is the default content_w_resourcePaths (a copy of content)
        # AND the default content_wo_resourcePaths (a copy of content),
        # so only need to update the content_wo_resourcePaths:
        replacementIdev.content.content_wo_resourcePaths = \
                replacementIdev.content.MassageContentForRenderView( \
                    replacementIdev.content.content_w_resourcePaths)
        # Design note: ahhhhh, the above is a good looking reason to possibly
        # have the MassageContentForRenderView() method
        # just assume its content_w_resourcePaths as the input
        # and write the output to its content_wo_resourcePaths.....
        #######
        
        # next step, add the new IDevice into the same node as this one
        self.parentNode.addIdevice(replacementIdev)
        
        # in passing GalleryImage into the FieldWithResources, 
        # that content field needs to be sure to have an updated 
        # parentNode, courtesy of its idevice: 
        replacementIdev.content.setParentNode()

        # and semi-manually add/create the current image
        # resource into the FreeTextIdevice's TextAreaField, content.
        # the content text will have already been taken care of above,
        # including the ideal <img src=...> including resources path,
        # but still need the actual image resource:
        
        if imageResource_exists:
            # Not sure why this can't be imported up top, but it gives 
            # ImportError: cannot import name GalleryImages, 
            # so here it be: 
            from exe.engine.galleryidevice  import GalleryImage 
            
            full_image_path = self.content.gifResource.path
            # with empty caption:
            new_GalleryImage = GalleryImage(replacementIdev.content, \
                    '',  full_image_path, mkThumbnail=False)

            # and....  write the latex_source out into the preview_math_srcfile
            # such that it can then be passed into the compile command.
            # Using the desired name (image.gif.tex), write it into tempWebDir:
            webDir = Path(G.application.tempWebDir)
            source_tex_name = self.content.gifResource.storageName+".tex"
            math_path = webDir.joinpath(source_tex_name)
            math_filename_str = math_path.abspath().encode('utf-8')

            log.debug("convertToFreeText: writing LaTeX source into \'" \
                                        + math_filename_str + "\'.")
            math_file = open(math_filename_str, 'wb')
            # do we need to append a \n here?:
            math_file.write(self.content.latex)
            math_file.flush()
            math_file.close()

            # finally, creating a resource for the latex_source as well:
            new_GalleryLatex = GalleryImage(replacementIdev.content, \
                    '', math_filename_str, mkThumbnail=False) 
            new_GalleryLatexResource = new_GalleryLatex._imageResource
            mathsrc_resource_path = new_GalleryLatexResource._storageName
            # and re-concatenate from the global resources name, 
            # to build the webUrl to the resource: 
            mathsrc_resource_url = new_GalleryLatex.resourcesUrl \
                    + mathsrc_resource_path
                
            # AND compare with the newly built resource_url from above,
            # to ensure that we've got what we had expected, jah!
            if (mathsrc_resource_url != math_resource_url): 
                log.warn('The math source was resource-ified differently ' \
                        + 'than expected, to: ' + mathsrc_resource_url \
                        + '; the source will need to be recreated.') 
                # right. we COULD go ahead and change the exe_math_latex
                # attribute to point to the actual mathsrc_resource_url,
                # EXCEPT that the entire exemath plugin is currently built
                # with the idea that the source .tex file will always be named
                # as the mathimage.gif.tex, and this exe_math_latex tag
                # is really just letting the rest of the world know that 
                # there IS corresponding source expected there.
                # If exemath is to ever change and use the actual contents
                # of this exe_math_latex tag (rather than just appended .tex),
                # then this could be revisited here.

            else: 
                log.debug('math source was resource-ified properly to: ' \
                        + mathsrc_resource_url)


        # and move the new idevice up to the position following this node!
        while ( self.parentNode.idevices.index(replacementIdev) \
                > ( (self.parentNode.idevices.index(self) + 1))):
            replacementIdev.movePrev()

        # finally: delete THIS idevice itself, deleting it from the node
        self.delete()
コード例 #5
0
 def convertToFreeText(self):
     """
     Actually do the Converting of 
           MathsIdevice -> FreeTextIdevice,
     now that FreeText can hold embeddded images.
     """
     new_content = ""
     imageResource_exists = False
     if not self.content.gifResource is None:
         if os.path.exists(self.content.gifResource.path) and \
         os.path.isfile(self.content.gifResource.path): 
             imageResource_exists = True
         else:
             log.warn("Couldn't find Maths image when upgrading "\
                     + self.content.gifResource.storageName)
     if imageResource_exists:
         new_content += "<img src=\"resources/" \
                 + self.content.gifResource.storageName + "\" " 
         math_resource_url="resources/" \
                 + self.content.gifResource.storageName + ".tex\" " 
         new_content += "exe_math_latex=\"" + math_resource_url + "\" "
         new_content += "exe_math_size=\"" + repr(self.content.fontsize) \
                 + "\" "
         new_content += "/> \n"
     elif self.content.gifResource:
         new_content += "<BR>\n[WARNING: missing image: " \
                 + self.content.gifResource.storageName + "]\n"
     replacementIdev = FreeTextIdevice(new_content)
     replacementIdev.content.content_wo_resourcePaths = \
             replacementIdev.content.MassageContentForRenderView( \
                 replacementIdev.content.content_w_resourcePaths)
     self.parentNode.addIdevice(replacementIdev)
     replacementIdev.content.setParentNode()
     if imageResource_exists:
         from exe.engine.galleryidevice  import GalleryImage 
         full_image_path = self.content.gifResource.path
         new_GalleryImage = GalleryImage(replacementIdev.content, \
                 '',  full_image_path, mkThumbnail=False)
         webDir = Path(G.application.tempWebDir)
         source_tex_name = self.content.gifResource.storageName+".tex"
         math_path = webDir.joinpath(source_tex_name)
         math_filename_str = math_path.abspath().encode('utf-8')
         log.debug("convertToFreeText: writing LaTeX source into \'" \
                                     + math_filename_str + "\'.")
         math_file = open(math_filename_str, 'wb')
         math_file.write(self.content.latex)
         math_file.flush()
         math_file.close()
         new_GalleryLatex = GalleryImage(replacementIdev.content, \
                 '', math_filename_str, mkThumbnail=False) 
         new_GalleryLatexResource = new_GalleryLatex._imageResource
         mathsrc_resource_path = new_GalleryLatexResource._storageName
         mathsrc_resource_url = new_GalleryLatex.resourcesUrl \
                 + mathsrc_resource_path
         if (mathsrc_resource_url != math_resource_url): 
             log.warn('The math source was resource-ified differently ' \
                     + 'than expected, to: ' + mathsrc_resource_url \
                     + '; the source will need to be recreated.') 
         else: 
             log.debug('math source was resource-ified properly to: ' \
                     + mathsrc_resource_url)
     while ( self.parentNode.idevices.index(replacementIdev) \
             > ( (self.parentNode.idevices.index(self) + 1))):
         replacementIdev.movePrev()
     self.delete()