def _editWithEditorInThread(self, inputData, note = None): if note: self.getEvernote().loadNoteContent(note) editor = Editor(note.content) else: editor = Editor('') thread = EditorThread(editor) thread.start() result = True prevChecksum = editor.getTempfileChecksum() while True: if prevChecksum != editor.getTempfileChecksum() and result: newContent = open(editor.tempfile, 'r').read() inputData['content'] = Editor.textToENML(newContent) if not note: result = self.getEvernote().createNote(**inputData) # TODO: log error if result is False or None if result: note = result else: result = False else: result = bool(self.getEvernote().updateNote(guid=note.guid, **inputData)) # TODO: log error if result is False if result: prevChecksum = editor.getTempfileChecksum() if not thread.isAlive(): # check if thread is alive here before sleep to avoid losing data saved during this 5 secs break time.sleep(5) return result
def _editWithEditorInThread(self, inputData, note=None, raw=None): editor_userprop = getEditor(self.getStorage()) noteExt_userprop = getNoteExt(self.getStorage()).split(',')[bool(raw)] if note: self.getEvernote().loadNoteContent(note) editor = Editor(editor_userprop, note.content, noteExt_userprop, raw) else: editor = Editor(editor_userprop, '', noteExt_userprop, raw) thread = EditorThread(editor) thread.start() result = True prevChecksum = editor.getTempfileChecksum() while True: if prevChecksum != editor.getTempfileChecksum() and result: newContent = open(editor.tempfile, 'r').read() ext = os.path.splitext(editor.tempfile)[1] mapping = { 'markdown': config.MARKDOWN_EXTENSIONS, 'html': config.HTML_EXTENSIONS } fmt = filter(lambda k: ext in mapping[k], mapping) if fmt: fmt = fmt[0] inputData['content'] = newContent if raw \ else Editor.textToENML(newContent, format=fmt) if not note: result = self.getEvernote().createNote(**inputData) # TODO: log error if result is False or None if result: note = result else: result = False else: result = bool(self.getEvernote().updateNote(guid=note.guid, **inputData)) # TODO: log error if result is False if result: prevChecksum = editor.getTempfileChecksum() if not thread.isAlive(): # check if thread is alive here before sleep to avoid losing data saved during this 5 secs break time.sleep(5) self._finalizeEditor(editor, result) return result
def _editWithEditorInThread(self, inputData, note=None, raw=None): editor_userprop = self.storage.getUserprop('editor') noteExtension = self.storage.getUserprop('note_ext') if note: self.getEvernote().loadNoteContent(note) editor = Editor(editor_userprop, note.content, noteExtension, raw) else: editor = Editor(editor_userprop, '', noteExtension, raw) thread = EditorThread(editor) thread.start() result = True prevChecksum = editor.getTempfileChecksum() while True: if prevChecksum != editor.getTempfileChecksum() and result: newContent = open(editor.tempfile, 'r').read() ext = os.path.splitext(editor.tempfile)[1] mapping = {'markdown': ['.md', '.markdown'], 'html': ['.html', '.org']} fmt = filter(lambda k: ext in mapping[k], mapping) if fmt: fmt = fmt[0] inputData['content'] = newContent if raw \ else Editor.textToENML(newContent, format=fmt) if not note: result = self.getEvernote().createNote(**inputData) # TODO: log error if result is False or None if result: note = result else: result = False else: result = bool(self.getEvernote().updateNote(guid=note.guid, **inputData)) # TODO: log error if result is False if result: prevChecksum = editor.getTempfileChecksum() if not thread.isAlive(): # check if thread is alive here before sleep to avoid losing data saved during this 5 secs break time.sleep(5) self._finalizeEditor(editor, result) return result
def _editWithEditorInThread(self, inputData, note=None, raw=None): editor_userprop = getEditor(self.getStorage()) noteExt_userprop = getNoteExt(self.getStorage()).split(",")[bool(raw)] if note: self.getEvernote().loadNoteContent(note) editor = Editor(editor_userprop, note.content, noteExt_userprop, raw) else: editor = Editor(editor_userprop, "", noteExt_userprop, raw) thread = EditorThread(editor) thread.start() result = True prevChecksum = editor.getTempfileChecksum() while True: if prevChecksum != editor.getTempfileChecksum() and result: newContent = open(editor.tempfile, "r").read() ext = os.path.splitext(editor.tempfile)[1] mapping = {"markdown": config.MARKDOWN_EXTENSIONS, "html": config.HTML_EXTENSIONS} fmt = filter(lambda k: ext in mapping[k], mapping) if fmt: fmt = fmt[0] inputData["content"] = newContent if raw else Editor.textToENML(newContent, format=fmt) if not note: result = self.getEvernote().createNote(**inputData) # TODO: log error if result is False or None if result: note = result else: result = False else: result = bool(self.getEvernote().updateNote(guid=note.guid, **inputData)) # TODO: log error if result is False if result: prevChecksum = editor.getTempfileChecksum() if not thread.isAlive(): # check if thread is alive here before sleep to avoid losing data saved during this 5 secs break time.sleep(5) self._finalizeEditor(editor, result) return result