Exemple #1
0
    def updateDynamic(self):

        text = readFile(self.getFullName())

        if text.find("<maker_dynamic") == -1:
            # no dynamics
            return

        if self.core.getFilesByExtension(".dynamic") != []:

            #            print "project dynamics"
            #            for x in self.core.filterFilesByLanguage(self.core.getFilesByExtension(".dynamic")):
            #                print x
            #

            for i in self.core.filterFilesByLanguage(
                    self.core.getFilesByExtension(".dynamic")):
                # self.output("replacing dynamic: %s" % str(i))
                # TO DO
                # make this faster
                dynamicContent = readFile(self.core.getPathParts() + i +
                                          ".dynamic")
                newtext = text.replace(
                    str("<maker_dynamic:" + i + " />").encode(
                        self.core.encoding), dynamicContent)
                text = newtext
                # ---

            writeFile(self.getFullName(), newtext)
Exemple #2
0
    def load(self):
        #        self.core.history.setLastContentFile(self.name)

        self.fileController.infoMessage(readFile(self.getFullName()))

        self.fileController.loadTextIntoEditor(
            readFile(self.getFullName()).decode(self.core.encoding))
    def updateDynamic(self):
               
        text = readFile(self.getFullName())
        
        if text.find("<maker_dynamic") == -1:
            # no dynamics
            return

        
        if self.core.getFilesByExtension(".dynamic") != []:
        
#            print "project dynamics"
#            for x in self.core.filterFilesByLanguage(self.core.getFilesByExtension(".dynamic")):
#                print x
#            
            
            for i in self.core.filterFilesByLanguage(self.core.getFilesByExtension(".dynamic")):
                # self.output("replacing dynamic: %s" % str(i))
                # TO DO 
                # make this faster
                dynamicContent = readFile(self.core.getPathParts()+i+".dynamic")
                newtext = text.replace(str("<maker_dynamic:" + i + " />").encode(self.core.encoding), dynamicContent) 
                text = newtext
                # ---
            
            writeFile(self.getFullName(), newtext)
Exemple #4
0
 def load(self):
     try:
         self.fileController.loadTextIntoEditor(
             readFile(self.getFullName()).decode(self.core.encoding))
     except:
         self.fileController.loadTextIntoEditor(
             readFile(self.getFullName()).decode('latin-1'))
Exemple #5
0
    def createRSSFeed(self, HTMLFile):
        """
        Creates an RSS 2.0 Feed from a given HTML File.
        The feed is saved under the same filename but with the extension .rss.
        It also extends the existing HTML file with a list of anchors.
        """

        content = readFile(HTMLFile)

        headlines = re.compile('<h1>(.*?)</h1>',
                               re.DOTALL | re.IGNORECASE).findall(content)

        # make sure to remove doubles from the list
        uniqueSet = Set(headlines)
        headlines = list(uniqueSet)

        for i in headlines:
            #
            # this might need some explanation
            #
            # * the anchor is attached BEFORE the h1 so we do not get in trouble
            # with exising anchors inside the h1 tag
            #
            # the style of the a tag is set to display none so it does not
            # interfere with existing styles and settings
            #
            this = "<h1>%s</h1>" % str(i)
            that = "<a name='" + i.replace(" ",
                                           "_") + "'> </a>\n<h1>" + i + "</h1>"
            new = content.replace(this, that)

            content = new

        # replace RSS link placeholder
        new = content.replace("!RSS!",
                              self.name.encode(self.core.encoding) + ".rss")
        content = new

        # write the updated HTML to File
        writeFile(HTMLFile, content)

        # create RSS Feed
        location = (self.core.getPageLocationsBySource(self.name + ".htm"))[0]

        rss = ""

        for i in headlines:
            link = urlparse.urljoin(self.core.getProjectURL(), location)
            link = link.encode(self.core.encoding) + "#" + i.replace(" ", "_")
            rss += "<item>"
            rss += "<title>%s</title>" % str(i)
            rss += "<link>%s</link>" % str(link)
            rss += "</item>\n"

        _head = readFile(os.path.join(self.core.getPathParts(), 'rss.head'))
        _foot = readFile(os.path.join(self.core.getPathParts(), 'rss.foot'))

        fName = os.path.join(self.core.getPathParts(), self.name + '.rss')
        writeFile(fName, _head + rss + _foot)
Exemple #6
0
    def makeWebSite(self, preview=False):
        """
        Build website from parts - invoked by preview
        rss creation has been removed !        
        Calls self.updateDynamic().
        """

        pathParts = self.core.getPathParts()
        lang = self.getLanguage()

        writeFile(self.core.getPathParts() + self.getRealName(), ' ')

        name0 = pathParts + self.name + '.head'
        name1 = pathParts + lang + '.body'
        name2 = pathParts + lang + '.nav'
        name3 = pathParts + self.name + self.type
        name4 = pathParts + lang + '.foot'

        sourceMarkers = [
            'head', 'top of page', 'navigation', 'content', 'foot'
        ]

        theList = [name0, name1, name2, name3, name4]
        for aFile, sMarker in zip(theList, sourceMarkers):
            out = readFile(aFile)
            out += "\n\n\n<!-- end of part: %s -->\n\n" % sMarker
            writeFile(self.getFullName(), out, append=True)

        #print "make_this_website: %s.htm  Done..." % self.getName()
        self.updateDynamic()

        text = readFile(self.getFullName())

        for marker in self.core.markers:
            #print str(self.core.getDataForMakerMarker(marker)), marker

            this = marker.encode(self.core.encoding)
            that = self.core.getDataForMakerMarker(marker).encode(
                self.core.encoding)
            something = text.replace(this, that)
            text = something

        # do markdown
        markD = re.compile('<markdown>(.*?)</markdown>',
                           re.DOTALL | re.IGNORECASE).findall(text)
        for md in markD:
            #ITB 25/10/2011 add support for tables and footnotes in markdown
            mdHTML = (markdown2.markdown(md.decode("latin-1"),
                                         extras=["wiki-tables", "footnotes"
                                                 ])).encode("latin-1")

            text = text.replace('<markdown>' + md + '</markdown>', mdHTML)

        writeFile(self.getFullName(), text)

        self.createRSSFeed(self.getFullName())

        if not preview:
            self.core.addToFtpQueue(self.getFileName())
    def createRSSFeed(self, HTMLFile):
        """
        Creates an RSS 2.0 Feed from a given HTML File.
        The feed is saved under the same filename but with the extension .rss.
        It also extends the existing HTML file with a list of anchors.
        """

        content = readFile(HTMLFile)
        
        headlines  = re.compile('<h1>(.*?)</h1>', 
                                re.DOTALL |  re.IGNORECASE).findall(content)
        
        # make sure to remove doubles from the list        
        uniqueSet = Set(headlines)
        headlines = list(uniqueSet)
        
        for i in headlines:
            #
            # this might need some explanation
            #
            # * the anchor is attached BEFORE the h1 so we do not get in trouble
            # with exising anchors inside the h1 tag
            #
            # the style of the a tag is set to display none so it does not 
            # interfere with existing styles and settings
            #
            this = "<h1>%s</h1>" % str(i)
            that = "<a name='" + i.replace(" ", "_") + "'> </a>\n<h1>" + i + "</h1>"
            new = content.replace(this, that)

            content = new
            
        
        # replace RSS link placeholder        
        new = content.replace("!RSS!", self.name.encode(self.core.encoding)+".rss")
        content = new
        
        # write the updated HTML to File        
        writeFile(HTMLFile, content)

        # create RSS Feed
        location  = (self.core.getPageLocationsBySource(self.name+".htm"))[0]
        
        rss = ""
        
        for i in headlines:
            link = urlparse.urljoin(self.core.getProjectURL(), location)
            link = link.encode(self.core.encoding) + "#" + i.replace(" ", "_")
            rss +=  "<item>"
            rss += "<title>%s</title>" % str(i)
            rss += "<link>%s</link>" % str(link)
            rss += "</item>\n"
        
        _head = readFile(os.path.join(self.core.getPathParts(),'rss.head'))
        _foot = readFile(os.path.join(self.core.getPathParts(),'rss.foot'))

        fName  = os.path.join(self.core.getPathParts(),self.name+'.rss')
        writeFile(fName, _head + rss + _foot)
    def makeWebSite(self , preview = False):
        """
        Build website from parts - invoked by preview
        rss creation has been removed !        
        Calls self.updateDynamic().
        """
        
        pathParts = self.core.getPathParts()
        lang = self.getLanguage()
        
        writeFile(self.core.getPathParts()+self.getRealName(), ' ')
                
        name0 = pathParts + self.name + '.head'
        name1 = pathParts + lang + '.body'
        name2 = pathParts + lang + '.nav'
        name3 = pathParts + self.name+self.type
        name4 = pathParts + lang + '.foot'
            
        sourceMarkers = ['head', 'top of page', 'navigation', 'content', 'foot']
            
        theList = [name0, name1, name2, name3, name4]      
        for aFile, sMarker in zip(theList, sourceMarkers):
            out  = readFile(aFile)
            out += "\n\n\n<!-- end of part: %s -->\n\n" % sMarker
            writeFile(self.getFullName(), out, append=True)
        
        #print "make_this_website: %s.htm  Done..." % self.getName()
        self.updateDynamic()
        
        text = readFile(self.getFullName())
        
        for marker in self.core.markers:
            #print str(self.core.getDataForMakerMarker(marker)), marker

            this = marker.encode(self.core.encoding)
            that = self.core.getDataForMakerMarker(marker).encode(self.core.encoding)
            something = text.replace(this, that)
            text = something
        
        # do markdown
        markD = re.compile('<markdown>(.*?)</markdown>', re.DOTALL | re.IGNORECASE).findall(text)
        for md in markD:
            #ITB 25/10/2011 add support for tables and footnotes in markdown
            mdHTML = (markdown2.markdown(md.decode("latin-1"), extras=["wiki-tables","footnotes"])).encode("latin-1")
            
            text = text.replace('<markdown>' + md + '</markdown>', mdHTML)
            print text
                    
        writeFile(self.getFullName(), text)
        
        self.createRSSFeed(self.getFullName())
        
        if not preview:
            self.core.addToFtpQueue(self.getFileName())
    def printViaBrowser(self):
        """
        Is sending the contents of the current file to a webbrowser for printing
        
        This printing method works for most text files 
        It is overridden in some derived classes
        """
        printHeader = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="expires" content="0" />
<title></title>
</head>
<body onLoad="javascript:window.print();">
<pre>"""
        
        source = readFile(os.path.join(self.core.getPathParts(), self.getName() + 
                                       self.getType()))
        
        
        aSource = source.replace("<", "&lt;")
        bSource = aSource.replace(">", "&gt;")
        
        
        theContent = printHeader + bSource
        theContent += "</pre></html>" 
        
        writeFile(os.path.join(self.core.getProjectPath(), "makerPrintOut.html"), theContent)
        
        webbrowser.open("file:///" + os.path.join(self.core.getProjectPath(), "makerPrintOut.html"))
    def test_templateView(self):
        
        makerTemplateViewBuilder.buildView(self.sysPath, self.viewPath)
        self.assertTrue(os.path.isfile(os.path.join(self.viewPath, "yourTemplates.html")), "Template file has been created")

        contents = readFile(os.path.join(self.viewPath, "yourTemplates.html"))
        
        self.assertTrue(contents.find(os.path.join(self.sysPath,"jquery.min.js")) != -1, "Correct jquery reference found in view...")
 def loadStyles(self):
     """ this creates self.editorStyles """
     
     self.editorStyles = {}
     
     path = os.path.join(os.getcwd(), "system/EditorStyles")
     for item in os.listdir(path):
         if item.endswith(".json"):
             _s = item.replace(".json", "")
             self.editorStyles[_s] = eval(readFile(os.path.join(path,item)))
Exemple #12
0
    def loadStyles(self):
        """ this creates self.editorStyles """

        self.editorStyles = {}

        path = os.path.join(os.getcwd(), "system/EditorStyles")
        for item in os.listdir(path):
            if item.endswith(".json"):
                _s = item.replace(".json", "")
                self.editorStyles[_s] = eval(readFile(os.path.join(path,
                                                                   item)))
Exemple #13
0
    def preview(self, theContent):
        """Invokes MakeWebsite."""
        the_content = readFile(self.getEditModeName())

        writeFile(self.getEditModeName(), theContent)
                
        self.makeWebSite(preview = True)

        urlToOpen = 'file://'+self.core.getPathParts()+self.getRealName()
        webbrowser.open(urlToOpen, autoraise=1)
        writeFile(self.getEditModeName(), the_content)
Exemple #14
0
    def preview(self, theContent):
        """Invokes MakeWebsite."""
        the_content = readFile(self.getEditModeName())

        writeFile(self.getEditModeName(), theContent)

        self.makeWebSite(preview=True)

        urlToOpen = 'file://' + self.core.getPathParts() + self.getRealName()
        webbrowser.open(urlToOpen, autoraise=1)
        writeFile(self.getEditModeName(), the_content)
    def createFile(self, name, lang):

        # just making sure
        if not name.endswith("_"):
            name += "_"
              
        if not self.content:
            content = makerFileTemplates.getTemplate(self.type)
        
        if self.type == ".content":
            
            
        
            # TO DO: convert to use os.path.join()
            pathToHead = self.project.getPathParts()+"../templates/"+ lang +".head" 
            head = readFile(pathToHead)
                
                   
            pathToNewHead = self.project.getPathParts() + name + lang +".head"
                    
                    
            writeFile(pathToNewHead, head)
        
                    # TO DO: convert to use os.path.join()
            nameInTable = name + lang + ".htm"
                                        
                    
            self.project.addToDistributionTable(nameInTable, 
                                        self.project.getDefaultRemoteFolder(self.type), 
                                        "lines", 
                                        nameInTable)
            newFile = self.project.getPathParts() + name + lang + self.type
            writeFile(newFile, content)
        
                
        elif self.type==".dynamic":
        
            # TO DO: convert to use os.path.join()
                                        
            newFile = self.project.getPathParts() + name + lang + self.type
                            
            writeFile(newFile, content)
    
        
        group = self.projectController.findTreeItemByText(self.type)
        if not group:
            group = self.projectController.treeViewAddFolder(self.type)
                
        newItem = self.projectController.treeViewAppendItem(group, name + lang, type=None)
        self.projectController.selectTreeItemAndLoad(newItem)
Exemple #16
0
def createInfo(systemDir):
    
    info = "<div class='row'>\n"
    
    for template in os.listdir(os.path.join(systemDir, "templates")):
        
        if not template.startswith("."):
            s = readFile(os.path.join(systemDir, "templates", template, "parts","info.json")) 
            
            data = eval(s)
        
            info += makeInfo(systemDir, template, data)
    
    info += "</div>"     
    return info
Exemple #17
0
 def showOccurencesInProject(self, evt):
     
     project = self.model.project
     
     pathToProject = project.getPathParts()
     string = self.dialog.Find.GetValue()
     if string:
         count = 0
         for file in os.listdir(pathToProject):
             try:
                 count += (readFile(os.path.join(pathToProject, file))).count(string)
             except:
                 pass
         if count > 0:
             self.dialog.Status.SetLabel(str(count) + " Found")
         else:
             self.dialog.Status.SetLabel("Not Found")
Exemple #18
0
 def preview(self, theContent):
     
     """
     Preview for .css files is using either an already opened .content file or
     one from inside the project to show changes to the stylesheet in the browser
     
     """
     
     current_version = readFile(self.getFullName())
            
     writeFile(self.getFullName(), theContent)
     
     openFiles = self.core.projectManager.openFiles
     
     contentFiles = []
     
     # get open .content files
     for instance in openFiles:
         if instance.getType() == ".content":
             contentFiles.append(instance.getFullName())
     
     # if no open files get all of them
     if contentFiles == []:
         contentFiles = self.core.getFilesByExtension(".content")
         # ok there are .content files in the project
         if contentFiles == []:
             writeFile(self.getFullName(), current_version)
             return
         else:
             # use right extensions
             correctExtensions = []
             for f in contentFiles:
                 correctExtensions.append(os.path.join(self.core.getPathParts(), f + ".htm"))
             
             contentFiles = correctExtensions
     
     tool = makerCSSTools.CSSTools()
     
     for file in contentFiles:
         if self.getRealName() in tool.listUsedStyleSheetsForFilename(file):
           
             urlToOpen = 'file://'+ file
             webbrowser.open(urlToOpen, autoraise=0)    
             writeFile(self.getFullName(), current_version)
             return
Exemple #19
0
    def preview(self, theContent):
        """
        Preview for .css files is using either an already opened .content file or
        one from inside the project to show changes to the stylesheet in the browser
        
        """

        current_version = readFile(self.getFullName())

        writeFile(self.getFullName(), theContent)

        openFiles = self.core.projectManager.openFiles

        contentFiles = []

        # get open .content files
        for instance in openFiles:
            if instance.getType() == ".content":
                contentFiles.append(instance.getFullName())

        # if no open files get all of them
        if contentFiles == []:
            contentFiles = self.core.getFilesByExtension(".content")
            # ok there are .content files in the project
            if contentFiles == []:
                writeFile(self.getFullName(), current_version)
                return
            else:
                # use right extensions
                correctExtensions = []
                for f in contentFiles:
                    correctExtensions.append(
                        os.path.join(self.core.getPathParts(), f + ".htm"))

                contentFiles = correctExtensions

        tool = makerCSSTools.CSSTools()

        for file in contentFiles:
            if self.getRealName() in tool.listUsedStyleSheetsForFilename(file):

                urlToOpen = 'file://' + file
                webbrowser.open(urlToOpen, autoraise=0)
                writeFile(self.getFullName(), current_version)
                return
Exemple #20
0
    def showOccurencesInProject(self, evt):

        project = self.model.project

        pathToProject = project.getPathParts()
        string = self.dialog.Find.GetValue()
        if string:
            count = 0
            for file in os.listdir(pathToProject):
                try:
                    count += (readFile(os.path.join(pathToProject,
                                                    file))).count(string)
                except:
                    pass
            if count > 0:
                self.dialog.Status.SetLabel(str(count) + " Found")
            else:
                self.dialog.Status.SetLabel("Not Found")
    def setProjectDirNT(self, showOnlyWarnings=False):
        """
        from revision 387 
        we are moving the path file to the application directory due to problems on Vista
        
        """
        fPath = os.path.join(self.getApplicationPath(), "makerPath")
        if os.path.isfile(fPath):

            path = readFile(fPath, asLines=True, lineRange=[0])

            if os.path.isdir(path) and path.endswith(Constants.PROJECTBASE):
                self.projectDir = path
            else:
                m = "No maker projects OR invalid path to projects: "
                m += path
                self.controller.errorMessage(m)
                os.remove(fPath)
                self.setProjectDirNT(showOnlyWarnings=True)
        else:
            m = "Please select a directory to store your projects!\n"
            m += "You can also select an existing 'makerProjects' folder."

            if not showOnlyWarnings:
                self.controller.infoMessage(m)

            p = self.controller.dirDialog()

            if p:
                self.projectDir = os.path.join(p, Constants.PROJECTBASE)
                if p.endswith(Constants.PROJECTBASE):
                    self.projectDir = p

                writeFile(fPath, self.projectDir)
                if not os.path.isdir(self.projectDir):
                    self.createProjectDir()
            else:
                m = "You need to select a project folder "
                m += "to run the maker !\n"
                m += "Would you like to try again ?"
                if self.controller.askYesOrNo(m) == "Yes":
                    self.setProjectDirNT(showOnlyWarnings=True)
                else:
                    sys.exit(0)
Exemple #22
0
    def printViaBrowser(self):
        """
        Is sending the contents of the current file to a webbrowser for printing
        
        This printing method works for most text files 
        It is overridden in some derived classes
        """
        printHeader = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="expires" content="0" />
<title></title>
</head>
<body onLoad="javascript:window.print();">
<pre>"""

        source = readFile(
            os.path.join(self.core.getPathParts(),
                         self.getName() + self.getType()))

        aSource = source.replace("<", "&lt;")
        bSource = aSource.replace(">", "&gt;")

        theContent = printHeader + bSource
        theContent += "</pre></html>"

        writeFile(
            os.path.join(self.core.getProjectPath(), "makerPrintOut.html"),
            theContent)

        webbrowser.open(
            "file:///" +
            os.path.join(self.core.getProjectPath(), "makerPrintOut.html"))
Exemple #23
0
    def rename(self):
        
        oldFilename = self.fileModel.getFileName()
        oldRealName = self.fileModel.getRealName()
        newName = self.controller.getNewName()
    
        nName = os.path.join(self.fileModel.core.getPathParts(),
                             newName + self.fileModel.getType())
        
        fName = os.path.join(self.fileModel.core.getPathParts(), oldFilename)
               
        
        if self.fileModel.getType() == ".content":
            #print fName
            os.rename(fName, nName)
            os.rename(os.path.join(self.fileModel.core.getPathParts(),
                                       self.fileModel.getName()+".head"),
                          os.path.join(self.fileModel.core.getPathParts(),
                                       newName+".head")) 
            
            # remove old htm file
            fileName = self.fileModel.getFullName()
            
            if os.path.isfile(fileName):
                os.remove(fileName)


        elif self.fileModel.getType() == ".dynamic":
                #print fName
                os.rename(fName, nName)
            
        else:
                #print fName
            os.rename(fName, nName)
           
            
        self.fileModel.setName(newName)

        distContent = readFile(self.fileModel.core.getDistributionTableFilename())
         

        if self.fileModel.getType() == ".content":
                newDist = distContent.replace(oldRealName, newName+".htm")
        
        else:
        
            newDist = distContent.replace(oldFilename, newName + self.fileModel.getType())
            
        writeFile(self.fileModel.core.getDistributionTableFilename(), newDist)
            
        if self.fileModel.getType() == ".content":
            
            quotes = ["'",'"']
            
            for q in quotes:
            
                this = q + oldRealName + q
                that = q + newName+".htm" + q                
                self.fileModel.core.replaceStringInAllItems(this, that)
                
        else:
            quotes = ["'",'"']
            
            for q in quotes:
            
                this = q + oldFilename + q
                that = q + newName + self.fileModel.getType() + q
                # Brinick: why is this done twice?
                # Gerald once for single , once for double quotes
                self.fileModel.core.replaceStringInAllItems(this, that)
        
        # update in ftp queue
        self.fileModel.core.renameItemInFtpQueue(oldFilename, newName + self.fileModel.getType())
Exemple #24
0
    def updateFileBase(self):
        """
        Works on the finished HTML file and searches the distribution 
        table and current file for ftp_sources. In a second step the 
        file references are completed with the absolute path of the file.
        """
        
        text = readFile(self.getFullName())
        
        sourceList = []
        
        class XmlReader(ContentHandler):
            def __init__(XmlReader, scrwid=79, *args):
                ContentHandler.__init__(XmlReader, *args)
                
            def startElement(XmlReader, name, attrs):
                XmlReader.start_name = name
                        
                if XmlReader.start_name == "rule":
                    sourceList.append(attrs.get("ftp_source"))

            def endElement(XmlReader, name):
                pass
                
            def characters(XmlReader, chars):                        
                pass
                
        parse(self.core.getDistributionTableFilename(), XmlReader())
              
        for i in sourceList:
            try:
                print text.index(i.encode(self.core.encoding))
            except:
                print 'Unable to print text.index(i) for: %s' % str(i)
            
            if text.find(i.encode(self.core.encoding))==-1:
                print "DEBUG: cannot find ",i," in file..."
            else:
                #print "replacing ",i
                
                loc = self.core.getPageLocationsBySource(i)
                location = urlparse.urljoin(self.core.url,loc[0])
                #print location,i
                
                this = '"'+i.encode(self.core.encoding)+'"'
                that = '"'+location.encode(self.core.encoding)+'"'
                newtext = text.replace(this, that)
                text = newtext
        
        bar = text
        imagelist = self.core.getImageFiles()
        
        for image in imagelist:
            image = image.encode(self.core.encoding)
                    
            #print " inside Update Filebase: image is:",image
                    
            if bar.find('"'+image+'"')==-1:
                pass
                #print "image is not referenced in file"
            else:
                #print "inside Update Filebase: replacing : ", image
                this = '"'+image+'"'
                that = '"'+urlparse.urljoin(self.core.getProjectURL(),
                                            self.core.getRemoteGfxFolder())
                that += image+'"'
                that = str(that).encode(self.core.encoding)
                new = bar.replace(this, that)
                bar = new        
                text = new
        
        writeFile(self.core.getPathParts()+self.name+".htm", text)
Exemple #25
0
    def updateFileBase(self):
        """
        Works on the finished HTML file and searches the distribution 
        table and current file for ftp_sources. In a second step the 
        file references are completed with the absolute path of the file.
        """

        text = readFile(self.getFullName())

        sourceList = []

        class XmlReader(ContentHandler):
            def __init__(XmlReader, scrwid=79, *args):
                ContentHandler.__init__(XmlReader, *args)

            def startElement(XmlReader, name, attrs):
                XmlReader.start_name = name

                if XmlReader.start_name == "rule":
                    sourceList.append(attrs.get("ftp_source"))

            def endElement(XmlReader, name):
                pass

            def characters(XmlReader, chars):
                pass

        parse(self.core.getDistributionTableFilename(), XmlReader())

        for i in sourceList:
            try:
                print text.index(i.encode(self.core.encoding))
            except:
                print 'Unable to print text.index(i) for: %s' % str(i)

            if text.find(i.encode(self.core.encoding)) == -1:
                print "DEBUG: cannot find ", i, " in file..."
            else:

                loc = self.core.getPageLocationsBySource(i)
                location = urlparse.urljoin(self.core.url, loc[0])

                toReplace = [['"', '"'], ["'", "'"], ['"', '?'], ["'", "?"]]

                for quotes in toReplace:

                    this = quotes[0] + i.encode(self.core.encoding) + quotes[1]
                    that = quotes[0] + location.encode(
                        self.core.encoding) + quotes[1]
                    newtext = text.replace(this, that)
                    text = newtext

        bar = text
        imagelist = self.core.getImageFiles()

        for image in imagelist:
            image = image.encode(self.core.encoding)

            #print " inside Update Filebase: image is:",image

            if bar.find('"' + image + '"') == -1:
                pass
                #print "image is not referenced in file"
            else:
                #print "inside Update Filebase: replacing : ", image
                this = '"' + image + '"'
                that = '"' + urlparse.urljoin(self.core.getProjectURL(),
                                              self.core.getRemoteGfxFolder())
                that += image + '"'
                that = str(that).encode(self.core.encoding)
                new = bar.replace(this, that)
                bar = new
                text = new

        writeFile(self.core.getPathParts() + self.name + ".htm", text)
Exemple #26
0
    def rename(self):

        oldFilename = self.fileModel.getFileName()
        oldRealName = self.fileModel.getRealName()
        newName = self.controller.getNewName()

        nName = os.path.join(self.fileModel.core.getPathParts(),
                             newName + self.fileModel.getType())

        fName = os.path.join(self.fileModel.core.getPathParts(), oldFilename)

        if self.fileModel.getType() == ".content":
            #print fName
            os.rename(fName, nName)
            os.rename(
                os.path.join(self.fileModel.core.getPathParts(),
                             self.fileModel.getName() + ".head"),
                os.path.join(self.fileModel.core.getPathParts(),
                             newName + ".head"))

            # remove old htm file
            fileName = self.fileModel.getFullName()

            if os.path.isfile(fileName):
                os.remove(fileName)

        elif self.fileModel.getType() == ".dynamic":
            #print fName
            os.rename(fName, nName)

        else:
            #print fName
            os.rename(fName, nName)

        self.fileModel.setName(newName)

        distContent = readFile(
            self.fileModel.core.getDistributionTableFilename())

        if self.fileModel.getType() == ".content":
            newDist = distContent.replace(oldRealName, newName + ".htm")

        else:

            newDist = distContent.replace(oldFilename,
                                          newName + self.fileModel.getType())

        writeFile(self.fileModel.core.getDistributionTableFilename(), newDist)

        if self.fileModel.getType() == ".content":

            quotes = ["'", '"']

            for q in quotes:

                this = q + oldRealName + q
                that = q + newName + ".htm" + q
                self.fileModel.core.replaceStringInAllItems(this, that)

        else:
            quotes = ["'", '"']

            for q in quotes:

                this = q + oldFilename + q
                that = q + newName + self.fileModel.getType() + q
                # Brinick: why is this done twice?
                # Gerald once for single , once for double quotes
                self.fileModel.core.replaceStringInAllItems(this, that)

        # update in ftp queue
        self.fileModel.core.renameItemInFtpQueue(
            oldFilename, newName + self.fileModel.getType())
Exemple #27
0
    def load(self):
#        self.core.history.setLastContentFile(self.name)
                
        self.fileController.loadTextIntoEditor(readFile(self.getEditModeName()).decode(self.core.encoding))
Exemple #28
0
 def load(self):
     try:
         self.fileController.loadTextIntoEditor(readFile(self.getFullName()).decode(self.core.encoding))
     except:
         self.fileController.loadTextIntoEditor(readFile(self.getFullName()).decode('latin-1'))