TMU (Too Many Updates)

This commit is contained in:
Geoffrey Frogeye 2019-10-17 12:44:30 +02:00
parent 392dfed89a
commit 789f26d925
12 changed files with 147 additions and 76 deletions

View file

@ -1,11 +1,19 @@
#!/usr/bin/env python3
# pylint: disable=C0103
"""
Find the subjectively best software
to open the file given in arguments with.
Doesn't use that XDG mess (only in last resort).
"""
import os
import sys
import magic
import subprocess
import urllib.request
import sys
import tempfile
import urllib.request
import magic
# Getting what's needed
path = sys.argv[1]
@ -25,7 +33,7 @@ else:
mime = tuple(mime.split('/'))
assert len(mime) == 2
graphical = not not os.environ.get('DISPLAY')
graphical = os.environ.get('DISPLAY')
# Some energumens
if mime[0] == "application" and mime[1] in ("json", "javascript"):
@ -34,7 +42,7 @@ if mime[0] == "application" and mime[1] in ("json", "javascript"):
# Determine stuff
ex = None # Executable needed to open the file
forcelocal = False # If we need to copy the file locally before opening it
isterm = False # Executable should run in a terminal
isterm = False # Executable should run in a terminal
if mime[0] == "text":
if not ishttp:
@ -46,13 +54,14 @@ elif mime[0] in ("audio", "video"):
ex = "mpv"
isterm = True
elif mime == ("application", "pdf"):
ex = "llpp.inotify"
ex = "zathura"
forcelocal = True
# Open stuff
tmp = None
if ex:
if forcelocal and ishttp:
assert buf
tmp = tempfile.NamedTemporaryFile(prefix='o')
tmp.write(chunk)
tmp.write(buf.read())
@ -66,6 +75,7 @@ if buf:
# TODO Launch a new terminal window for some
assert ex
p = subprocess.run([ex, path])
if tmp:
tmp.close()