Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 11, 2023
1 parent bc658e1 commit 164ea2d
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,27 @@ def grabclipboard():
except subprocess.CalledProcessError:
loginctl = None
else:
loginctl = None
loginctl = None

if loginctl is not None:
username = subprocess.check_output("whoami").decode().strip("\n")
sessionid = [line.split()[0] for line in loginctl if username in line.split()][0]
sessiontype = subprocess.check_output(
["loginctl", "show-session", sessionid, "-p", "Type"]
).decode().strip("\n").split("=")[1]
else: # Session type check failed
sessionid = [

Check warning on line 153 in src/PIL/ImageGrab.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageGrab.py#L152-L153

Added lines #L152 - L153 were not covered by tests
line.split()[0] for line in loginctl if username in line.split()
][0]
sessiontype = (

Check warning on line 156 in src/PIL/ImageGrab.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageGrab.py#L156

Added line #L156 was not covered by tests
subprocess.check_output(
["loginctl", "show-session", sessionid, "-p", "Type"]
)
.decode()
.strip("\n")
.split("=")[1]
)
else: # Session type check failed
sessiontype = None

if shutil.which("wl-paste") and ((sessiontype == "wayland") or (sessiontype is None)):
if shutil.which("wl-paste") and (
(sessiontype == "wayland") or (sessiontype is None)
):
output = subprocess.check_output(["wl-paste", "-l"]).decode()
mimetypes = output.splitlines()
if "image/png" in mimetypes:
Expand All @@ -170,7 +179,9 @@ def grabclipboard():
args = ["wl-paste"]
if mimetype:
args.extend(["-t", mimetype])
elif shutil.which("xclip") and ((sessiontype == "x11") or (sessiontype is None)):
elif shutil.which("xclip") and (
(sessiontype == "x11") or (sessiontype is None)
):
args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
else:
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
Expand Down

0 comments on commit 164ea2d

Please sign in to comment.