Esempio n. 1
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()
Esempio n. 2
0
    def startSearch(self, searchText):
        self.aborted = False
        print('Starting search operation "{}" on {} ...'.format(searchText, self.notepad.getName()))

        for pageId in self.pageList:
            if self.aborted:
                return

            page = LocalPage(self.notepad, pageId)

            imp = XMLImporter(page.getPageDir(), page.getFilename(), None)
            topFrame = imp.importModel()
            contents = topFrame.getPlainText()

            if re.search(searchText, contents, re.IGNORECASE):
                self.addMatch.emit(pageId)

        self.searchDone.emit()
Esempio n. 3
0
    def startSearch(self, searchText):
        self.aborted = False
        print('Starting search operation "{}" on {} ...'.format(
            searchText, self.notepad.getName()))

        for pageId in self.pageList:
            if self.aborted:
                return

            page = LocalPage(self.notepad, pageId)

            imp = XMLImporter(page.getPageDir(), page.getFilename(), None)
            topFrame = imp.importModel()
            contents = topFrame.getPlainText()

            if re.search(searchText, contents, re.IGNORECASE):
                self.addMatch.emit(pageId)

        self.searchDone.emit()
Esempio n. 4
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()
Esempio n. 5
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))
Esempio n. 6
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))