Skip to content

Commit

Permalink
extra/main/spot: Verify subprocess return code
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rn3j committed Nov 28, 2024
1 parent ec1e4d8 commit 011b127
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/tauon/t_modules/t_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def archive_file_scan(path: str, extensions: str, launch_prefix: str="") -> floa
matches = 0
count = 0
line = launch_prefix + "unrar lb -p- " + shlex.quote(path) + " " + shlex.quote(os.path.dirname(path)) + os.sep
result = subprocess.run(shlex.split(line), stdout=subprocess.PIPE, check=False)
result = subprocess.run(shlex.split(line), stdout=subprocess.PIPE, check=True)
file_list = result.stdout.decode("utf-8", "ignore").split("\n")
#logging.info(file_list)
for fi in file_list:
Expand Down Expand Up @@ -525,7 +525,7 @@ def archive_file_scan(path: str, extensions: str, launch_prefix: str="") -> floa
matches = 0
count = 0
line = launch_prefix + "7z l " + shlex.quote(path) # + " " + shlex.quote(os.path.dirname(path)) + os.sep
result = subprocess.run(shlex.split(line), stdout=subprocess.PIPE, check=False)
result = subprocess.run(shlex.split(line), stdout=subprocess.PIPE, check=True)
file_list = result.stdout.decode("utf-8", "ignore").split("\n")
#logging.info(file_list)

Expand Down
22 changes: 11 additions & 11 deletions src/tauon/t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def whicher(target: str) -> bool | str:
if flatpak_mode:
complete = subprocess.run(
shlex.split("flatpak-spawn --host which " + target), stdout=subprocess.PIPE,
stderr=subprocess.PIPE, check=False)
stderr=subprocess.PIPE, check=True)
r = complete.stdout.decode()
return "bin/" + target in r
return shutil.which(target)
Expand Down Expand Up @@ -4647,42 +4647,42 @@ def scan_ffprobe(nt):
try:
result = subprocess.run(
[tauon.get_ffprobe(), "-v", "error", "-show_entries", "format=duration", "-of",
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=False)
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=True)
nt.length = float(result.stdout.decode())
except Exception:
logging.exception("FFPROBE couldn't supply a duration")
try:
result = subprocess.run(
[tauon.get_ffprobe(), "-v", "error", "-show_entries", "format_tags=title", "-of",
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=False)
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=True)
nt.title = str(result.stdout.decode())
except Exception:
logging.exception("FFPROBE couldn't supply a title")
try:
result = subprocess.run(
[tauon.get_ffprobe(), "-v", "error", "-show_entries", "format_tags=artist", "-of",
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=False)
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=True)
nt.artist = str(result.stdout.decode())
except Exception:
logging.exception("FFPROBE couldn't supply a artist")
try:
result = subprocess.run(
[tauon.get_ffprobe(), "-v", "error", "-show_entries", "format_tags=album", "-of",
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=False)
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=True)
nt.album = str(result.stdout.decode())
except Exception:
logging.exception("FFPROBE couldn't supply a album")
try:
result = subprocess.run(
[tauon.get_ffprobe(), "-v", "error", "-show_entries", "format_tags=date", "-of",
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=False)
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=True)
nt.date = str(result.stdout.decode())
except Exception:
logging.exception("FFPROBE couldn't supply a date")
try:
result = subprocess.run(
[tauon.get_ffprobe(), "-v", "error", "-show_entries", "format_tags=track", "-of",
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=False)
"default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=True)
nt.track_number = str(result.stdout.decode())
except Exception:
logging.exception("FFPROBE couldn't supply a track")
Expand Down Expand Up @@ -4958,7 +4958,7 @@ def tag_scan(nt: TrackClass) -> TrackClass | None:
if system == "Windows" or msys:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
result = subprocess.run([tauon.get_ffprobe(), "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=False)
result = subprocess.run([tauon.get_ffprobe(), "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", nt.fullpath], stdout=subprocess.PIPE, startupinfo=startupinfo, check=True)
nt.length = float(result.stdout.decode())
except Exception:
logging.exception("FFPROBE couldn't supply a duration")
Expand Down Expand Up @@ -21303,7 +21303,7 @@ def editor(index: int | None) -> None:
prefs.tag_editor_name + " launched.", "Fields will be updated once application is closed.", mode="arrow")
gui.update = 1

complete = subprocess.run(shlex.split(line), stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
complete = subprocess.run(shlex.split(line), stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)

if "picard" in prefs.tag_editor_target:
r = complete.stderr.decode()
Expand Down Expand Up @@ -26417,7 +26417,7 @@ def add_file(path, force_scan: bool = False) -> int | None:
gui.update += 1
line = launch_prefix + "unrar x -y -p- " + shlex.quote(path) + " " + shlex.quote(
target_dir) + os.sep
result = subprocess.run(shlex.split(line), check=False)
result = subprocess.run(shlex.split(line), check=True)
logging.info(result)
except Exception:
logging.exception("Failed to extract rar archive.")
Expand All @@ -26433,7 +26433,7 @@ def add_file(path, force_scan: bool = False) -> int | None:
gui.update += 1
line = launch_prefix + "7z x -y " + shlex.quote(path) + " -o" + shlex.quote(
target_dir) + os.sep
result = subprocess.run(shlex.split(line), check=False)
result = subprocess.run(shlex.split(line), check=True)
logging.info(result)
except Exception:
logging.exception("Failed to extract 7z archive.")
Expand Down
2 changes: 1 addition & 1 deletion src/tauon/t_modules/t_spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def play_target(self, id: int, force_new_device: bool = False, start_time: int =
time.sleep(3)
else:
self.launching_spotify = True
subprocess.run(["xdg-open", "spotify:track"], check=False)
subprocess.run(["xdg-open", "spotify:track"], check=True)
time.sleep(3)
logging.info("Launched spotify app via URI")

Expand Down

0 comments on commit 011b127

Please sign in to comment.