def run_in_thread(on_exit, args): proc = subprocess.Popen(*args) proc.wait() on_exit(proc) syslog.syslog(syslog.LOG_NOTICE, "Results path is: %s" % args[0][args[0].index('--outputdir') + 1]) self.my_run.status = (proc.returncode == 0) and True or False self.my_run.finish = datetime.now(tz(config.path.time_difference)).replace(tzinfo=None) self.my_run.save() return
def fetch(self): try: if not self.uid: self.uid = get_uid() for main_run in Run.objects.filter( Q(hwaddr=self.hwaddr, rerun=True) | Q(hwaddr=None)): #syslog.syslog(syslog.LOG_DEBUG, 'main: ' + str(main_run)) i = 0 task = main_run.task main_run_id = main_run.pk my_previous_runs = Run.objects.filter(hwaddr=self.hwaddr, task=task, rerun=False) #syslog.syslog(syslog.LOG_DEBUG, 'prev: ' + str(my_previous_runs)) if (not main_run.hwaddr and my_previous_runs) or ( main_run.hwaddr and my_previous_runs and any( map(lambda prev: prev.id > main_run.id, my_previous_runs))): continue my_run = Run( task_id=main_run.task.pk, hwaddr=self.hwaddr, ip=self.ip, uid=self.uid, start=datetime.now(tz( config.path.time_difference)).replace(tzinfo=None)) my_run.save() _id = "%s_%04d_%s" % (task.name, my_run.pk, self.ip) _cmd = [ 'python2.7', config.path.pybot, '--critical', 'critical', '--pythonpath', "%s:%s" % (config.path.listener_path, config.path.suits_path), '--listener', "%(module)s:%(run_id)s:%(uid)s" % { 'module': config.path.listener, 'run_id': my_run.pk, 'uid': self.uid } ] _suites = set() for test in task.tests.all(): _cmd += ['--test', test.name] _suites.add(test.suite.path) _outputdir = my_run.path_to_results _cmd += ['--outputdir', _outputdir] _cmd += _suites if not os.path.isdir(_outputdir): os.mkdir(_outputdir) Task(self, my_run.pk, on_exit, (_cmd, 0, None, None, subprocess.PIPE, subprocess.PIPE)) except Exception, e: syslog.syslog(syslog.LOG_DEBUG, "Cannot fetch tasks: %s, %s" % (e.message, e.args))
def run_in_thread(on_exit, args): proc = subprocess.Popen(*args) proc.wait() on_exit(proc) syslog.syslog( syslog.LOG_NOTICE, "Results path is: %s" % args[0][args[0].index('--outputdir') + 1]) self.my_run.status = (proc.returncode == 0) and True or False self.my_run.finish = datetime.now(tz( config.path.time_difference)).replace(tzinfo=None) self.my_run.save() return
def fetch(self): try: if not self.uid: self.uid = get_uid() for main_run in Run.objects.filter( Q(hwaddr=self.hwaddr, rerun=True) | Q(hwaddr=None)): #syslog.syslog(syslog.LOG_DEBUG, 'main: ' + str(main_run)) i = 0 task = main_run.task main_run_id = main_run.pk my_previous_runs = Run.objects.filter( hwaddr=self.hwaddr, task=task, rerun=False) #syslog.syslog(syslog.LOG_DEBUG, 'prev: ' + str(my_previous_runs)) if (not main_run.hwaddr and my_previous_runs) or ( main_run.hwaddr and my_previous_runs and any( map(lambda prev: prev.id > main_run.id, my_previous_runs))): continue my_run = Run( task_id=main_run.task.pk, hwaddr=self.hwaddr, ip=self.ip, uid=self.uid, start=datetime.now(tz( config.path.time_difference)).replace(tzinfo=None)) my_run.save() _id = "%s_%04d_%s" % (task.name, my_run.pk, self.ip) _cmd = [ 'python2.7', config.path.pybot, '--critical', 'critical', '--pythonpath', "%s:%s" % (config.path.listener_path, config.path.suits_path), '--listener', "%(module)s:%(run_id)s:%(uid)s" % { 'module': config.path.listener, 'run_id': my_run.pk, 'uid': self.uid } ] _suites = set() for test in task.tests.all(): _cmd += ['--test', test.name] _suites.add(test.suite.path) _outputdir = my_run.path_to_results _cmd += ['--outputdir', _outputdir] _cmd += _suites if not os.path.isdir(_outputdir): os.mkdir(_outputdir) Task(self, my_run.pk, on_exit, (_cmd, 0, None, None, subprocess.PIPE, subprocess.PIPE)) except Exception, e: syslog.syslog(syslog.LOG_DEBUG, "Cannot fetch tasks: %s, %s" % (e.message, e.args))
def privmsg(self, user, channel, msg): # What happens when bot gets a message self.count = self.count + 1 swag = user.split('!') user = user.split('!', 1)[0] # Turn user!ident@host into nickname print("%s:<%s> %s" % (channel, user, msg)) # Show the message in console capsIntact = msg if channel == self.nickname: # Check if it's a private message pm = 1 else: pm = 0 # append(channel, user, msg) msg = msg.lower() if swag[1].lower() in self.opersh or channel.lower() == "#dino": # if the user is in the oper list admin = 1 else: admin = 0 if channel == "#thegrammarnaziboners": tstchan = 1 else: tstchan = 0 insult_ = True fibo_ = True choose_ = True dict_ = True wiki_ = True tz_ = True wz_ = True rule_ = True convert_ = True flist = {'insult': insult_, 'fibo': fibo_, 'choose': choose_, 'dict': dict_, 'wiki': wiki_, 'wz': wz_, 'tz': tz_, 'rule': rule_, 'convert': convert_} if msg.startswith("~die"): try: if admin == 1: if user.lower() in self.azi: print "Killed by %s" % user reactor.stop() else: self.notice(user, "Not amused") print("%s attempted to kill me!") except: self.notice(user, "You are not authorized to perform this command.") print("%s attempted to kill me!" % user) elif msg.startswith("~set ") and swag.lower() == "*****@*****.**": # self.sendLine("MODE %s +B %s" % (self.nickname, self.nickname)) self.mode(self.nickname, True, 'B', limit=None, user=self.nickname, mask=None) elif msg.startswith("~stop") and admin == 1: self.quit() elif msg.startswith("~id") and (admin == 1 or user.lower == "Kojiro"): self.msg("Nickserv", "identify hamsterbot %s" % self.password) elif msg.startswith("~ghost ") and admin == 1: msg = msg.split() self.msg("Nickserv", "ghost %s swagonball" % msg[1]) elif msg.startswith("~donut") and admin == 1: msg = msg.split(' ') try: if msg[1].isdigit(): #hopefully if i use a number it'll join that chan i = int(msg[1]) chan = self.chanlist[i] self.join(chan) #why doesnt this work nvm it does elif msg[1] == "joinall" or msg[1] == "all": for item in self.chanlist: self.join(item) else: self.join(msg[1]) except: if admin != 1: self.notice(user, "You are not authorized to perform this command.") else: self.say(channel, "-_-") elif msg.startswith("~bye"): try: if admin == 1: self.part(channel) except: self.notice(user, "You are not authorized to perform this command.") print("%s attempted to use command ~bye." % user) elif msg.startswith("~nick"): try: if admin == 1: msg = msg.split(' ') self.setNick(msg[1]) except: self.notice(user, "You are not authorized to perform this command.") print("%s tried to change my nick" % user) elif msg.startswith("~toggle ") and admin == 1: msg = msg.split() if len(msg) == 3: if flist.has_key(msg[1]): funct = msg[1].strip() if msg[2].strip() == "on" or msg[2] == '1': flist[funct] = True elif msg[2].strip() == 'off' or msg[2] == '0': flist[funct] = False elif msg[2] == 'not': flist[funct] = not flist[funct] else: self.notice(user, "Values accepted: on/off or 1/0") else: self.notice(user, "No function found with that name or function may not be switched on/off") elif len(msg) == 2: if msg[1] == 'help': self.notice(user, "The following functions may be switched on/off: insult, choose, convert, dict, fibo, rule, tz, wz, wiki") elif msg[1] == 'is_on': is_on = [] for key, value in flist.iteritems(): if value == True: is_on.append(key) self.notice(user, "The following functions are on: %r" % is_on) else: self.notice(user, "Toggle takes 2 arguments. Do ~toggle help for functions that may be toggled on/off") elif msg.startswith("~say ") and admin == 1: msg = msg[5:] self.say(channel, msg) elif msg.startswith("~note ") and (swag[1].lower()=="*****@*****.**"): msg = msg[6:] # bs.notes(str(msg)) self.notice(user, notes(str(msg))) elif msg.startswith(":prefixes "): msg = msg[10:] self.say(channel, whattodo(msg, user)) elif msg.startswith(".insult ") and insult_ == True: msg = msg.split(' ') #nick = msg[1] try: if msg[1].lower() in self.azi: self.say(channel, random.choice(azi_insults)) elif msg[1].lower() == "?roulette": self.say(channel, "%s, %s" % (user, random.choice(insults))) else: insult = "%s, %s" % (msg[1], random.choice(insults)) self.say(channel, insult) except IndexError: self.say(channel, random.choice(insults)) elif msg.startswith(".inslut") and flist['insult'] == True: msg = msg.split(' ') insult = "%s, %s" % (user, random.choice(insults)) self.say(channel, insult) elif msg.startswith(".halp") or msg.startswith(".help"): try: if admin == 1: self.notice(user, "Commands: .help, .insult <user>, .fibo, .convert <conversion> <numbers>, .gay, .rule <1-47>, .choose <option1, option2,...>, .dict <query>") self.notice(user, "Restricted commands: ~die, ~bye, ~donut <channel>, ~nick <newnick>") except: self.notice(user, "Commands: .help, .about, .insult <user>, .fibo, .convert <conversion> <numbers>") # elif msg.startswith("~~"): # msg = msg.strip("~~") # exec(msg) elif msg.startswith(".choose ") and flist['choose'] == True: msg = msg[8:] # re.sub("or*", '', msg) msg = msg.split(",") msg = random.choice(msg) words = msg.split(' ') if words[0] == 'or' and len(words) > 1: msg = msg.replace('or ','') self.msg(channel, "%s: %s" % (user, msg.strip())) # elif msg.startswith(".last"): # msg = msg[5:] # list = last(channel, msg) # for item in list: # self.msg(user, item) elif msg.startswith(".wiki ") and flist['wiki'] == True: #broken wikipedia feature msg = msg[6:] msg = msg.replace(' ', '_') self.msg(channel, str(wiki(str(msg)))) elif msg.startswith(".dict ") and flist['dict'] == True: #dictionary feature # msg = capsIntact msg = msg[6:] self.msg(channel, dict(msg)) elif msg.startswith(".tz ") and flist['tz'] == True: #timezone feature msg = msg[4:] self.msg(channel, tz(msg)) elif msg.startswith(".wz ") and flist['wz'] == True: #weatherbot feature msg = msg[4:] self.msg(channel, wz(msg)) elif msg.startswith(".gay"): self.msg(channel, "%s: http://blog.okcupid.com/index.php/gay-sex-vs-straight-sex" % user) elif msg.startswith(".rule ") and flist['rule'] == True: msg = msg.split() self.msg(channel, rules((msg[1].strip()))) elif msg.startswith(".fibo") and flist['fibo'] == True: msg = msg.split(' ') num = msg[1] i = fib2(int(num)) self.msg(channel, str(i)) elif msg.startswith(".convert") and flist['convert'] == True: msg = msg.split(' ') if convert(msg).startswith('S') or convert(msg).startswith('N'): if '::' in convert(msg): resp = convert(msg).split('::') self.notice(user, resp[0]) self.notice(user, resp[1]) else: self.notice(user, convert(msg)) elif pm == 1: self.notice(user, convert(msg)) else: self.msg(channel, convert(msg))