aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2024-10-26 19:46:13 +0200
committerWolfgang Müller2024-10-26 19:46:13 +0200
commit9ecf39499a70f7d1e8977aed66fd041356bd9b58 (patch)
tree390959552aabc3613fce944817a0e99d6d906778
parent9860a2185b8b4300fb33fe9f59140d591bdc2884 (diff)
downloadlater-9ecf39499a70f7d1e8977aed66fd041356bd9b58.tar.gz
Introduce small helper function for sys.exit
This saves us from specifying the program name every single time we want the program to exit with an error message.
Diffstat (limited to '')
-rwxr-xr-xlater10
1 files changed, 7 insertions, 3 deletions
diff --git a/later b/later
index 61d8abe..5b82a6e 100755
--- a/later
+++ b/later
@@ -21,6 +21,10 @@ class YTDLPLogger:
print("later: yt-dlp:", msg, file=sys.stderr)
+def exit(message=""):
+ sys.exit(f"later: {message}" if message else 0)
+
+
def get_xdg(type, fallback):
env = f"XDG_{type.upper()}_HOME"
if env in os.environ:
@@ -75,7 +79,7 @@ class TitleMap:
# Clobber the title cache if it was corrupted
self.commit_to_disk = True
except Exception as err:
- sys.exit(f"later: cannot read title cache: {err}")
+ exit(f"cannot read title cache: {err}")
def mark_seen(self, key):
self.seen.add(key)
@@ -96,7 +100,7 @@ class TitleMap:
# necessary: importing yt_dlp is noticeably slow :(
import yt_dlp
except ModuleNotFoundError:
- sys.exit("later: yt-dlp was requested, but yt_dlp python module not found")
+ exit("yt-dlp was requested, but yt_dlp python module not found")
if not self.ytdl:
self.ytdl = yt_dlp.YoutubeDL({"logger": YTDLPLogger()})
@@ -131,7 +135,7 @@ class TitleMap:
with open(self.path, "w") as handle:
json.dump(seen_entries, handle)
except OSError as err:
- sys.exit(f"later: cannot write title cache: {err}")
+ exit(f"cannot write title cache: {err}")
def entries(title_map):