Skip to content

Commit

Permalink
Fix dirty stderr to curses when opening image.
Browse files Browse the repository at this point in the history
  • Loading branch information
wustho committed Feb 11, 2020
1 parent 2a128dc commit 6f461db
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions epr.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
import json
import tempfile
import shutil
import subprocess
import xml.etree.ElementTree as ET
from urllib.parse import unquote
from html import unescape
from subprocess import run
from html.parser import HTMLParser
from difflib import SequenceMatcher as SM

Expand Down Expand Up @@ -607,24 +607,32 @@ def find_media_viewer():
"firefox"
]
if sys.platform == "win32":
VWR = "start"
VWR = ["start"]
elif sys.platform == "darwin":
VWR = "open"
VWR = ["open"]
else:
for i in VWR_LIST:
if shutil.which(i) is not None:
VWR = i
if VWR == "gio": VWR += " open"
VWR = [i]
break

if VWR[0] in {"gio"}:
VWR.append("open")


def open_media(scr, epub, src):
sfx = os.path.splitext(src)[1]
fd, path = tempfile.mkstemp(suffix=sfx)
try:
with os.fdopen(fd, "wb") as tmp:
tmp.write(epub.file.read(src))
run(VWR +" "+ path, shell=True)
# run(VWR +" "+ path, shell=True)
subprocess.call(
VWR + [path],
# shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
k = scr.getch()
finally:
os.remove(path)
Expand Down

0 comments on commit 6f461db

Please sign in to comment.