def insertEx(self, refTextRough, deleteRefNum, updatingEx): """Set updatingEx to True if updating the example.""" logger.debug(util.funcName('begin', args=refTextRough)) logger.debug("%d examples", len(self.examplesDict)) refnum = refTextRough.strip() if refnum.startswith("#"): refnum = refnum[1:] # keep all but first character ## Select the specified ref number refnum_key = refnum.lower() # case insensitive if refnum_key in self.examplesDict: logger.debug( "Inserting '%s'", self.examplesDict[refnum_key].refText) ## Display the data in the Writer doc if updatingEx: self.exUpdater.gotoAfterEx() self.outputManager.setConfig(self.settings.getOutconfig()) self.outputManager.outputExample( self.examplesDict[refnum_key], deleteRefNum, updatingEx) else: raise exceptions.DataNotFoundError( *self.messageAndSuggestions( "Could not find ref number %s", [refnum]))
def _verifyDataFound(self): """Derived classes should override if they don't want this check to be performed. """ if not self.data: raise exceptions.DataNotFoundError( "Did not find any data in file %s", self.filepath)
def _verifyDataFound(self): if not self.data: scope_string = ScopeType.TO_STRING[self.scopeType] logger.debug( "Searched by %s in folder %s but did not find anything.", scope_string, self.srcdir) raise exceptions.DataNotFoundError( "Searched by %s but did not find anything.", scope_string)
def getStringParam(strval): """Prepare the string to pass as a parameter to C++ code. :returns: None if an error occurs On Windows, with the converter name, either using c_char_p or else encoding results in ECDriver returning -7 Name Not Found error. """ try: if platform.system() == "Windows": return ctypes.c_wchar_p(strval) else: byteStr = strval.encode('utf-8') return ctypes.c_char_p(byteStr) except UnicodeEncodeError: raise exceptions.DataNotFoundError("Failed to encode string properly.")
def _read(self): progressRange = ProgressRange(ops=len(self.config.fileList), pbar=self.progressBar) progressRange.partSize = 3 self.suggestions = [] self.duplicate_refnums = set() list_index = 1 # 1-based index of current element in list for fileItem in self.config.fileList: logger.debug("Parsing file %s", fileItem.filepath) self.prefix = fileItem.prefix self.use_segnum = fileItem.use_segnum self.dom = None if not os.path.exists(fileItem.filepath): raise exceptions.FileAccessError("Cannot find file %s", fileItem.filepath) try: self.dom = xml.dom.minidom.parse(fileItem.filepath) except (xml.parsers.expat.ExpatError, IOError) as exc: raise exceptions.FileAccessError("Error reading file %s\n\n%s", fileItem.filepath, str(exc).capitalize()) logger.debug("Parse finished.") progressRange.updatePart(1) filetype = self.get_filetype(fileItem.filepath, self.dom) progressRange.updatePart(2) prevLen = len(self.data) if filetype == "toolbox": ToolboxXML(self).read() elif filetype == "fieldworks": FieldworksXML(self).read() logger.debug("Read %d examples.", len(self.data)) if len(self.data) == prevLen: raise exceptions.DataNotFoundError( "Did not find any data in file %s", fileItem.filepath) progressRange.update(list_index) list_index += 1
def convert(self, sInput): """:returns: converted unicode string""" logger.debug(util.funcName('begin')) if not self.config.convName: raise exceptions.LogicError("No converter was specified.") logger.debug("Using conv name %r", self.config.convName) c_convName = getStringParam(self.config.convName) logger.debug(repr(sInput)) c_input = getStringParam(sInput) if c_input is None: raise exceptions.DataNotFoundError("No conversion result.") # ECDriver will truncate the result if we go over this amount. c_outSize = ctypes.c_int(10000) bufOutput = createBuffer(c_outSize.value) logger.debug("Calling ConvertString using %s.", self.config.convName) status = self.funcConvertString(c_convName, c_input, bufOutput, c_outSize) verifyStatusOk(status) sOutput = bufOutput.value if platform.system() != "Windows": sOutput = sOutput.decode("utf-8") logger.debug(repr(sOutput)) logger.debug(util.funcName('end')) return sOutput
def noUserVarData(varName): return exceptions.DataNotFoundError( u"Error parsing %s user variable. Please go to Insert -> " u"Field -> More Fields and fix the problem.", varName)