summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicodebo <nico.debo@openmailbox.org>2017-07-20 16:34:33 +0200
committernicodebo <nico.debo@openmailbox.org>2017-07-21 17:31:28 +0200
commitd3990e805bf43843eb3692e02c33b601cf9622fe (patch)
tree179d68828406098c749123545a932be9fd934242
parentb40a7e94f64bc854c33bdc6c8c70d2287e5f0f6a (diff)
downloadperl-app-clerk-d3990e805bf43843eb3692e02c33b601cf9622fe.tar.gz
perl-app-clerk-d3990e805bf43843eb3692e02c33b601cf9622fe.tar.xz
Fix trackrating does not exist
The first time rating a track, a FileNotFoundError is raised because ~/.config/clerk/trackratings.json does not exists: - Moved the file opening (i.e. load_fastlistTrack) 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.
-rwxr-xr-xclerk_helper14
1 files changed, 9 insertions, 5 deletions
diff --git a/clerk_helper b/clerk_helper
index 9257bc0..47e3bb2 100755
--- a/clerk_helper
+++ b/clerk_helper
@@ -159,17 +159,21 @@ def prune_fastlistTrack(fastlist, mpdcachefile):
return (new, newhdata)
def rateTrack(args):
- fastlist = load_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json')
+ """ rate a single track: create/update json track database and update mpd
+ sticker database
+ """
try:
+ fastlist = load_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json')
entry = get_entryTrack(fastlist, args.artist, args.album, args.track, args.title)
entry["rating"] = args.rating
- save_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json', fastlist)
- uri = client.find('artist', args.artist, 'album', args.album, 'track', args.track, 'title', args.title)
- for i in uri:
- client.sticker_set("song", i['file'], "rating", args.rating)
except KeyError:
entry = {'artist': args.artist, 'album': args.album, 'track': args.track, 'title': args.title, 'rating': args.rating}
append_entryTrack(fastlist, entry)
+ except FileNotFoundError:
+ fastlist = ([], {})
+ entry = {'artist': args.artist, 'album': args.album, 'track': args.track, 'title': args.title, 'rating': args.rating}
+ fastlist[0].append(entry)
+ finally:
save_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json', fastlist)
uri = client.find('artist', args.artist, 'album', args.album, 'track', args.track, 'title', args.title)
for i in uri: