diff options
author | nicodebo <nico.debo@openmailbox.org> | 2017-07-21 00:40:30 +0200 |
---|---|---|
committer | nicodebo <nico.debo@openmailbox.org> | 2017-07-22 12:50:15 +0200 |
commit | 04bb38ff174cb98bf49474bfb5a41d27050a5510 (patch) | |
tree | 1ef2f3f1ab41eb9f970adcc700ab93a00f287819 | |
parent | 436489984829371f13765d2ac08863bd4f1589d4 (diff) | |
download | perl-app-clerk-04bb38ff174cb98bf49474bfb5a41d27050a5510.tar.gz perl-app-clerk-04bb38ff174cb98bf49474bfb5a41d27050a5510.tar.xz |
Fix albumratings does not exist
The first time rating an album, a FileNotFoundError is raised
because ~/.config/clerk/albumratings.json does not exists:
- Moved the file opening (i.e. load_fastlist) inside the 'try'
block and added an except clause, to catch the FileNotFoundError
exception and process it accordingly.
- Moved the action of saving the json track database and setting the
sticker into a 'finally' block in order not to duplicate lines of code
in the different blocks of the try/except.
- Replaced the 'artist' tag with the 'albumartist' one.
-rwxr-xr-x | clerk_helper | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/clerk_helper b/clerk_helper index 47e3bb2..ee4fa88 100755 --- a/clerk_helper +++ b/clerk_helper @@ -89,19 +89,20 @@ def prune_fastlist(fastlist, mpdcachefile): return (new, newhdata) def rateAlbum(args): - fastlist = load_fastlist(os.getenv('HOME')+'/.config/clerk/albumratings.json') try: + fastlist = load_fastlist(os.getenv('HOME')+'/.config/clerk/albumratings.json') entry = get_entry(fastlist, args.artist, args.album, args.date) entry["rating"] = args.rating - save_fastlist(os.getenv('HOME')+'/.config/clerk/albumratings.json', fastlist) - uri = client.find('albumartist', args.artist, 'album', args.album, 'date', args.date, 'track', os.getenv('track'), 'disc', os.getenv('disc')) - for i in uri: - client.sticker_set("song", i['file'], "albumrating", args.rating) except KeyError: entry = {'albumartist': args.artist, 'album': args.album, 'date': args.date, 'disc': os.getenv('disc'), 'track': os.getenv('track'), 'rating': args.rating} append_entry(fastlist, entry) + except FileNotFoundError: + fastlist = ([], {}) + entry = {'albumartist': args.artist, 'album': args.album, 'date': args.date, 'disc': os.getenv('disc'), 'track': os.getenv('track'), 'rating': args.rating} + fastlist[0].append(entry) + finally: save_fastlist(os.getenv('HOME')+'/.config/clerk/albumratings.json', fastlist) - uri = client.find('artist', args.artist, 'album', args.album, 'date', args.date, 'track', os.getenv('track'), 'disc', os.getenv('disc')) + uri = client.find('albumartist', args.artist, 'album', args.album, 'date', args.date, 'track', os.getenv('track'), 'disc', os.getenv('disc')) for i in uri: client.sticker_set("song", i['file'], "albumrating", args.rating) |