def childprocess_backend_version(backend): p = run_mod_as_subproc("pyscreenshot.cli.print_backend_version", [backend]) if p.return_code != 0: log.warning(p) raise FailedBackendError(p) return p.stdout
def childprocess_grab(backend, bbox): with TemporaryDirectory(prefix="pyscreenshot") as tmpdirname: filename = os.path.join(tmpdirname, "screenshot.png") cmd = ["--filename", filename] if bbox: x1, y1, x2, y2 = map(str, bbox) bbox = ":".join(map(str, (x1, y1, x2, y2))) cmd += ["--bbox", bbox] if backend: cmd += ["--backend", backend] if log.isEnabledFor(logging.DEBUG): cmd += ["--debug"] p = run_mod_as_subproc("pyscreenshot.cli.grab", cmd) if p.return_code != 0: # log.debug(p) raise FailedBackendError(p) data = open(filename, "rb").read() data = codec[1](data) return data
def auto(bbox, childprocess): im = None for backend_class in backends(childprocess): backend_name = backend_class.name try: if select_childprocess(childprocess, backend_class): log.debug('running "%s" in child process', backend_name) im = childprocess_grab(backend_name, bbox) else: obj = backend_class() im = obj.grab(bbox) break except Exception: msg = traceback.format_exc() log.debug(msg) if not im: msg = "All backends failed!" raise FailedBackendError(msg) return im