def init(self, api_key=None): """Perform a set of actions to initialize the TS connection so that further commands can be executed on that connection. Returns self to allow for method chaining. """ connect_ok = self.connect() if not connect_ok: return None self._recv() if self.auth_call_present(): if api_key: self.authenticate(api_key) else: message = textwrap.dedent(''' Teamspeak clientquery requires api_key but it it could not be found on disk! The Teamspeak server detection will not work correctly! ''') MessageBox(message, 'Teamspeak detection error!') return self
def _open_hyperlink(url): """Open the url passed as argument. If the url points to a local file, encode it using the right encoding. """ if url[1:].startswith(':\\'): # C:\, D:\, etc... if not os.path.exists(url): MessageBox('The file or directory does not exist', 'Can\'t open file or directory') return url = url.encode(sys.getfilesystemencoding()) return webbrowser.open(url)
def _set_launcher_moddir(self, launcher_moddir): """ interceptor for launcher_moddir sets the user defined launcher_moddir and ensures it is created. If something goes wrong nothing is done """ Logger.info('Settings: Ensuring mod dir exists - {}'.format(launcher_moddir)) try: mkdir_p(launcher_moddir) except OSError: fallback_moddir = self.get('launcher_moddir') # TODO: Show a regular message box, not a win32 message box MessageBox('Could not create directory {}\nFalling back to {}'.format( launcher_moddir, fallback_moddir), 'Error while setting mod directory') return ModelInterceptorError() return launcher_moddir
def __init__(self): try: devmode_file_path = get_external_executable_dir(DEVMODE_FILE_NAME) with file(devmode_file_path, "rb") as f: s = f.read() self.devdata = json.loads(s) except ValueError as ex: # Bad JSON data try: message = unicode(ex) except: message = unicode(repr(str(ex))) MessageBox('devmode.conf:\n' + message, 'devmode.conf contains an error!') sys.exit(1) except Exception: self.devdata = {}
def wrapper(*args, **kwargs): try: try: func(*args, **kwargs) except (UnicodeEncodeError, UnicodeDecodeError) as ex: error_message = "{}. Original exception: {} Text: {}".format( unicode(ex), type(ex).__name__, repr(ex.args[1])) raise UnicodeError, UnicodeError( error_message), sys.exc_info()[2] except Exception: build = get_git_sha1_auto() stacktrace = "".join(_format_exc_info(*sys.exc_info())) msg = 'Build: {}\n{}'.format(build, stacktrace) # p = ErrorPopup(details=msg) # p.open() MessageBox(msg, CRITICAL_POPUP_TITLE)
def run(program_args, shell=False): """Run the given program with the given parameters. In case the program requires elevation, run an UAC prompt if on Windows. Returns a Popen or Popen compatible object. """ fs_program_args = unicode_helpers.u_to_fs_list(program_args) try: return subprocess.Popen(fs_program_args, shell=shell) except WindowsError as ex: if ex.winerror != 740: # The requested operation requires elevation raise # Try running as admin handle = admin.run_admin(program_args[0], program_args[1:]) if not handle: MessageBox(ADMIN_REQUIRED_MESSAGE.format(program_args[0]), 'Error!') return handle
CRITICAL_POPUP_TITLE = """An error occurred. Copy it with Ctrl+C and submit a bug""" try: from utils.primitive_git import get_git_sha1_auto build = get_git_sha1_auto() except: build = 'N/A (exception occurred)\nBuild exception reason:\n{}'.format( repr(sys.exc_info()[1]) ) try: from utils.testtools_compat import _format_exc_info stacktrace = "".join(_format_exc_info(*exc_info)) except: try: import traceback last_chance_traceback = "\n".join(traceback.format_tb(exc_info[2])) except: last_chance_traceback = "Traceback parsing failed. Reason:\n{}\n\nLast chance parsing:\n{}".format( repr(sys.exc_info()[1]), repr(exc_info[1]) ) stacktrace = "Could not parse stacktrace. Emergency parsing:\n{}\nException while parsing stacktrace:\n{}".format( last_chance_traceback, repr(sys.exc_info()[1]) ) msg = 'Build: {}\n\n{}'.format(build, stacktrace) MessageBox(msg, CRITICAL_POPUP_TITLE)
from config_select import config_dir except ImportError: message = textwrap.dedent(''' Could not load config_dir variable from config_select.py. Make sure you created that file in "src/launcher_config" directory and filled it with the correct value. You can use config_select_sample.py as an example.''') print message from kivy.logger import Logger Logger.error('Config: {}'.format(message)) from utils.critical_messagebox import MessageBox MessageBox(message, 'Error') import sys sys.exit(1) try: import site import os file_directory = os.path.dirname(os.path.realpath(__file__)) site.addsitedir( os.path.abspath( os.path.join(file_directory, '..', '..', 'resources', config_dir))) except AttributeError: pass # there is no site.addsitedir in applications frozen with PyInstaller # Which we don't care because we don't need to fix the path in those