def main(): # TODO: *actual* argparsing if '--no-checks' not in sys.argv: sanity_checks() finalize_logging() import asyncio tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: # Maybe I need to try to import stuff first, then actually import stuff # It'd save me a lot of pain with all that awful exception type checking m = None try: from musicbot import MusicBot m = MusicBot() sh.terminator = '' log.info("Connecting") sh.terminator = '\n' m.run() except SyntaxError: log.exception("Syntax error (this is a bug, not your fault)") break print() log.info("All done.")
def main(): if not sys.version_info >= (3, 5): print("Python 3.5+ is required. This version is %s" % sys.version.split()[0]) print("Attempting to locate python 3.5...") pycom = None # Maybe I should check for if the current dir is the musicbot folder, just in case if sys.platform.startswith('win'): try: subprocess.check_output('py -3.5 -c "exit()"', shell=True) pycom = 'py -3.5' except: try: subprocess.check_output('python3 -c "exit()"', shell=True) pycom = 'python3' except: pass if pycom: print("Python 3 found. Launching bot...") os.system('start cmd /k %s run.py' % pycom) sys.exit(0) else: try: pycom = subprocess.check_output(['which', 'python3.5']).strip().decode() except: pass if pycom: print("\nPython 3 found. Re-launching bot using: ") print(" %s run.py\n" % pycom) os.execlp(pycom, pycom, 'run.py') print("Please run the bot using python 3.5") input("Press enter to continue . . .") return import asyncio tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: # Maybe I need to try to import stuff first, then actually import stuff # It'd save me a lot of pain with all that awful exception type checking try: from musicbot import MusicBot m = MusicBot() print("Connecting...", end='', flush=True) m.run() except SyntaxError: traceback.print_exc() break except ImportError as e: if not tried_requirementstxt: tried_requirementstxt = True # TODO: Better output print(e) print("Attempting to install dependencies...") err = PIP.run_install('--upgrade -r requirements.txt') if err: print("\nYou may need to %s to install dependencies." % ['use sudo', 'run as admin'][sys.platform.startswith('win')]) break else: print("\nOk lets hope it worked\n") else: traceback.print_exc() print("Unknown ImportError, exiting.") break except Exception as e: if hasattr(e, '__module__') and e.__module__ == 'musicbot.exceptions': if e.__class__.__name__ == 'HelpfulError': print(e.message) break elif e.__class__.__name__ == "TerminateSignal": break elif e.__class__.__name__ == "RestartSignal": loops = -1 else: traceback.print_exc() finally: asyncio.set_event_loop(asyncio.new_event_loop()) loops += 1 print("Cleaning up... ", end='') gc.collect() print("Done.") sleeptime = min(loops * 2, max_wait_time) if sleeptime: print("Restarting in {} seconds...".format(loops*2)) time.sleep(sleeptime)
def main(): # TODO: *actual* argparsing if '--no-checks' not in sys.argv: sanity_checks() finalize_logging() import asyncio tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: # Maybe I need to try to import stuff first, then actually import stuff # It'd save me a lot of pain with all that awful exception type checking m = None try: from musicbot import MusicBot m = MusicBot() sh.terminator = '' log.info("Connecting") sh.terminator = '\n' m.run() except SyntaxError: log.exception("Syntax error (this is a bug, not your fault)") break except ImportError: # TODO: if error module is in pip or dpy requirements... if not tried_requirementstxt: tried_requirementstxt = True log.exception("Error starting bot") log.info("Attempting to install dependencies...") err = PIP.run_install('--upgrade -r requirements.txt') if err: # TODO: add the specific error check back as not to always tell users to sudo it print() log.critical( "You may need to %s to install dependencies." % ['use sudo', 'run as admin' ][sys.platform.startswith('win')]) break else: print() log.info("Ok lets hope it worked") print() else: log.exception("Unknown ImportError, exiting.") break except Exception as e: if hasattr(e, '__module__') and e.__module__ == 'musicbot.exceptions': if e.__class__.__name__ == 'HelpfulError': log.info(e.message) break elif e.__class__.__name__ == "TerminateSignal": break elif e.__class__.__name__ == "RestartSignal": restart() else: log.exception("Error starting bot") finally: if not m or not m.init_ok: if any(sys.exc_info()): # How to log this without redundant messages... traceback.print_exc() break asyncio.set_event_loop(asyncio.new_event_loop()) loops += 1 sleeptime = min(loops * 2, max_wait_time) if sleeptime: log.info("Restarting in {} seconds...".format(loops * 2)) time.sleep(sleeptime) print() log.info("All done.")
def main(): if not sys.version_info >= (3, 5): print("Python 3.5+ is required. This version is %s" % sys.version.split()[0]) print("Attempting to locate python 3.5...") pycom = None # Maybe I should check for if the current dir is the musicbot folder, just in case if sys.platform.startswith('win'): try: subprocess.check_output('py -3.5 -c "exit()"', shell=True) pycom = 'py -3.5' except: try: subprocess.check_output('python3 -c "exit()"', shell=True) pycom = 'python3' except: pass if pycom: print("Python 3 found. Launching bot...") os.system('start cmd /k %s run.py' % pycom) sys.exit(0) else: try: pycom = subprocess.check_output(['which', 'python3.5' ]).strip().decode() except: pass if pycom: print("\nPython 3 found. Re-launching bot using: ") print(" %s run.py\n" % pycom) os.execlp(pycom, pycom, 'run.py') print("Please run the bot using python 3.5") input("Press enter to continue . . .") return import asyncio tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: # Maybe I need to try to import stuff first, then actually import stuff # It'd save me a lot of pain with all that awful exception type checking try: from musicbot import MusicBot m = MusicBot() print("Connecting...", end='', flush=True) m.run() except SyntaxError: traceback.print_exc() break except ImportError as e: if not tried_requirementstxt: tried_requirementstxt = True # TODO: Better output print(e) print("Attempting to install dependencies...") err = PIP.run_install('--upgrade -r requirements.txt') if err: print("\nYou may need to %s to install dependencies." % ['use sudo', 'run as admin' ][sys.platform.startswith('win')]) break else: print("\nOk lets hope it worked\n") else: traceback.print_exc() print("Unknown ImportError, exiting.") break except Exception as e: if hasattr(e, '__module__') and e.__module__ == 'musicbot.exceptions': if e.__class__.__name__ == 'HelpfulError': print(e.message) break elif e.__class__.__name__ == "TerminateSignal": break elif e.__class__.__name__ == "RestartSignal": loops = -1 else: traceback.print_exc() finally: asyncio.set_event_loop(asyncio.new_event_loop()) loops += 1 print("Cleaning up... ", end='') gc.collect() print("Done.") sleeptime = min(loops * 2, max_wait_time) if sleeptime: print("Restarting in {} seconds...".format(loops * 2)) time.sleep(sleeptime)
# 🎶 from musicbot import MusicBot import uuid if __name__ == "__main__": bot_instance = MusicBot() bot_instance.run('bot.cfg')
def main(): # TODO: *actual* argparsing if '--no-checks' not in sys.argv: sanity_checks() finalize_logging() import asyncio tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: # Maybe I need to try to import stuff first, then actually import stuff # It'd save me a lot of pain with all that awful exception type checking m = None try: from musicbot import MusicBot m = MusicBot() sh.terminator = '' log.info("Connecting") sh.terminator = '\n' m.run() except SyntaxError: log.exception("Syntax error (this is a bug, not your fault)") break except ImportError: # TODO: if error module is in pip or dpy requirements... if not tried_requirementstxt: tried_requirementstxt = True log.exception("Error starting bot") log.info("Attempting to install dependencies...") err = PIP.run_install('--upgrade -r requirements.txt') if err: # TODO: add the specific error check back as not to always tell users to sudo it print() log.critical("You may need to %s to install dependencies." % ['use sudo', 'run as admin'][sys.platform.startswith('win')]) break else: print() log.info("Ok lets hope it worked") print() else: log.exception("Unknown ImportError, exiting.") break except Exception as e: if hasattr(e, '__module__') and e.__module__ == 'musicbot.exceptions': if e.__class__.__name__ == 'HelpfulError': log.info(e.message) break elif e.__class__.__name__ == "TerminateSignal": break elif e.__class__.__name__ == "RestartSignal": restart() else: log.exception("Error starting bot") finally: if not m or not m.init_ok: if any(sys.exc_info()): # How to log this without redundant messages... traceback.print_exc() break asyncio.set_event_loop(asyncio.new_event_loop()) loops += 1 sleeptime = min(loops * 2, max_wait_time) if sleeptime: log.info("Restarting in {} seconds...".format(loops*2)) time.sleep(sleeptime) print() log.info("All done.")
def main(): if not sys.version_info >= (3, 5): print("Python 3.5+ jest potrzbeny. Twoja wersja to: %s" % sys.version.split()[0]) print("Szukam lokalizacji Pythona 3.5...") pycom = None # Maybe I should check for if the current dir is the musicbot folder, just in case if sys.platform.startswith('win'): try: subprocess.check_output('py -3.5 -c "exit()"', shell=True) pycom = 'py -3.5' except: try: subprocess.check_output('python3 -c "exit()"', shell=True) pycom = 'python3' except: pass if pycom: print("Python 3 znaleziony. Uruchamiam bota...") os.system('start cmd /k %s run.py' % pycom) sys.exit(0) else: try: pycom = subprocess.check_output(['which', 'python3.5' ]).strip().decode() except: pass if pycom: print("\nPython 3 znaleziony. Restartuje bota: ") print(" %s run.py\n" % pycom) os.execlp(pycom, pycom, 'run.py') print("Proszę uruchomić bota w Python 3.5") input("Press enter to continue . . .") return import asyncio tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: # Maybe I need to try to import stuff first, then actually import stuff # It'd save me a lot of pain with all that awful exception type checking m = None try: from musicbot import MusicBot m = MusicBot() print("Łączę...", end='', flush=True) m.run() except SyntaxError: traceback.print_exc() break except ImportError as e: if not tried_requirementstxt: tried_requirementstxt = True # TODO: Better output print(e) print("Instaluje pakiety...") err = PIP.run_install('--upgrade -r requirements.txt') if err: print("\nYou may need to %s to install dependencies." % ['use sudo', 'run as admin' ][sys.platform.startswith('win')]) break else: print("\nOk lets hope it worked\n") else: traceback.print_exc() print("Unknown ImportError, exiting.") break except Exception as e: if hasattr(e, '__module__') and e.__module__ == 'musicbot.exceptions': if e.__class__.__name__ == 'HelpfulError': print(e.message) break elif e.__class__.__name__ == "TerminateSignal": break elif e.__class__.__name__ == "RestartSignal": loops = -1 else: traceback.print_exc() finally: if not m or not m.init_ok: break asyncio.set_event_loop(asyncio.new_event_loop()) loops += 1 print("Czyszcze... ", end='') gc.collect() print("Gotowe.") sleeptime = min(loops * 2, max_wait_time) if sleeptime: print("Restartuje w {} sekundach...".format(loops * 2)) time.sleep(sleeptime)
def main(): if '--no-checks' not in sys.argv: sanity_checks() finalize_logging() import asyncio if sys.platform == 'win32': loop = asyncio.ProactorEventLoop() asyncio.set_event_loop(loop) tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: m = None try: from musicbot import MusicBot m = MusicBot() sh.terminator = '' sh.terminator = '\n' m.run() except SyntaxError: log.exception("Syntax error (this is a bug, not your fault)") break except ImportError: if not tried_requirementstxt: tried_requirementstxt = True log.exception("Error starting bot") log.info("Attempting to install dependencies...") err = PIP.run_install('--upgrade -r requirements.txt') if err: print() log.critical( "You may need to %s to install dependencies." % ['use sudo', 'run as admin' ][sys.platform.startswith('win')]) break else: print() log.info("Ok lets hope it worked") print() else: log.exception("Unknown ImportError, exiting.") break except Exception as e: if hasattr(e, '__module__') and e.__module__ == 'musicbot.exceptions': if e.__class__.__name__ == 'HelpfulError': log.info(e.message) break elif e.__class__.__name__ == "TerminateSignal": break elif e.__class__.__name__ == "RestartSignal": loops = 0 pass else: log.exception("Error starting bot") finally: if not m or not m.init_ok: if any(sys.exc_info()): traceback.print_exc() break asyncio.set_event_loop(asyncio.new_event_loop()) loops += 1 sleeptime = min(loops * 2, max_wait_time) if sleeptime: log.info("Restarting in {} seconds...".format(loops * 2)) time.sleep(sleeptime) print() log.info("All done.")
from musicbot import MusicBot if __name__ == "__main__": MusicBot().run()
def main(): if not sys.version_info >= (3, 5): print("Python 3.5+ is required. This version is %s" % sys.version.split()[0]) print("Attempting to locate python 3.5...") pycom = None # Maybe I should check for if the current dir is the musicbot folder, just in case if sys.platform.startswith('win'): try: subprocess.check_output('py -3.5 -c "exit()"', shell=True) pycom = 'py -3.5' except: try: subprocess.check_output('python3 -c "exit()"', shell=True) pycom = 'python3' except: pass if pycom: print("Python 3 found. Launching bot...") os.system('start cmd /k %s run.py' % pycom) sys.exit(0) else: try: pycom = subprocess.check_output(['which', 'python3.5' ]).strip().decode() except: pass if pycom: print("\nPython 3 found. Re-launching bot using: ") print(" %s run.py\n" % pycom) os.execlp(pycom, pycom, 'run.py') print("Please run the bot using python 3.5") input("Press enter to continue . . .") return tried_requirementstxt = False tryagain = True while tryagain: try: from musicbot import MusicBot from musicbot.exceptions import HelpfulError MusicBot().run() break # check if restart? replace process? except SyntaxError: traceback.print_exc() break except HelpfulError as e: print(e.message) break except ImportError as e: if not tried_requirementstxt: tried_requirementstxt = True # TODO: Better output print(e) print("Attempting to install dependencies...") err = PIP.run_install('-r requirements.txt') if err: print("\nYou may need to %s to install dependencies." % ['use sudo', 'run as admin' ][sys.platform.startswith('win')]) break else: print("\nOk lets hope it worked\n") else: traceback.print_exc() print("Unknown ImportError, exiting.") break
def main(): if not sys.version_info >= (3, 5): print("Python 3.5+ is required. This version is %s" % sys.version.split()[0]) print("Attempting to locate python 3.5...") pycom = None # Maybe I should check for if the current dir is the musicbot folder, just in case if sys.platform.startswith('win'): try: subprocess.check_output('py -3.5 -c "exit()"', shell=True) pycom = 'py -3.5' except: try: subprocess.check_output('python3 -c "exit()"', shell=True) pycom = 'python3' except: pass if pycom: print("Python 3 found. Launching bot...") os.system('start cmd /k %s run.py' % pycom) sys.exit(0) else: try: pycom = subprocess.check_output(['which', 'python3.5' ]).strip().decode() except: pass if pycom: print("\nPython 3 found. Re-launching bot using: ") print(" %s run.py\n" % pycom) os.execlp(pycom, pycom, 'run.py') print("Please run the bot using python 3.5") input("Press enter to continue . . .") return if '--update' in sys.argv: if PIP.works(): try: err = PIP.run_install('--upgrade -r requirements.txt') except subprocess.CalledProcessError as err: print("\nUpgrade failed, you may need to run it as admin/root") input("Press enter to continue . . .") return else: # TODO: Make this text less questionable print( "\n" "Could not locate PIP. If you're sure you have it, run this:\n" " your_pip_command install --upgrade -r requirements.txt" "\n\n") input("Press enter to continue . . .") return tried_requirementstxt = False tryagain = True while tryagain: try: from musicbot import MusicBot MusicBot().run() break # check if restart? replace process? except ImportError as e: print(e) if not tried_requirementstxt: tried_requirementstxt = True # TODO: Better output print("Attempting to install dependencies...") err = PIP.run_install('-r requirements.txt') if err: print("\nYou may need to %s to install dependencies." % ['use sudo', 'run as admin' ][sys.platform.startswith('win')]) break else: print("\nOk lets hope it worked\n")
def main(): # TODO: *actual* argparsing if '--no-checks' not in sys.argv: sanity_checks() finalize_logging() import asyncio if sys.platform == 'win32': loop = asyncio.ProactorEventLoop() # needed for subprocesses asyncio.set_event_loop(loop) tried_requirementstxt = False tryagain = True loops = 0 max_wait_time = 60 while tryagain: # Maybe I need to try to import stuff first, then actually import stuff # It'd save me a lot of pain with all that awful exception type checking m = None try: from musicbot import MusicBot m = MusicBot() sh.terminator = '' sh.terminator = '\n' m.run() except SyntaxError: log.exception("構文エラー(これはバグであり、あなたのせいではありません)") break except ImportError: # TODO: if error module is in pip or dpy requirements... if not tried_requirementstxt: tried_requirementstxt = True log.exception("ボットの起動エラー") log.info("依存関係をインストールしようとしています...") err = PIP.run_install('--upgrade -r requirements.txt') if err: # TODO: add the specific error check back as not to always tell users to sudo it print() log.critical("依存関係をインストールするには%sが必要になる場合があります。" % ['use sudo', 'run as admin' ][sys.platform.startswith('win')]) break else: print() log.info("OK") print() else: log.exception("不明なImportError、終了します。") break except Exception as e: if hasattr(e, '__module__') and e.__module__ == 'musicbot.exceptions': if e.__class__.__name__ == 'HelpfulError': log.info(e.message) break elif e.__class__.__name__ == "TerminateSignal": break elif e.__class__.__name__ == "RestartSignal": loops = 0 pass else: log.exception("ボット起動時にエラーが発生しました。") finally: if not m or not m.init_ok: if any(sys.exc_info()): # How to log this without redundant messages... traceback.print_exc() break asyncio.set_event_loop(asyncio.new_event_loop()) loops += 1 sleeptime = min(loops * 2, max_wait_time) if sleeptime: log.info("{}秒で再起動します...".format(loops * 2)) time.sleep(sleeptime) print() log.info("全て完了しました。")