コード例 #1
0
 def __init__(self):
     if "Darwin" not in platform.platform():
         raise RunProgError("This backend runs only on Darwin")
     p = EasyProcess([PROGRAM, "-help"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
コード例 #2
0
ファイル: util.py プロジェクト: StealthyMC/selenium-proj
def get_helptext(program):
    p = EasyProcess([program, "-help"])
    p.enable_stdout_log = False
    p.enable_stderr_log = False
    p.call()
    helptext = p.stderr
    return helptext
コード例 #3
0
ファイル: size.py プロジェクト: bohansuning/pyscreenshot
def display_size():
    if platform_is_osx():
        from Quartz import CGDisplayBounds
        from Quartz import CGMainDisplayID

        mainMonitor = CGDisplayBounds(CGMainDisplayID())
        return int(mainMonitor.size.width), int(mainMonitor.size.height)

    if platform_is_win():
        from win32api import GetSystemMetrics

        return int(GetSystemMetrics(0)), int(GetSystemMetrics(1))

    if platform_is_linux():
        # http://www.cyberciti.biz/faq/how-do-i-find-out-screen-resolution-of-my-linux-desktop/
        # xdpyinfo  | grep 'dimensions:'
        screen_width, screen_height = 0, 0
        xdpyinfo = EasyProcess("xdpyinfo")
        xdpyinfo.enable_stdout_log = False
        if xdpyinfo.call().return_code != 0:
            raise ValueError("xdpyinfo error: %s" % xdpyinfo)
        for x in xdpyinfo.stdout.splitlines():
            if "dimensions:" in x:
                screen_width, screen_height = map(int, x.strip().split()[1].split("x"))

        return screen_width, screen_height
コード例 #4
0
 def backend_version(self):
     p = EasyProcess([PROGRAM, "-help"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
     if p.return_code == 0:
         return UNKNOWN_VERSION
コード例 #5
0
    def __init__(self):
        if sys.platform == "darwin":
            raise ImagemagickBackendError("osx not supported")  # TODO

        p = EasyProcess([PROGRAM, "-version"])
        p.enable_stdout_log = False
        p.enable_stderr_log = False
        p.call()
コード例 #6
0
 def backend_version(self):
     p = EasyProcess([PROGRAM, "-help"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
     if p.return_code == 0:
         # TODO: get real version
         return "0.0"
コード例 #7
0
ファイル: grim.py プロジェクト: ImAvinashSharma/sip-py
 def backend_version(self):
     # grim doesn't have a version flag for some reason
     p = EasyProcess([PROGRAM, "-help"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
     if p.return_code == 0:
         return UNKNOWN_VERSION
コード例 #8
0
 def check_installed(cls):
     p = EasyProcess([PROGRAM, "-help"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
     helptext = p.stdout
     cls.has_displayfd = "-displayfd" in helptext
     cls.has_resizeable = "-resizeable" in helptext
コード例 #9
0
ファイル: tutil.py プロジェクト: schlang/PyVirtualDisplay
def prog_check(cmd):
    try:
        p = EasyProcess(cmd)
        p.enable_stdout_log = False
        p.enable_stderr_log = False
        p.call()
        return p.return_code == 0
    except Exception:
        return False
コード例 #10
0
def is_installed():
    """
    Return whether or not xauth is installed.
    """
    try:
        p = EasyProcess(["xauth", "-V"])
        p.enable_stdout_log = False
        p.enable_stderr_log = False
        p.call()
    except Exception:
        return False
    else:
        return True
コード例 #11
0
def display_size_x():
    # http://www.cyberciti.biz/faq/how-do-i-find-out-screen-resolution-of-my-linux-desktop/
    # xdpyinfo  | grep 'dimensions:'
    screen_width, screen_height = 0, 0
    xdpyinfo = EasyProcess("xdpyinfo")
    xdpyinfo.enable_stdout_log = False
    if xdpyinfo.call().return_code != 0:
        raise ValueError("xdpyinfo error: %s" % xdpyinfo)
    for x in xdpyinfo.stdout.splitlines():
        if "dimensions:" in x:
            screen_width, screen_height = map(int, x.strip().split()[1].split("x"))

    return screen_width, screen_height
コード例 #12
0
def is_installed():
    '''
    Return whether or not xauth is installed.
    '''
    try:
        p = EasyProcess(['xauth', '-V'])
        p.enable_stdout_log = False
        p.enable_stderr_log = False
        p.call()
    except Exception:
        return False
    else:
        return True
コード例 #13
0
def display_size():
    if sys.platform == "darwin":
        from Quartz import CGDisplayBounds
        from Quartz import CGMainDisplayID

        mainMonitor = CGDisplayBounds(CGMainDisplayID())
        return (mainMonitor.size.width, mainMonitor.size.height)

    # http://www.cyberciti.biz/faq/how-do-i-find-out-screen-resolution-of-my-linux-desktop/
    # xdpyinfo  | grep 'dimensions:'
    screen_width, screen_height = None, None
    xdpyinfo = EasyProcess("xdpyinfo")
    xdpyinfo.enable_stdout_log = False
    for x in xdpyinfo.call().stdout.splitlines():
        if "dimensions:" in x:
            screen_width, screen_height = map(int,
                                              x.strip().split()[1].split("x"))

    return screen_width, screen_height
コード例 #14
0
 def __init__(self):
     p = EasyProcess([PROGRAM, '--version'])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
コード例 #15
0
    def _start1(self):
        with _mutex:
            self.display = _search_for_display()
            while self.display in _USED_DISPLAY_NR_LIST:
                self.display += 1
            self.new_display_var = ":%s" % int(self.display)

            _USED_DISPLAY_NR_LIST.append(self.display)

        self._command = self._cmd() + self._extra_args
        log.debug("command: %s", self._command)

        self._popen(use_pass_fds=False)

        self.new_display_var = ":%s" % int(self.display)

        if self._use_xauth:
            self._setup_xauth()

        # https://github.com/ponty/PyVirtualDisplay/issues/2
        # https://github.com/ponty/PyVirtualDisplay/issues/14
        self.old_display_var = os.environ.get("DISPLAY", None)

        # wait until X server is active
        start_time = time.time()

        d = self.new_display_var
        ok = False
        time.sleep(0.05)  # give time for early exit
        while True:
            if not self.is_alive():
                break

            try:
                xdpyinfo = EasyProcess(["xdpyinfo"], env=self._env())
                xdpyinfo.enable_stdout_log = False
                xdpyinfo.enable_stderr_log = False
                exit_code = xdpyinfo.call().return_code
            except EasyProcessError:
                log.warning(
                    "xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!"
                )
                time.sleep(_X_START_WAIT)  # old method
                ok = True
                break

            if exit_code != 0:
                pass
            else:
                log.info('Successfully started X with display "%s".', d)
                ok = True
                break

            if time.time() - start_time >= _X_START_TIMEOUT:
                break
            time.sleep(_X_START_TIME_STEP)
        if not self.is_alive():
            log.warning("process exited early. stderr:%s", self.stderr)
            msg = "Failed to start process: %s"
            raise XStartError(msg % self)
        if not ok:
            msg = 'Failed to start X on display "%s" (xdpyinfo check failed, stderr:[%s]).'
            raise XStartTimeoutError(msg % (d, xdpyinfo.stderr))
コード例 #16
0
 def check_installed(cls):
     p = EasyProcess([PROGRAM, '-help'])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
コード例 #17
0
 def backend_version(self):
     p = EasyProcess([PROGRAM, "--version"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
     return extract_version(p.stdout.replace("-", " "))
コード例 #18
0
    def _start1(self):
        if self.has_displayfd:
            # stdout doesn't work on osx -> create own pipe
            rfd, self.pipe_wfd = os.pipe()
        else:
            with mutex:
                self.display = search_for_display(randomizer=self.randomizer)
                while self.display in USED_DISPLAY_NR_LIST:
                    self.display += 1
                self.new_display_var = ":%s" % int(self.display)

                USED_DISPLAY_NR_LIST.append(self.display)

        self.command = self._cmd() + self.extra_args
        log.debug("command: %s", self.command)

        self._stdout_file = tempfile.TemporaryFile(prefix="stdout_")
        self._stderr_file = tempfile.TemporaryFile(prefix="stderr_")

        if py2() or not self.has_displayfd:
            self.subproc = subprocess.Popen(
                self.command,
                stdout=self._stdout_file,
                stderr=self._stderr_file,
                shell=False,
            )
        else:
            if self.has_displayfd:
                self.subproc = subprocess.Popen(
                    self.command,
                    pass_fds=[self.pipe_wfd],
                    stdout=self._stdout_file,
                    stderr=self._stderr_file,
                    shell=False,
                )
        if self.has_displayfd:
            # rfd = self.subproc.stdout.fileno()
            self.display = int(self.wait_for_pipe_text(rfd))
            os.close(rfd)
            os.close(self.pipe_wfd)
        self.new_display_var = ":%s" % int(self.display)

        if self.use_xauth:
            self._setup_xauth()

        # https://github.com/ponty/PyVirtualDisplay/issues/2
        # https://github.com/ponty/PyVirtualDisplay/issues/14
        self.old_display_var = os.environ.get("DISPLAY", None)

        # wait until X server is active
        start_time = time.time()
        # if self.check_startup:
        #     rp = self._check_startup_fd
        #     display_check = None
        #     rlist, wlist, xlist = select.select((rp,), (), (), X_START_TIMEOUT)
        #     if rlist:
        #         display_check = os.read(rp, 10).rstrip()
        #     else:
        #         msg = "No display number returned by X server"
        #         raise XStartTimeoutError(msg)
        #     dnbs = str(self.display)
        #     if bytes != str:
        #         dnbs = bytes(dnbs, "ascii")
        #     if display_check != dnbs:
        #         msg = 'Display number "%s" not returned by X server' + str(
        #             display_check
        #         )
        #         raise XStartTimeoutError(msg % self.display)

        if not self.has_displayfd:
            self.redirect_display(True)  # for xdpyinfo
            d = self.new_display_var
            ok = False
            time.sleep(0.05)  # give time for early exit
            while True:
                if not self.is_alive():
                    break

                try:
                    xdpyinfo = EasyProcess(["xdpyinfo"])
                    xdpyinfo.enable_stdout_log = False
                    xdpyinfo.enable_stderr_log = False
                    exit_code = xdpyinfo.call().return_code
                except EasyProcessError:
                    log.warning(
                        "xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!"
                    )
                    time.sleep(X_START_WAIT)  # old method
                    ok = True
                    break

                if exit_code != 0:
                    pass
                else:
                    log.info('Successfully started X with display "%s".', d)
                    ok = True
                    break

                if time.time() - start_time >= X_START_TIMEOUT:
                    break
                time.sleep(X_START_TIME_STEP)
            if not self.is_alive():
                log.warning("process exited early. stderr:%s", self.stderr)
                msg = "Failed to start process: %s"
                raise XStartError(msg % self)
            if not ok:
                msg = 'Failed to start X on display "%s" (xdpyinfo check failed, stderr:[%s]).'
                raise XStartTimeoutError(msg % (d, xdpyinfo.stderr))

        return self
コード例 #19
0
    def start(self):
        """
        start display

        :rtype: self
        """
        if self.use_xauth:
            self._setup_xauth()
        EasyProcess.start(self)
        time.sleep(0.01)

        # https://github.com/ponty/PyVirtualDisplay/issues/2
        # https://github.com/ponty/PyVirtualDisplay/issues/14
        self.old_display_var = os.environ.get("DISPLAY", None)

        self.redirect_display(True)

        # wait until X server is active
        start_time = time.time()
        if self.check_startup:
            rp = self._check_startup_fd
            display_check = None
            rlist, wlist, xlist = select.select((rp, ), (), (),
                                                X_START_TIMEOUT)
            if rlist:
                display_check = os.read(rp, 10).rstrip()
            else:
                msg = "No display number returned by X server"
                raise XStartTimeoutError(msg)
            dnbs = str(self.display)
            if bytes != str:
                dnbs = bytes(dnbs, "ascii")
            if display_check != dnbs:
                msg = 'Display number "%s" not returned by X server' + str(
                    display_check)
                raise XStartTimeoutError(msg % self.display)

        d = self.new_display_var
        ok = False
        while True:
            if not EasyProcess.is_alive(self):
                break

            try:
                xdpyinfo = EasyProcess("xdpyinfo")
                xdpyinfo.enable_stdout_log = False
                xdpyinfo.enable_stderr_log = False
                exit_code = xdpyinfo.call().return_code
            except EasyProcessError:
                log.warning(
                    "xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!"
                )
                time.sleep(X_START_WAIT)  # old method
                ok = True
                break

            if exit_code != 0:
                pass
            else:
                log.info('Successfully started X with display "%s".', d)
                ok = True
                break

            if time.time() - start_time >= X_START_TIMEOUT:
                break
            time.sleep(X_START_TIME_STEP)
        if not EasyProcess.is_alive(self):
            log.warning("process exited early", )
            msg = "Failed to start process: %s"
            raise XStartError(msg % self)
        if not ok:
            msg = 'Failed to start X on display "%s" (xdpyinfo check failed, stderr:[%s]).'
            raise XStartTimeoutError(msg % (d, xdpyinfo.stderr))
        return self