def closeOutput(self): self.closed = True if self._flushable(True): self._flush() self.session.close() if self.error: raise IOException('Error Uploading file...', self)
def flush(self): print("gdrive.OutputStream.flush() 1") if self.closed: print("gdrive.OutputStream.flush() ERROR") raise IOException('OutputStream is closed...', self) if self._flushable(True): self._flush() print("gdrive.OutputStream.flush() 2")
def export1(self, content, folder, task): toPerform = 1 contentDir = None try: task.setSubtaskName(TASK_EXPORT_PREPARE) # 1. create a content directory. # each content (at the moment there is only one :-( ) # is created in its own directory. # faileure here is fatal. contentDir = self.fileAccess.createNewDir(folder, content.cp_Name) if (contentDir is None or contentDir is ""): raise IOException("Directory " + folder + " could not be created.") content.dirName = FileAccess.getFilename(contentDir) task.advance1(True, TASK_EXPORT_DOCUMENTS) toPerform -= 1 # 2. export all documents and sub contents. # (at the moment, only documents, no subcontents) for item in content.cp_Documents.childrenList: try: # # In present this is always the case. # may be in the future, when # a tree is used, it will be abit different. if (isinstance(item, CGDocument)): if (not self.export2(item, contentDir, task)): return False elif (not self.export2(item, contentDir, task)): # we never get here since we # did not implement sub-contents. return False except SecurityException as sx: # nonfatal traceback.print_exc() if (not self.error(sx, item, ProcessErrors.ERROR_EXPORT_SECURITY, ErrorHandler.ERROR_NORMAL_IGNORE)): return False self.result = False except IOException as iox: # nonfatal traceback.print_exc() return self.error(iox, content, ProcessErrors.ERROR_EXPORT_IO, ErrorHandler.ERROR_NORMAL_IGNORE) except SecurityException as se: # nonfatal traceback.print_exc() return self.error(se, content, ProcessErrors.ERROR_EXPORT_SECURITY, ErrorHandler.ERROR_NORMAL_IGNORE) self.failTask(task, toPerform) return True
def closeOutput(self): print("gdrive.OutputStream.closeOutput() 1") self.closed = True if self._flushable(True): print("gdrive.OutputStream.closeOutput() 2") self._flush() print("gdrive.OutputStream.closeOutput() 3") self.session.close() if self.error: print("gdrive.OutputStream.closeOutput() ERROR") raise IOException('Error Uploading file...', self)
def writeBytes(self, sequence): if self.closed: print("gdrive.OutputStream.writeBytes(): ERROR %s" % self.length) raise IOException('OutputStream is closed...', self) self.buffers += sequence.value if self._flushable(): self._flush() print("gdrive.OutputStream.writeBytes(): %s" % self.length) #raise IOException('Error Uploading file...', self) else: print("gdrive.OutputStream.writeBytes() Bufferize: %s - %s" % (self.start, self.length))
def close_document(self): """ Close document. Close current document. @rtype: bool @return: Operation result """ result = False try: if self._oDoc: self._oDoc.close(True) self._oDoc = None result = True except ErrorCodeIOException as e: raise ErrorCodeIOException(e) except IOException as e: raise IOException(e) return result
def save_document(self, doc_name="", filter_name=""): """ Save document. @type doc_name: string @param doc_name: Document name. If no document name defined the current name is used. @type filter_name: string @param filter_name: file type: # ods="" # pdf="calc_pdf_Export" # csv="Text - txt - csv (StarCalc)" # xls="calc_MS_Excel_40" # xlsx="Calc Office Open XML" @rtype: bool @return: Operation result """ result = False if self._oDoc: if 0 == len(doc_name): self._oDoc.store() else: full_file_name = unohelper.systemPathToFileUrl(doc_name) try: self._oDoc.storeToURL( full_file_name, self._to_properties(FilterName=filter_name)) result = True except IllegalArgumentException as e: raise IllegalArgumentException(e) except ErrorCodeIOException as e: raise ErrorCodeIOException(e) except IOException as e: raise IOException(e) return result
def flush(self): if self.closed: raise IOException('OutputStream is closed...', self) if self._flushable(True): self._flush()
def writeBytes(self, sequence): if self.closed: raise IOException('OutputStream is closed...', self) self.buffers += sequence.value if self._flushable(): self._flush()