예제 #1
0
    def load(self):
        pagePath = self.getPagePath()
        print("  DROPBOX: Loading page from {} ".format(pagePath))

        try:
            # NOTE: get_file retrieves a BINARY file, with no character decoding applied!
            # The sax parser seems to use the proper encoding, based on the xml header
            with self.notepad.client.get_file(pagePath) as f:
                importer = XMLImporter(self.getPageDir(), self.getFilename(),
                                       self.notepad.getFormatManager())
                importer.importFromFile(f)
                self.document = importer.getDocument()
                self.links = importer.getLinks()
        except ErrorResponse as rsp:
            if rsp.status == 404:
                self.createPage(pagePath)

                # TODO: Should not require an additional roundtrip after page creation
                with self.notepad.client.get_file(pagePath) as f:
                    importer = XMLImporter(self.getPageDir(),
                                           self.getFilename(),
                                           self.notepad.getFormatManager())
                    importer.importFromFile(f)
                    self.document = importer.getDocument()
                    self.links = importer.getLinks()
            else:
                print(str(rsp))
예제 #2
0
    def load(self):
        pageFullPath = self.getPagePath()
        self.l.debug('Loading page at {} '.format(pageFullPath))

        pageDir = self.getPageDir()
        if not os.path.isfile(pageFullPath):
            self.l.debug('Page does not exist, creating empty document ...')

            rootFrame = Frame()
            p1 = Paragraph(0, ('title', 'level', '1'))
            title = TextFragment(None)
            title.setText(self.pageId)
            p1.add(title)
            p2 = Paragraph(0, ('para', None, None))
            rootFrame.add(p1)
            rootFrame.add(p2)

            docFac = DocumentFactory(pageDir, self.notepad.formatManager)
            self.document = docFac.createDocument(rootFrame)

            self.links = []
        else:
            importer = XMLImporter(pageDir, self.getFilename(),
                                   self.notepad.getFormatManager())
            importer.importDocument()
            self.document = importer.getDocument()
            self.links = importer.getLinks()
예제 #3
0
파일: Page.py 프로젝트: afester/CodeSamples
    def load(self):
        pageFullPath = self.getPagePath()
        self.l.debug('Loading page at {} '.format(pageFullPath))

        pageDir = self.getPageDir()
        if not os.path.isfile(pageFullPath):
            self.l.debug('Page does not exist, creating empty document ...')

            rootFrame = Frame()
            p1 = Paragraph(0, ('title', 'level', '1'))
            title = TextFragment(None)
            title.setText(self.pageId)
            p1.add(title)
            p2 = Paragraph(0, ('para', None, None))
            rootFrame.add(p1)
            rootFrame.add(p2)

            docFac= DocumentFactory(pageDir, self.notepad.formatManager)
            self.document = docFac.createDocument(rootFrame)

            self.links = []
        else:
            importer = XMLImporter(pageDir, self.getFilename(), self.notepad.getFormatManager())
            importer.importDocument()
            self.document = importer.getDocument()
            self.links = importer.getLinks()
예제 #4
0
파일: Page.py 프로젝트: afester/CodeSamples
    def load(self):
        pagePath = self.getPagePath()
        print("  DROPBOX: Loading page from {} ".format(pagePath))

        try:
            # NOTE: get_file retrieves a BINARY file, with no character decoding applied!
            # The sax parser seems to use the proper encoding, based on the xml header
            with self.notepad.client.get_file(pagePath) as f:
                importer = XMLImporter(self.getPageDir(), self.getFilename(), self.notepad.getFormatManager())
                importer.importFromFile(f)
                self.document = importer.getDocument()
                self.links = importer.getLinks()
        except ErrorResponse as rsp:
            if rsp.status == 404:
                self.createPage(pagePath)

                # TODO: Should not require an additional roundtrip after page creation
                with self.notepad.client.get_file(pagePath) as f:
                    importer = XMLImporter(self.getPageDir(), self.getFilename(), self.notepad.getFormatManager())
                    importer.importFromFile(f)
                    self.document = importer.getDocument()
                    self.links = importer.getLinks()
            else:
                print(str(rsp))