def adminInfo(handler): handler.title('Information') requirePriv(handler, 'Admin') print "<div class=\"info\">" print "<h3>Uptime</h3>" loadTime = getLoadtime() print "Started %s<br>" % loadTime print "Up for %s<br>" % timesince(loadTime) print "Total requests: %d<br>" % server().getTotalRequests() print "<form method=\"post\" action=\"/admin/restart\">" print Button('Restart', type = 'submit').negative() print "</form>" print "<h3>Threads</h3>" print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">" print "<tr><th>ID</th><th class=\"main\">Name</th><th>Alive</th><th>Daemon</th></tr>" for thread in sorted(threads(), key = lambda thread: thread.name): print "<tr><td>%s</td><td>" % ('None' if thread.ident is None else "%x" % abs(thread.ident)) print thread.name print "<br>" try: print CollapsibleBox('Traceback', formatTrace(traceback.extract_stack(sys._current_frames()[thread.ident]))) except Exception: pass print "</td><td class=\"%s\"> </td><td class=\"%s\"> </td></tr>" % ('yes' if thread.isAlive() else 'no', 'yes' if thread.daemon else 'no') print "</table>" print "<h3>Locks</h3>" print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">" print "<tr><th class=\"main\">Name</th><th>Available</th><th>Reentrant</th></tr>" for (name, lock) in sorted(locks.iteritems()): print "<tr><td>" print name avail = lock.avail() if not avail: print "<br>" writer = ResponseWriter() try: owner, tb = lock.owner, lock.tb name = ("%x" % abs(owner)) if owner else 'None' #TODO Is there no O(1) way to do this? for thread in threads(): if thread.ident == owner: name = "%s (%x)" % (thread.name, abs(owner)) break print "Owned by: <b>%s</b><br><br>" % name if tb: print "Acquisition traceback:<br>" print formatTrace(tb) print "<br>" print "Current traceback:<br>" print formatTrace(traceback.extract_stack(sys._current_frames()[owner])) except Exception, e: writer.clear() print "<i>(Unable to retrieve stack trace)</i>" print CollapsibleBox('Ownership', writer.done()) print "</td><td class=\"%s\">%s</td><td class=\"%s\"> </td></tr>" % ('yes' if avail else 'no', ' ' if avail else (lock.owner or '???'), 'yes' if lock.reentrant() else 'no')
def mKill(self, params, peer): debug('Kill "' + str(params) + '"') if type(params) is int: debug("Removing from queue") self.queue.delete(params) debug(self.queue) self.inform('done', params) elif self.processor.cur and (params == "lock" or params == str(self.processor.cur.id)): debug("Stopping current job") if self.processor.unlocked.isSet(): killpg(self.processor.pid, 9) # Kill current task with SIGKILL else: self.processor.unlocked.set() else: all_threads = threads() for thread in all_threads: if thread.name.startswith('Receiver') and thread.job.id == int( params): debug('Killing job ' + params) thread.stop()
def mKill(self, params, peer): debug('Kill "' + str(params) + '"') if type(params) is int: debug("Removing from queue") self.queue.delete(params) debug(self.queue) self.inform('done', params) elif self.processor.cur and ( params == "lock" or params == str(self.processor.cur.id)): debug("Stopping current job") if self.processor.unlocked.isSet(): killpg(self.processor.pid, 9) # Kill current task with SIGKILL else: self.processor.unlocked.set() else: all_threads = threads() for thread in all_threads: if thread.name.startswith('Receiver' ) and thread.job.id == int(params): debug('Killing job ' + params) thread.stop()
"XtQBdeR0zHYmdo52RXYNnvQ+2dNt293+o9GPh06pnqo5LXu69AzhTMGZT2dzz86dSz83" "cz7h/HhPTM/9CxEXbvUG9g5c9Ll4+ZL7pQt9Tn1nL9tdPnXF5srJq4yrndcsr3X0W/S3" "/2TxU/uA5UDHdavrXTesb3QPLh88M+QwdP6m681Lt7xuXbu94vbgcOjwnZHokdE77DtT" "d1PuvriXeW/h/sYH6AdFD6UeVjxSfNTws+7PbaOWo6fHXMf6Hwc/vj/OGn/2S8Yv7ycK" "npCfVEyqTDZPmU2dmnafvvF05dOJZ+nPFmYKf5X+tfa5zvMffnP8rX82YnbiBf/Fp99L" "Xsq/PPRq2aueuYC5R69TXy/MF72Rf3P4LeNt37vwd5MLWe+x7ys/6H7o/ujz8cGn1E+f" "/gUDmPP8usTo0wAAAGJJREFUWMNjYBhi4D8R+BUDA4MWsQYy0cih9wfaAYrEKmTEE9S0" "AIz0CgGiAQs+yes3r1PFEk11TbqnAYaBToSjDhh1wKgDqFMQZTDYjUbBqANGHTDqgFEH" "jDqA5mC0XzAKAES7EOxy1gLHAAAAAElFTkSuQmCC")) from threading import enumerate as threads from wx.lib.mixins.listctrl import CheckListCtrlMixin from ctypes import wintypes, Structure, POINTER, pointer, windll, WinError SYS_VSCROLL_X = wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X) ACV = wx.ALIGN_CENTER_VERTICAL ST = [i for i in threads() if i.name == "SchedulerThread"][0] #=============================================================================== class SYSTEM_POWER_STATUS(Structure): _fields_ = [ ('ACLineStatus', wintypes.c_ubyte), ('BatteryFlag', wintypes.c_ubyte), ('BatteryLifePercent', wintypes.c_ubyte), ('Reserved1', wintypes.c_ubyte), ('BatteryLifeTime', wintypes.DWORD), ('BatteryFullLifeTime', wintypes.DWORD), ] SYSTEM_POWER_STATUS_P = POINTER(SYSTEM_POWER_STATUS)
def main() -> None: """Функция запуска бота и прослушивание им сообщений от пользователя""" Config.read_config() print(Fore.BLUE + "Файл настроек загружен!" + Style.RESET_ALL) try: vk_session = VkApi(token=Config.get_token()) longpoll = VkLongPoll(vk_session) print(Fore.BLUE + "Бот залогинился!" + Style.RESET_ALL) except ApiError: exit( "Ошибка! Неправильно введён токен для бота! Измените токен бота на правильный!" ) return vk_session_user = None if Config.get_user_info(): chdir(Config.get_dir_name()) login, password = Config.get_user_info() captcha = None while True: try: if captcha is not None: raise captcha vk_session_user = VkApi(login, password) vk_session_user.auth() break except Captcha as ex: try: print( Fore.RED + f"Нужна капча! Пройдите по этой ссылке {ex.get_url()} и решите её!" + Style.RESET_ALL) captcha_solve = input("Введите капчу: ") ex.try_again(captcha_solve) except Captcha as ex_c: captcha = ex_c except BadPassword: vk_session_user = None print( Fore.RED + "Ошибка! Логин и/или пароль пользователя для бота введены не правильно! " "Функции подкоманд 'Мем' не будут работать!" + Style.RESET_ALL) break chdir("..") print(Fore.BLUE + "Пользователь для бота авторизировался!" + Style.RESET_ALL) else: print( Fore.YELLOW + "Логин и/или пароль пользователя для бота не введены. Функции подкоманд 'Мем' не доступны!" + Style.RESET_ALL) ensure_tables_created() print(Fore.BLUE + "Соединение с базой данных установлено!" + Style.RESET_ALL) if Config.get_init_database(): InitDatabase.ensure_start_data_added() if "checking_schedule_on_changes" not in [i.name for i in threads()]: thread_1 = Thread(target=checking_schedule_on_changes, name="checking_schedule_on_changes", daemon=True) print(Fore.CYAN + "Бот запустил поток проверки расписания!" + Style.RESET_ALL) thread_1.start() print(Fore.LIGHTMAGENTA_EX + "Бот начал слушать сообщения!" + Style.RESET_ALL) for event in longpoll.listen(): if event.type == VkEventType.MESSAGE_NEW and ( event.text or "attach1_kind" in event.attachments) and event.to_me: user_message = event.text if "attach1_kind" in event.attachments and event.attachments[ "attach1_kind"] == 'audiomsg': attachs = eval(event.attachments["attachments"]) try: user_message = SpeechRecognizer.get_phrase( attachs[0]['audio_message']['link_mp3']).lower() except ValueError: user_message = "ошибка при обработке звукового сообщения" bot = VkBotChat(vk_session, event.user_id, vk_session_user) try: bot.get_response(user_message) except BaseException: bot.get_response(None) print_exc() exit()