def grep(fileName, txt, resultList = None, doQuiet=False, caseSensitive=True): """ Exit status is 0 if selected lines are found and 1 if none are found. Exit status 2 is returned if an error occurred, unless the -q or --quiet or --silent option is used and a selected line is found. Instead of printing, a resultList will be filled if provided. """ if not os.path.exists(fileName): return 2 if not caseSensitive: txt = txt.lower() matchedLine = False for line in open(fileName): if len(line): line = line[:-1] # must be at least 1 char long else: nTcodeerror("Fix code in grep") lineMod = line if not caseSensitive: lineMod = lineMod.lower() if txt in lineMod: # nTdebug("Matched line in grep: %s" % lineMod) if resultList != None: resultList.append(line) if doQuiet: # important for not scanning whole file. return 0 matchedLine = True if matchedLine: return 0 return 1
def grep(fileName, txt, resultList=None, doQuiet=False, caseSensitive=True): """ Exit status is 0 if selected lines are found and 1 if none are found. Exit status 2 is returned if an error occurred, unless the -q or --quiet or --silent option is used and a selected line is found. Instead of printing, a resultList will be filled if provided. """ if not os.path.exists(fileName): return 2 if not caseSensitive: txt = txt.lower() matchedLine = False for line in open(fileName): if len(line): line = line[:-1] # must be at least 1 char long else: nTcodeerror("Fix code in grep") lineMod = line if not caseSensitive: lineMod = lineMod.lower() if txt in lineMod: # nTdebug("Matched line in grep: %s" % lineMod) if resultList != None: resultList.append(line) if doQuiet: # important for not scanning whole file. return 0 matchedLine = True if matchedLine: return 0 return 1
def _restoreFromSML(self, convention=constants.INTERNAL): """ Restore the MolDef instance from CING ResidueDef SML files """ rootPath = os.path.realpath(os.path.join(cingPythonCingDir, "Database", convention)) if not os.path.exists(rootPath): nTcodeerror('MolDef._restoreFromSML: rootPath "%s" does not exist; bailing out!', rootPath) sys.exit(1) # end if restoreFromSML(rootPath, self, convention=convention) self.postProcess() return NTdb
def capitalizeFirst(s): if s == None: return # end if if not isinstance(s, str): nTcodeerror('Failed capitalizeFirst with non string argument: [%s]' % str(s)) return # end if if len(s) < 1: return '' # end if firstChar = s[0].capitalize() if len(s) == 1: return firstChar # end if return firstChar + s[1:]
def getAtomDefByName(self, atmName, convention=constants.INTERNAL): """return AtomDef instance for atmName if atmName is a valid for convention or None otherwise. Do NOT print an error here because for optimal use the code is called many times in cases where no defs are available; e.g. pdbParser#_matchAtom2Cing """ if not atmName: nTcodeerror("ResidueDef.getAtomDefByName: atmName not defined") return None # end if if not self.atomDict.has_key(convention): # nTdebug('ResidueDef.getAtomDefByName: convention %s not defined within CING', convention) return None # end if an = atmName.strip() if self.atomDict[convention].has_key(an): return self.atomDict[convention][an] # endif return None