예제 #1
0
    def test_parceInput2(self):
        testData = self.notes._parceInput("title", "WRITE_IN_EDITOR", "tag1, tag2", None, self.testNote)
        self.assertIsInstance(testData, dict)
        if not isinstance(testData, dict): return

        self.assertEqual(testData['title'], "title")
        self.assertEqual(testData['content'], editor.textToENML("note content from text editor"))
        self.assertEqual(testData["tags"], ["tag1", "tag2"])
예제 #2
0
    def test_parceInput1(self):
        testData = self.notes._parceInput("title", "test body", "tag1")
        self.assertIsInstance(testData, dict)
        if not isinstance(testData, dict): return

        self.assertEqual(testData['title'], "title")
        self.assertEqual(testData['content'], editor.textToENML("test body"))
        self.assertEqual(testData["tags"], ["tag1", ])
예제 #3
0
    def test_parceInput2(self):
        testData = self.notes._parceInput("title", "WRITE", "tag1, tag2", None, self.testNote)
        self.assertIsInstance(testData, dict)
        if not isinstance(testData, dict): return

        self.assertEqual(testData['title'], "title")
        self.assertEqual(testData['content'], editor.textToENML("note content from text editor"))
        self.assertEqual(testData["tags"], ["tag1", "tag2"])
예제 #4
0
    def test_parceInput1(self):
        testData = self.notes._parceInput("title", "test body", "tag1")
        self.assertIsInstance(testData, dict)
        if not isinstance(testData, dict): return

        self.assertEqual(testData['title'], "title")
        self.assertEqual(testData['content'], editor.textToENML("test body"))
        self.assertEqual(testData["tags"], ["tag1", ])
예제 #5
0
    def _parseInput(self,
                    title=None,
                    content=None,
                    tags=None,
                    notebook=None,
                    resources=None,
                    note=None):
        result = {
            "title": title,
            "content": content,
            "tags": tags,
            "notebook": notebook,
            "resources": resources if resources else []
        }
        result = tools.strip(result)

        # if get note without params
        if note and title is None and content is None and tags is None and notebook is None:
            content = config.EDITOR_OPEN

        if title is None and note:
            result['title'] = note.title

        if content:
            if content == config.EDITOR_OPEN:
                logging.debug("launch system editor")
                if note:
                    self.getEvernote().loadNoteContent(note)
                    content = editor.edit(note.content)
                else:
                    content = editor.edit()

            elif isinstance(content, str) and os.path.isfile(content):
                logging.debug("Load content from the file")
                content = open(content, "r").read()

            logging.debug("Convert content")
            content = editor.textToENML(content)

            result['content'] = content

        if tags:
            result['tags'] = tools.strip(tags.split(','))

        if notebook:
            notepadGuid = Notebooks().getNoteGUID(notebook)
            if notepadGuid is None:
                newNotepad = Notebooks().create(notebook)
                notepadGuid = newNotepad.guid

            result['notebook'] = notepadGuid
            logging.debug("Search notebook")

        return result
예제 #6
0
    def _get_file_content(self, path):
        """
        Get file content.
        """
        content = open(path, "r").read()
        content = editor.textToENML(content=content, raise_ex=True)
        
        if content is None:
            logger.warning("File {0}. Content must be an UTF-8 encode.".format(path))
            return None

        return content
예제 #7
0
    def _get_file_content(self, path):
        """
        Get file content.
        """
        content = open(path, "r").read()
        content = editor.textToENML(content=content, raise_ex=True)

        if content is None:
            logger.warning("File {0}. Content must be an UTF-8 encode.".format(path))
            return None

        return content
예제 #8
0
파일: gnsync.py 프로젝트: lonnon/geeknote
    def _get_file_content(self, path):
        """
        Get file content.
        """
        content = open(path, "r").read()
        # strip unprintable characters
        content = ''.join(s for s in content if s in string.printable)
        content = editor.textToENML(content=content, raise_ex=True, format=self.format)
        
        if content is None:
            logger.warning("File {0}. Content must be an UTF-8 encode.".format(path))
            return None

        return content
예제 #9
0
    def _parseInput(self, title=None, content=None, tags=None, notebook=None, resources=None, note=None):
        result = {
            "title": title,
            "content": content,
            "tags": tags,
            "notebook": notebook,
            "resources": resources if resources else []
        }
        result = tools.strip(result)

        # if get note without params
        if note and title is None and content is None and tags is None and notebook is None:
            content = config.EDITOR_OPEN

        if title is None and note:
            result['title'] = note.title

        if content:
            if content == config.EDITOR_OPEN:
                logging.debug("launch system editor")
                if note:
                    self.getEvernote().loadNoteContent(note)
                    content = editor.edit(note.content)
                else:
                    content = editor.edit()

            elif isinstance(content, str) and os.path.isfile(content):
                logging.debug("Load content from the file")
                content = open(content, "r").read()

            logging.debug("Convert content")
            content = editor.textToENML(content)

            result['content'] = content

        if tags:
            result['tags'] = tools.strip(tags.split(','))

        if notebook:
            notepadGuid = Notebooks().getNoteGUID(notebook)
            if notepadGuid is None:
                newNotepad = Notebooks().create(notebook)
                notepadGuid = newNotepad.guid
            
            result['notebook'] = notepadGuid
            logging.debug("Search notebook")
            
        return result
예제 #10
0
    def _get_file_content(self, path):
        """
        Get file content.
        """
        content = open(path, "r").read()
        # strip unprintable characters
        content = ''.join(s for s in content if s in string.printable)
        content = editor.textToENML(content=content,
                                    raise_ex=True,
                                    format=self.format)

        if content is None:
            logger.warning(
                "File {0}. Content must be an UTF-8 encode.".format(path))
            return None

        return content