for p in searchDirectories: if os.path.isfile(p): version = getVersionFromFile(p) return version def resource_directory(self, module): return os.path.dirname(sys.modules[module].__file__) def getB3Path(self): if main_is_frozen(): # which happens when running from the py2exe build return os.path.dirname(sys.executable) return self.resource_directory('bbk') pkg_handler = None if main_is_frozen(): # avoid issues when frozen with py2exe on a windows machine # that have phg_resources importable. pkg_handler = PkgResourcesStandIn() else: try: import pkg_ressources except ImportError: pkg_handler = PkgResourcesStandIn() else: pkg_handler = PkgResources() version = pkg_handler.version resource_directory = pkg_handler.resource_directory
def getB3Path(self): if main_is_frozen(): # which happens when running from the py2exe build return os.path.dirname(sys.executable) return self.resource_directory('bbk')
def run_autorestart(args=None): _restarts = 0 if main_is_frozen(): script = '' else: script= os.path.join(modulePath[:-3], 'bbk_run.py') if not os.path.isfile(script): script = os.path.join(modulePath[:-3], 'bkk', 'run.py') if os.path.isfile(script + 'c'): script += 'c' if args: script = '%s %s %s' % (sys.executable, script, ' '.join(args)) else: script = '%s %s' % (sys.executable, script) while True: try: print 'Running in auto-restart mode...' if _restarts > 0: print 'Bot restarted %s times.' %_restarts time.sleep(1) try: import subprocess status = subprocess.call(script, shell=True) except ImportError: #for Python versions < 2.5 #status = os.system(script) print 'Restart mode not fully supported!\nUse BBK without the -r (--restart) option or update your python installation!' break print 'Exited with status %s' % status if status == 221: # restart print 'Restart requested...' elif status == 222: # stop print 'Shutdown requested.' break elif status == 220: # stop print 'BBK Error, check log file.' break elif status == 223: # stop print 'BBK Error Restart, check log file.' break elif status == 224: # stop print 'BBK Error, check console.' break elif status == 256: # stop print 'Python error, stopping, check log file.' break elif status == 0: # stop print 'Normal shutdown, stopping.' break elif status == 1: # stop print 'Error, stopping, check console.' break else: print 'Unknown shutdown status (%s), restarting...' % status _restarts += 1 time.sleep(4) except KeyboardInterrupt: print 'Quit' break