def analyseLine(line, csvlist, linecount): try: tmplist = csvlist[:] hostname = None ans = [] for cell in line: bit = xlutil.cellConvert(cell) if not tmplist: # Someone has added extra fields in the data line break curcol = tmplist.pop(0) if curcol == '-': continue if bit == '': continue if curcol == 'hostname' and bit: hostname = sanitiseHostname(bit) else: if bit not in ('unknown', ''): ans.extend(foundValue(curcol, bit)) if hostname in ('', 'None', None): warning("No hostname to use on line %d" % linecount) return if hostname.startswith('???'): warning("No good hostname to use on line %d - %s" % (linecount, hostname)) return if hostname not in hostinfo_cache: runCmd("hostinfo_addhost --origin '%s' %s" % (origin, hostname)) for key, value in ans: if value and value != '???': update(hostname, key, value) except: warning("Failed on line %d: %s" % (linecount, line)) raise
def analyseLine(line, csvlist, linecount): try: tmplist=csvlist[:] hostname=None ans=[] for cell in line: bit=xlutil.cellConvert(cell) if not tmplist: # Someone has added extra fields in the data line break curcol=tmplist.pop(0) if curcol=='-': continue if bit=='': continue if curcol=='hostname' and bit: hostname=sanitiseHostname(bit) else: if bit not in ('unknown', ''): ans.extend(foundValue(curcol, bit)) if hostname in ('', 'None', None): warning("No hostname to use on line %d" % linecount) return if hostname.startswith('???'): warning("No good hostname to use on line %d - %s" % (linecount, hostname)) return if hostname not in hostinfo_cache: runCmd("hostinfo_addhost --origin '%s' %s" % (origin,hostname)) for key,value in ans: if value and value!='???': update(hostname, key, value) except: warning("Failed on line %d: %s" % (linecount, line)) raise
def analyseHeaders(rowdata): """Work out from the header of the CSV file what all the columns mean """ csvlist = [] for col in rowdata: found = False data = xlutil.cellConvert(col) if not data: continue data = data.lower() for key in hostinfo: if data in hostinfo[key]['aka']: csvlist.append(key) found = True continue if not found: csvlist.append('-') if verbflag: print "CSV to key mapping" for i in range(len(csvlist)): try: rowdata[i] except IndexError: continue if csvlist[i] == '-': print "\t%s-> unmapped" % rowdata[i] else: print "\t%s->%s" % (rowdata[i], csvlist[i]) return csvlist
def analyseHeaders(rowdata): """Work out from the header of the CSV file what all the columns mean """ csvlist=[] for col in rowdata: found=False data=xlutil.cellConvert(col) if not data: continue data=data.lower() for key in hostinfo: if data in hostinfo[key]['aka']: csvlist.append(key) found=True continue if not found: csvlist.append('-') if verbflag: print "CSV to key mapping" for i in range(len(csvlist)): try: rowdata[i] except IndexError: continue if csvlist[i]=='-': print "\t%s-> unmapped" % rowdata[i] else: print "\t%s->%s" % (rowdata[i], csvlist[i]) return csvlist