def main(): """Run all checks and handle fatal errors.""" try: sites_data = sites_from_file(config.MONITORED_SITES) RunChecks(sites_data).check_all() except Exception as fatal_err: # Fatal error during CSV read or RunChecks fatal_err_msg = logs.get_err_str(fatal_err, "Fatal error.") logs.log_error(fatal_err_msg) email_subject = "Robots.txt Check Fatal Error" email_content = "There was a fatal error during the latest robots.txt checks which " \ "caused the program to terminate unexpectedly." email_body = emails.get_admin_email_body(email_content) emails.admin_email.append( (config.ADMIN_EMAIL, email_subject, email_body)) finally: if config.EMAILS_ENABLED: emails.send_emails(emails.admin_email) else: print( "Note: emails are disabled. Details of the program run have been printed " "and/or logged. Set 'EMAILS_ENABLED' to equal 'True' to send/receive emails." ) logs.update_main_log("\n{}END OF RUN{}\n".format("-" * 20, "-" * 20), timestamp=False)
def assignRegWidByFields(self): curReg = False Wid = 0 Reset = 0 for Item in self.items: Reset = Item.Params['reset'] if (Item.Kind == 'reg') and ('wid' in Item.Params): curReg = Item Wid = curReg.Params['wid'] if curReg and (Wid == 0): logs.log_error('widhless register %s' % curReg.Name) elif (curReg): curReg.Params['wid'] = Wid curReg.Params['reset'] = Reset elif (Item.Kind == 'field'): if not curReg: logs.log_error('field without register %s' % Item.Name) if 'reset' in Item.Params: Rst = Item.Params['reset'] if Rst == '': Rst = 0 else: Rst = 0 Incr = Item.Params['wid'] Wid += Incr if curReg: curReg.Params['wid'] = Wid curReg.Params['reset'] = Reset
def is_edged_timing(List): if not List: return False if type(List) is str: return False if type(List) is tuple: if List[0] == '*': return False if List[1] == 'token': return False if List == '*': return False if List[0] == 'edge': return True if List[0] == 'list': edges = 0 nonedges = 0 for Item in List[1:]: if Item[1] in ['posedge', 'negedge']: edges += 1 else: nonedges += 1 if (edges > 0) and (nonedges > 0): logs.log_error( 'scan_rtl: is_edged_timing got edges and nonedges %s' % str(List)) return (edges > 0) logs.log_error('scan_rtl: is_edged_timing got %s' % str(List)) return False
def run(Fname, Regfiles, Dirx='.'): Present = {} for regFile in Regfiles: Cell, Dir, Ext = logs.fnameCell(regFile) Present[Cell] = regFile, Dir, Ext Mdfile = open('%s.md' % Fname, 'w') Csvfile = open('%s.csv' % Fname, 'w') for Rgf, Instance, Base in LIST: if Rgf not in Present: logs.log_error('needed rgf %s is not in given list %s' % (Rgf, list(Present.keys()))) else: regFile, Dir, Ext = Present[Rgf] if Dir == '': Dir = '.' if Ext == '': Rname = Rgf else: Rname = '%s.%s' % (Rgf, Ext) regfile.run(Rname, Dir, Base) Name = regfile.Db['module'] # if Name != Instance: # shutil.copyfile('%s.md' % Name, '%s.md' % Instance) Mdfile.write('# %s %s\n\n' % (Rgf, Instance)) Csvfile.write(',,,,\n,,,,\n,file,%s,%s,,,,\n\n' % (Rgf, Instance)) concatFile('%s.md' % Name, Mdfile) concatFile('%s.csv' % Name, Csvfile) # logs.log_info('%s %x %s' % (Rgf,regfile.Db['lastAddr'],list(regfile.Db.keys()))) Mdfile.close() Csvfile.close()
def addPort(Item,Mod): Vars = matches.matches_l(Item,'signal ? ?s ?s [ ?s ?s ?s ]') if Vars: Sigs = Vars[0] Dir = Vars[1] Kind = Vars[2] Hi = Vars[4] Lo = Vars[5] Wid = (Hi,Lo) addNet(Mod,Sigs,Dir,Kind,Wid) return Vars = matches.matches_l(Item,'signal ? ?s ?s [ ?s ? ?s ]') if Vars: Sigs = Vars[0] Dir = Vars[1] Kind = Vars[2] Hi = Vars[4] Lo = Vars[5] Wid = (Hi,Lo) addNet(Mod,Sigs,Dir,Kind,Wid) return Vars = matches.matches_l(Item,'signal ? ?s ?s ') if Vars: Sigs = Vars[0] Dir = Vars[1] Kind = Vars[2] Wid = 0 addNet(Mod,Sigs,Dir,Kind,Wid) return logs.log_error('addPort failed "%s"'%(str(Item)))
def combiAlways(When, Module): if When == '*': return True if When[0] == 'edge': return False if When[0] == 'list': return combiAlways(When[1], Module) logs.log_error('combiAlways failed on "%s" in %s' % (When, Module)) return False
def __init__(self, Kind, Path): self.Kind = Kind self.Path = Path self.Base = db.baseme(self) self.Pins = {} veri.force('%s.base' % (Path), str(self.Base)) if Kind == 'color': self.Color = logs.bin2str(veri.peek('%s.color' % (Path))) self.Clock = logs.bin2str(veri.peek('%s.clock' % (Path))) self.refClock = logs.bin2str(veri.peek('%s.refclock' % (Path))) if self.Clock != '': self.Cycle = 0 self.Pins['in0'] = newNet(self, 'in0', self.Base) self.Pins['out0'] = newNet(self, 'out0', self.Base) elif Kind == 'blob': self.Func = logs.bin2str(veri.peek('%s.func' % (Path))) self.Func = self.Func.replace('||', '|') self.Func = self.Func.replace('&&', '&') self.Func = self.Func.replace('!', '~') self.Vars = getVars(self.Func) for Var in self.Vars: self.Pins[Var] = newNet(self, Var, self.Base) self.Pins['out0'] = newNet(self, 'out0', self.Base) self.Vals = {} elif Kind == 'flop': self.Pins['clk'] = newNet(self, 'clk', self.Base) self.Pins['dd'] = newNet(self, 'dd', self.Base) self.Pins['qq'] = newNet(self, 'qq', self.Base) else: logs.log_error('kind is %s' % self.Kind)
def getprm(self, Field, Dir, Default=0): if Field in Dir: return Dir[Field] if Default == 'must': logs.log_error('MUST "%s" is missing from %s' % (Field, Dir)) return 0 return Default
def reading(self): if len(self.arqueue) > 4: self.force('arready', 0) elif self.peek('arvalid') == 1: self.force('arready', 1) arid = self.peek('arid') arburst = self.peek('arburst') araddr = self.peek('araddr') logs.log_info('>>>>>>>> %s %x' % (arburst, araddr)) arlen = self.peek('arlen') arsize = self.peek('arsize') self.arqueue.append((arburst, araddr, arlen, arsize)) self.rqueue.append(('wait', self.WAITREAD, 0)) for ii in range(arlen): self.readQueue(arlen, ii, arburst, arsize, araddr, arid, 0) self.readQueue(arlen, arlen, arburst, arsize, araddr, arid, 1) self.rqueue.append('pop') LastAddr = (araddr + (arlen + 1) * (1 << arsize)) - 1 LastPage = LastAddr & 0xffffe000 FirstPage = araddr & 0xffffe000 if (FirstPage != LastPage): logs.log_error( 'slave %s CROSSING 4K read araddr=%x arlen=%x arsize=%x' % (self.Name, araddr, arlen, arsize))
def my_importing(Fname): sys.path += ['.'] Orig = Fname if (len(Fname) > 2) and (Fname[-3:] == '.py'): Fname = Fname[:-3] if ('/' in Fname): wrds2 = Fname.split('/') Fname = wrds2[-1] Path = '/'.join(wrds2[:-1]) Path = os.path.abspath(Path) sys.path += [Path] That = importlib.import_module(Fname) print('importing0 "%s"' % Fname) That = importlib.import_module(Fname) print('importing1 "%s"' % Fname) if 'run' in dir(That): run = That.run That.Glbs = Glbs return Fname, run else: logs.log_error( 'in imported file "%s" You need to have "run(yada-yada-yada)" function' % (Fname)) return False, False
def evalit(self,Expr): try: Val = eval(Expr,self.Defines) except: logs.log_error('eval of "%s" failed, on %s'%(Expr,self.Defines.keys())) Val=0 return Val
def run(Fname): File = open(Fname) readFile(File) assignAddresses() Params = Db['chip'].Params['names'] Module = Params[0] Db['module'] = Module if 'axi4lite' in Params: Postfix = '_ram' elif 'apb' in Params: Postfix = '_ram' else: Postfix = '' Db['fout'] = dumpRam(Postfix) Db['lines'] = LINES if 'axi4lite' in Params: dumpAxi4lite(Db) elif 'apb' in Params: dumpApb(Db) elif 'ram' in Params: Db['fout'].close() else: logs.log_error('need to specify output format: apb ram axi4lite') dumpDefines() runXml() # report() # report2(LINES) return Db['module']
def evalExpr(self, Wrds1): self.Defs = {} self.DEFS = [] Wrds = Wrds1[:] for ind, Wrd in enumerate(Wrds): if (str(Wrd)[0] in '_' + string.ascii_letters) and (Wrd not in [ 'or', 'and', 'not' ]): if Wrd in self.Translates: self.Defs[Wrd] = self.Translates[Wrd] Wrds[ind] = self.Translates[Wrd] elif self.exists(Wrd): Val = self.peek(Wrd) self.Defs[Wrd] = Val self.DEFS.append((Wrd, Val)) Wrds[ind] = Val Txt = ' '.join(map(str, Wrds)) if Txt == '': return 0 try: X = eval(Txt, self.Defs, self.Translates) return X except: logs.log_error('evaluation of %s failed' % Txt, 0, True, True) logs.log_info('TRANSLATES %s' % (str(self.Translates))) logs.log_info('RDS %s' % (str(Wrds))) return 0
def action(self, Txt): if 'enable' in Txt: self.Enable = True return if 'disable' in Txt: self.Enable = False return if 'snapshot' in Txt: counts.snapshot() return wrds = Txt.split() if wrds[0] == []: pass elif wrds[0] == 'chance': self.Chance = eval(wrds[1]) + 1 elif wrds[0] == 'masters': self.Masters = [] for X in wrds[1:]: self.Masters.append(eval(X)) elif wrds[0] == 'lens': self.Lens = [] for X in wrds[1:]: self.Lens.append(eval(X)) elif wrds[0] == 'address': self.Addresses = [] for X in wrds[1:]: self.Addresses.append(eval(X)) logs.log_info('ADDRESSES %s' % (list(map(hex, self.Addresses)))) else: logs.log_error('ACTION unrecognized "%s" ' % Txt)
def help_main(Env): Mod = Env.Current Fout = open('%s.vx' % Mod.Module, 'w') for Net in Mod.nets: Dir, Wid = Mod.nets[Net] if (type(Wid) is tuple) or (type(Wid) is list): Widx = int(Wid[0]) - int(Wid[1]) + 1 Fout.write('net %s | width=%d ;\n' % (Net, Widx)) Inserts, Extracts = [], [] for Inst in Mod.insts: Type = Mod.insts[Inst].Type Obj = Mod.insts[Inst] if Type in renames: Type0 = renames[Type] else: logs.log_error('type %s is not renamed' % Type) Type0 = Type.lower() Str = 'inst %s %s ' % (Type0, Inst) for Pin in Obj.conns: Sig = Obj.conns[Pin] Pin, Dir = pinDir(Pin, Type) if type(Sig) is list: if Sig[0] == 'subbit': New = '%s_%s_' % (Sig[1], Sig[2]) DD, _ = Mod.nets[Sig[1]] if (Dir == '<'): if (Sig[1], Sig[2]) not in Extracts: Extracts.append((Sig[1], Sig[2])) elif (Dir == '>'): if (Sig[1], Sig[2]) not in Inserts: Inserts.append((Sig[1], Sig[2])) Sig = New Str += '%s%s%s ' % (Pin, Dir, Sig) Fout.write('%s\n' % Str) BUF = 0 for Dst, Src, _, _ in Mod.hard_assigns: if simple(Dst) and simple(Src): Fout.write('inst buf bufx%s a<%s o>%s ;\n' % (BUF, Src, Dst)) BUF += 1 else: print('ddd', Dst) print('sss', Src) Inserts.sort() Extracts.sort() for SigInd in Inserts: if SigInd in Extracts: II = Extracts.index(SigInd) Extracts.pop(II) for ind, (Sig, Dig) in enumerate(Inserts): Fout.write('inst insert insrert%d a<%s_%s_ o>%s | index=%s ;\n' % (ind, Sig, Dig, Sig, Dig)) for ind, (Sig, Dig) in enumerate(Extracts): Fout.write('inst extract extract%d a<%s o>%s_%s_ | index=%s ;\n' % (ind, Sig, Sig, Dig, Dig)) Fout.close()
def pacifyExpr(Expr): if isinstance(Expr,(str,int)): return Expr if (type(Expr) is list) and (len(Expr)==1): return pacifyExpr(Expr[0]) if type(Expr) is tuple: if Expr[0]=='subbit': if Expr[1] in ['to_integer','unsigned']: return pacifyExpr(Expr[2]) return Expr if Expr[0] in ['integer','reg','logic','funccall','bin','hex']: return Expr if Expr[0] in ['|','if','ifelse','<=','==','!=','+','-','&','~','curly','<','>']: Res = [Expr[0]]+list(map(pacifyExpr,Expr[1:])) return Res if Expr[0] in ['for']: Res = [Expr[0],Expr[1]]+list(map(pacifyExpr,Expr[2:])) return Res if Expr[0]=='subbus': return Expr if (type(Expr) is list) and (len(Expr)>0) and (Expr[0]=='list'): Res = ['list']+list(map(pacifyExpr,Expr[1:])) return Res if (type(Expr) is list) and (len(Expr)==0): return [] if (type(Expr) is list) and (Expr[0] in ['ifelse','if']): Res = [Expr[0]]+list(map(pacifyExpr,Expr[1:])) return Res logs.log_error('pacifyExpr got %s'%str(Expr)) return Expr
def getWid(Net,Wid,Mod): if Wid in ['0',0]: return 0 if Wid in ['1',1]: return 1 if type(Wid) is int: return Wid if type(Wid) is tuple: print('getWid',Wid) if len(Wid)==2: Hi = getWid(Net,Wid[0],Mod) Lo = getWid(Net,Wid[1],Mod) return Hi-Lo+1 if (len(Wid)==3)and(Wid[0]=='packed'): AA = getWid(Net,Wid[1],Mod) BB = getWid(Net,Wid[2],Mod) return AA*BB if type(Wid) is list: if Wid[0] == 'functioncall': if Wid[1]=='$clog2': X = getWid(Net,Wid[2][0],Mod) Bits = len(bin(X))-2 return Bits if len(Wid)==3: AA = getWid(Net,Wid[1],Mod) BB = getWid(Net,Wid[2],Mod) Str = '%s %s %s'%(AA,Wid[0],BB) return getWid(Net,Str,Mod) return 1 if type(Wid) is str: print('LOCAL',Mod.localparams) return eval(Wid,Mod.parameters,Mod.localparams) logs.log_error('wid of "%s" failed "%s"'%(Net,Wid)) return 1
def always(Mod): for Ind,Alw in enumerate(Mod.alwayses): if len(Alw[0]) > 2: Mod.alwayses[Ind] = '*',Alw[1],Alw[2] elif len(Alw[0]) == 1: Clk = Alw[0][0] Sig,Edge = scan_for_edges(Alw[1]) if Sig != Clk: logs.log_error('ILIA scan back=%s clk=%s edge=%s' % (Sig,Clk,Edge)) Alw = [(Edge,Sig)],Alw[1],Alw[2] Mod.alwayses[Ind] = Alw elif len(Alw[0]) == 2: Clk,Edge = scan_for_edges(Alw[1]) if (Clk == 'no')and(Edge == 'no'): Mod.alwayses[Ind] = '*',Alw[1],Alw[2] else: Sense = Alw[0][:] Sense.remove(Clk) Rst = Sense[0] if Alw[1][0] == 'ifelse': Cond = Alw[1][1] if (Cond[0] == '==')and(Cond[1]==Rst): if Cond[2] in [0,'0']: Rst = ('negedge',Rst) elif Cond[2] in [1,'1']: Rst = ('posedge',Rst) Alw = ['list',(Edge,Clk),Rst],Alw[1],Alw[2] Mod.alwayses[Ind] = Alw
def scanBody(Body, Conds, Path): if (type(Body) is tuple) or (type(Body) is list): if Body[0] in ['=', '<=']: Dsts = support_set(Body[1], False) Srcs = support_set(Body[2], False) for S in Srcs + Conds: for D in Dsts: recordTable(Path + '.' + S, Path + '.' + D) return if Body[0] == 'list': for Item in Body[1:]: scanBody(Item, Conds, Path) return if Body[0] == 'ifelse': More = support_set(Body[1], False) scanBody(Body[2], Conds + More, Path) scanBody(Body[3], Conds + More, Path) return if Body[0] == 'if': More = support_set(Body[1], False) scanBody(Body[2], Conds + More, Path) return if Body[0] == 'case': More = support_set(Body[1], False) for Label, Item in Body[2]: scanBody(Item, Conds + More, Path) return logs.log_error('scanBody failed on %s' % str(Body[0])) return
def scan_for_edges(Code): if Code[0] == '=': return 'no','no' if Code[0] == 'list': Clk,Edge = scan_for_edges(Code[1][0]) return Clk,Edge if Code[0] == 'if': Clk,Edge = scan_for_edges(Code[1]) return Clk,Edge if Code[0] == 'ifelse': Clk,Edge = scan_for_edges(Code[3]) return Clk,Edge if (Code[0] == 'subbit')and (Code[1] == 'rising_edge'): return Code[2],'posedge' if (Code[0] == '&')and (Code[1][0] == 'function') and (Code[1][1] == 'edge'): if Code[2][0] == '==': Clk = Code[2][1] if Code[2][2] in ['0',0]: return Clk,'negedge' if Code[2][2] in ['1',1]: return Clk,'posedge' if (Code[0] == '&')and (Code[2][0] == 'function') and (Code[2][1] == 'edge'): if Code[1][0] == '==': Clk = Code[1][1] if Code[1][2] in ['0',0]: return Clk,'negedge' if Code[1][2] in ['1',1]: return Clk,'posedge' if Code[0] == 'case': return 'no','no' logs.log_error('scan_for_edges %s' % str(Code)) return 'no','no'
def translate(self, Addr): if Addr[0] in '0123456789': return eval(Addr) if Addr in self.translations: return self.translations[Addr][0] logs.log_error('cannot determine "%s" address' % Addr) return 0
def buildMsg(Cmd, Tags, Bytes, Addr, Data): Word0 = 0 if type(Cmd) == types.IntType: Word0 = Cmd elif Cmd == 'read': Word0 = 1 elif Cmd == 'write': Word0 = 2 elif Cmd == 'mng': Word0 = 3 else: logs.log_error('reqMsg got cmd=%s' % Cmd) if type(Tags) == types.IntType: Word0 |= Tags << 2 elif (Tags in tagTypes): Word0 |= (tagTypes[Tags] << 2) elif (Tags == 'reset'): Word0 |= 0 << 2 elif (Tags == 'enumerate'): Word0 |= 2 << 2 elif (Tags == 'controls'): Word0 |= 4 << 2 elif (Tags == 'report'): Word0 |= 6 << 2 checkField("bytes", Bytes, 4) checkField("tags", Tags, 5) Word0 |= (Bytes << 7) Word0 |= (Addr << 11) Word0 |= (Data << 43) return Word0
def reworkIf(IF): if len(IF)==5: Else = IF[4][0][1] # info('IFFF5 %s\n %s\n %s\n %s\n %s\n\n\n'%(IF[0],IF[1],IF[2],IF[3],Else)) Cond = reworkExpr(IF[1]) Yes = reworkExpr(IF[2]) No = reworkExpr(putElse(IF[3],Else)) After = ['ifelse',Cond,Yes,No] return After if len(IF)==4: # info('IFFF4 %s %s %s %s'%(IF[0],IF[1],IF[2],IF[3])) Else = IF[3][0][0] if Else=='else': Else = IF[3][0][1:] Cond = reworkExpr(IF[1]) Yes = reworkExpr(IF[2]) No = reworkExpr(Else) IF = ['ifelse',Cond,Yes,No] if Else=='ifelse': Else = IF[3][0] Else = ['if',Else[1],Else[2]] Cond = reworkExpr(IF[1]) Yes = reworkExpr(IF[2]) No = reworkExpr(Else) IF = ['ifelse',Cond,Yes,No] return IF logs.log_error('moduleBuilder: reworkIf got %d %s'%(len(IF),IF)) return IF
def checkField(Name, Val, Width): if type(Val) != types.IntType: return A = bin(Val) X = len(A) - 2 if X > Width: logs.log_error('checkField width violartion field=%s exp=%d act=%d' % (Name, Width, X))
def evaluateExpr(self,Expr): if type(Expr) is str: if Expr in self.peekedBus: return self.peekedBus[Expr] Val = self.peekBus(Expr) self.peekedBus[Expr] = Val return Val if type(Expr) is int: return Expr if Expr[0] == '^': A = self.evaluateExpr(Expr[1]) B = self.evaluateExpr(Expr[2]) return A^B if Expr[0] == '&': A = self.evaluateExpr(Expr[1]) B = self.evaluateExpr(Expr[2]) return A&B if Expr[0] == '|': A = self.evaluateExpr(Expr[1]) B = self.evaluateExpr(Expr[2]) return A|B if Expr[0] == '~': A = self.evaluateExpr(Expr[1]) return ~A logs.log_error('evaluateExpr failed on "%s"' % str(Expr))
def runQueue(): global waiting # if len(Queue)>0: # logs.log_info('waiting=%d cmd0=%s len=%d '%(waiting,Queue[0],len(Queue))) # else: # logs.log_info('waiting=%d cmd0=0 len=%d '%(waiting,len(Queue))) if (waiting > 0): waiting -= 1 return while Queue != []: Cmd = Queue.pop(0) if Cmd[0] == 'wait': waiting = int(Cmd[1]) - 1 return if Cmd[0] == 'finish': logs.log_info('finishing on queue command') sys.exit() veri.finish() return if Cmd[0] == 'force': veri.force('tb.' + Cmd[1], str(Cmd[2])) # logs.log_info('forcing %s %s'%(Cmd[1],Cmd[2])) else: logs.log_error('bad queue directive "%s"' % str(Cmd))
def run(self): if not self.Enable: return if self.valid('awvalid') and self.valid('awready'): Awid = self.peek('awid') Awaddr = self.peek('awaddr') self.Awqueue.append((Awid, Awaddr)) self.Awqueueb.append((Awid, Awaddr)) if self.valid('wvalid') and self.valid('wready') and self.valid( 'wlast'): self.Wqueue += 1 if self.valid('bvalid') and self.valid('bready'): bid = self.peek('bid') self.Bids.append(bid) if (self.Bids != []) and (self.Wqueue > 0) and (self.Awqueue != []): if self.Wqueue > len(self.Awqueue): logs.log_error('prober %s: wqueue=%d > awqueue=%d' % (self.Name, self.Wqueue, len(self.Awqueue))) bid0 = self.Bids[0] for ind, (bid1, addr1) in enumerate(self.Awqueueb): if bid0 == bid1: self.Awqueueb.pop(ind) self.Bids.pop(0) bid0 = 10000 if bid0 != 10000: logs.log_error('prober %s: bid=%d not in the awqueue=%s' % (self.Name, bid0, self.Awqueueb)) self.Bids.pop(0)
def advanceAddr(Obj): if Obj.Kind == 'reg': logs.mustKey(Obj.Params, 'width') AA = computeWid(Obj) return AA * 4 elif Obj.Kind in ('array', 'ram'): Wid = Obj.Params['width'] Dep = Obj.Params['depth'] Num = computeWid(Obj) Tot = Dep * Num * 4 return Tot elif Obj.Kind == 'gap': if 'align' in Obj.Params: Align = Obj.Params['align'] X = int(Obj.Addr / Align) Diff = Obj.Addr - (X * Align) if Diff == 0: return 0 return (X + 1) * Align - Obj.Addr elif 'abs' in Obj.Params: return Obj.Params['abs'] else: logs.log_error('advanceAddr GAP got %s' % str(Obj.Params)) else: logs.log_error('advanceAddr got %s' % (Obj.Kind)) return 4
def getWid(Net, Wid, Mod): if Wid in ['0', 0]: return 0 if Wid in ['1', 1]: return 1 if type(Wid) is int: return Wid if type(Wid) is tuple: if len(Wid) == 2: Hi = getWid(Net, Wid[0], Mod) Lo = getWid(Net, Wid[1], Mod) return Hi - Lo + 1 if (len(Wid) == 3) and (Wid[0] == 'packed'): AA = getWid(Net, Wid[1], Mod) BB = getWid(Net, Wid[2], Mod) return AA * BB if type(Wid) is list: if len(Wid) == 3: AA = getWid(Net, Wid[1], Mod) BB = getWid(Net, Wid[2], Mod) Str = '%s %s %s' % (AA, Wid[0], BB) return getWid(Net, Str, Mod) return 1 if type(Wid) is str: return eval(Wid, Mod.parameters) logs.log_error('wid of "%s" failed "%s"' % (Net, Wid)) return 1
def sites_from_file(file): """Extract monitored sites data from a CSV and return as a list of lists. Args: file (str): file location of a CSV file with the following attributes: - Header row labelling the three columns, as listed below. - url (col1): the absolute URL of the website homepage, with a trailing slash. - name (col2): the website's name identifier (letters/numbers only). - email (col3): the email address of the site admin, who will receive alerts. """ data = [] with open(file, 'r') as sites_file: csv_reader = csv.reader(sites_file, delimiter=',') row_num = 0 for row in csv_reader: # Skip the header row labels if row_num > 0: try: data.append([row[0], row[1], row[2]]) except Exception as e: err_msg = logs.get_err_str( e, "Couldn't extract row {} from CSV." "".format(row_num)) logs.log_error(err_msg) row_num += 1 return data