diff options
author | Wolfgang Müller | 2024-10-26 21:33:04 +0200 |
---|---|---|
committer | Wolfgang Müller | 2024-11-06 21:30:12 +0100 |
commit | f553ada1f4d0e1741aff828d83885caa80431f2d (patch) | |
tree | c4332c668cb774ce626b5f6d9c86668198e37578 | |
parent | ef2ba0943d941b080946f85993e4383cd5e0b1a3 (diff) | |
download | later-f553ada1f4d0e1741aff828d83885caa80431f2d.tar.gz |
Allow manually deleting watch_later entries
This commit introduces the "del" command which allows the user to delete
watch_later entries manually. Make sure to silently ignore entries that
were not found - we'll print the entire list of entries subsequently
anyway.
-rwxr-xr-x | later | 21 | ||||
-rw-r--r-- | later.1 | 6 |
2 files changed, 25 insertions, 2 deletions
@@ -35,6 +35,7 @@ def usage(message=""): lines.append("usage: later [options] [list]") lines.append(" [options] [add] item ...") + lines.append(" [options] del item ...") lines.append("options: [-u | --update-titles]") sys.exit("\n".join(lines)) @@ -228,6 +229,10 @@ def entries(title_map): yield WatchLaterEntry(name=name, path=entry.path, mtime=mtime) +def hexdigest(entry): + return hashlib.md5(entry.encode("utf-8")).hexdigest().upper() + + def list_entries(args, title_map): for entry in entries(title_map): print(entry.format(title_map)) @@ -235,8 +240,7 @@ def list_entries(args, title_map): def add_entries(args, title_map): for entry in args.rest: - filename = hashlib.md5(entry.encode("utf-8")).hexdigest().upper() - path = os.path.join(watch_later_dir, filename) + path = os.path.join(watch_later_dir, hexdigest(entry)) try: with open(path, "x") as handle: @@ -247,8 +251,21 @@ def add_entries(args, title_map): exit(e) +def delete_entries(args, title_map): + for entry in args.rest: + path = os.path.join(watch_later_dir, hexdigest(entry)) + + try: + os.remove(path) + except FileNotFoundError: + pass + except OSError as e: + exit(e) + + commands = { "add": Command("add", add_entries), + "del": Command("del", delete_entries), "list": Command("list", list_entries, implies_list=False, args=False), } @@ -12,6 +12,10 @@ .Op options .Op Ic add .Ar item ... +.Nm +.Op options +.Ic del +.Ar item ... .Sh DESCRIPTION .Nm is a program to manage watch_later entries as created by @@ -34,6 +38,8 @@ The commands are as follows: Creates watch_later entries for the given items. This command is implied if it wasn't explicitly given but there are remaining arguments. +.It Sy del Em item ... +Deletes watch_later entries matching the given items. .It Sy list Lists all watch_later entries. This command is implied if there are no remaining arguments. |