Esempio n. 1
0
    def test_all(self):
        set_default_name("platform info test", "platform-info-test")
        init()
        t = start_thread(threaded_server_init, "server-init")
        t.join()
        with program_context() as p:
            assert repr(p)
            assert get_application_name() == "platform-info-test"
            assert get_prgname() == "platform info test"

        if WIN32:  # pragma: no cover
            #we can check for command_error and command_info
            #on win32 because those trigger dialogs
            return
        calls = []

        def ccall(*args):
            calls.append(args)

        xpra_main.error = ccall
        xpra_main.info = ccall
        command_error("error")
        command_info("info")
        assert len(calls) == 2, "expected 2 messages but got: %s" % (calls, )
        set_prgname(None)
        clean()
Esempio n. 2
0
def do_init():
    if not REDIRECT_OUTPUT:
        if sys.version_info[0] < 3:
            #don't know why this breaks with Python 3 yet...
            fix_unicode_out()
        #figure out if we want to wait for input at the end:
        global _wait_for_input
        try:
            import win32console, win32con  #@UnresolvedImport
            handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
            #handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE)
            console_info = handle.GetConsoleScreenBufferInfo()
            cpos = console_info["CursorPosition"]
            #wait for input if this is a brand new console:
            _wait_for_input = cpos.X == 0 and cpos.Y == 0
        except:
            e = sys.exc_info()[1]
            code = -1
            try:
                code = e.winerror
            except:
                pass
            if code == errno.ENXIO:
                #ignore "no device" errors silently
                #(ie: happens if you redirect the command to a file)
                #we could also re-use the code above from "not_a_console()"
                pass
            else:
                print("error accessing console %s: %s" %
                      (errno.errorcode.get(e.errno, e.errno), e))
        if _wait_for_input:
            #don't wait for input when running under wine
            #(which usually does not popup a new shell window)
            try:
                import win32api  #@UnresolvedImport
                hKey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,
                                           r"Software\\Wine")
                if hKey is not None:
                    _wait_for_input = False
            except:
                #no wine key, assume not present and wait for input
                pass
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = get_prgname() + ".log"
    from paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout
Esempio n. 3
0
def do_init():
    if FIX_UNICODE_OUT:
        fix_unicode_out()
    if not REDIRECT_OUTPUT:
        #figure out if we want to wait for input at the end:
        set_wait_for_input()
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = (get_prgname() or "Xpra")+".log"
    from xpra.platform.win32.paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout
Esempio n. 4
0
def do_init():
    if not REDIRECT_OUTPUT:
        if sys.version_info[0] < 3:
            #don't know why this breaks with Python 3 yet...
            fix_unicode_out()
        #figure out if we want to wait for input at the end:
        set_wait_for_input()
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = (get_prgname() or "Xpra") + ".log"
    from paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout
Esempio n. 5
0
def do_init():
    if not REDIRECT_OUTPUT:
        if sys.version_info[0]<3:
            #don't know why this breaks with Python 3 yet...
            fix_unicode_out()
        #figure out if we want to wait for input at the end:
        set_wait_for_input()
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = (get_prgname() or "Xpra")+".log"
    from paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout
Esempio n. 6
0
def do_init():
    if not REDIRECT_OUTPUT:
        if sys.version_info[0]<3:
            #don't know why this breaks with Python 3 yet...
            fix_unicode_out()
        #figure out if we want to wait for input at the end:
        global _wait_for_input
        try:
            import win32console, win32con       #@UnresolvedImport
            handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
            #handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE)
            console_info = handle.GetConsoleScreenBufferInfo()
            cpos = console_info["CursorPosition"]
            #wait for input if this is a brand new console:
            _wait_for_input = cpos.X==0 and cpos.Y==0
        except:
            e = sys.exc_info()[1]
            code = -1
            try:
                code = e.winerror
            except:
                pass
            if code==errno.ENXIO:
                #ignore "no device" errors silently
                #(ie: happens if you redirect the command to a file)
                #we could also re-use the code above from "not_a_console()"
                pass
            else:
                print("error accessing console %s: %s" % (errno.errorcode.get(e.errno, e.errno), e))
        if _wait_for_input:
            #don't wait for input when running under wine
            #(which usually does not popup a new shell window)
            try:
                import win32api     #@UnresolvedImport
                hKey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, r"Software\\Wine")
                if hKey is not None:
                    _wait_for_input = False
            except:
                #no wine key, assume not present and wait for input
                pass
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = get_prgname()+".log"
    from paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout
Esempio n. 7
0
def do_init():
    if not REDIRECT_OUTPUT:
        FIX_UNICODE_OUT = envbool("XPRA_FIX_UNICODE_OUT", True)
        if PYTHON2 and FIX_UNICODE_OUT:
            #don't know why this breaks with Python 3 yet...
            fix_unicode_out()
        #figure out if we want to wait for input at the end:
        set_wait_for_input()
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = (get_prgname() or "Xpra") + ".log"
    from paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout
Esempio n. 8
0
    def test_all(self):
        threaded_server_init()
        with program_context() as f:
            assert repr(f)

        #this doesn't actually exercise more code,
        #as the attributes are initialized once per process...
        with program_context("prg") as f:
            assert repr(f)

        with program_context(None, "app") as f:
            assert repr(f)

        with program_context("prg", "app") as f:
            assert repr(f)
            assert get_application_name() == "app"
            assert get_prgname() == "prg"
Esempio n. 9
0
def do_init():
    if FIX_UNICODE_OUT:
        fix_unicode_out()
    if not REDIRECT_OUTPUT:
        #figure out if we want to wait for input at the end:
        set_wait_for_input()
        return
    if envbool("XPRA_LOG_TO_FILE", True):
        log_filename = os.environ.get("XPRA_LOG_FILENAME")
        if not log_filename:
            from xpra.platform.win32.paths import _get_data_dir
            from xpra.platform import get_prgname
            data_dir = _get_data_dir(False)
            if not os.path.exists(data_dir):
                os.mkdir(data_dir)
            log_filename = os.path.join(data_dir,
                                        (get_prgname() or "Xpra") + ".log")
        sys.stdout = open(log_filename, "a")
        sys.stderr = sys.stdout
Esempio n. 10
0
def do_init():
    if not REDIRECT_OUTPUT:
        fix_unicode_out()
        #figure out if we want to wait for input at the end:
        global _wait_for_input
        try:
            import win32console, win32con       #@UnresolvedImport
            handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
            #handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE)
            console_info = handle.GetConsoleScreenBufferInfo()
            cpos = console_info["CursorPosition"]
            #wait for input if this is a brand new console:
            _wait_for_input = cpos.X==0 and cpos.Y==0
        except Exception, e:
            print("error accessing console: %s" % e)
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = get_prgname()+".log"
    from paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout

def do_clean():
    global _wait_for_input
    if _wait_for_input:
        print("\nPress Enter to close")
        sys.stdin.readline()
Esempio n. 11
0
def do_init():
    if not REDIRECT_OUTPUT:
        fix_unicode_out()
        #figure out if we want to wait for input at the end:
        global _wait_for_input
        try:
            import win32console, win32con  #@UnresolvedImport
            handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
            #handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE)
            console_info = handle.GetConsoleScreenBufferInfo()
            cpos = console_info["CursorPosition"]
            #wait for input if this is a brand new console:
            _wait_for_input = cpos.X == 0 and cpos.Y == 0
        except Exception, e:
            print("error accessing console: %s" % e)
        return
    from xpra.platform import get_prgname
    LOG_FILENAME = get_prgname() + ".log"
    from paths import _get_data_dir
    d = _get_data_dir()
    log_file = os.path.join(d, LOG_FILENAME)
    sys.stdout = open(log_file, "a")
    sys.stderr = sys.stdout


def do_clean():
    global _wait_for_input
    if _wait_for_input:
        print("\nPress Enter to close")
        sys.stdin.readline()