diff options
author | nicodebo <nico.debo@openmailbox.org> | 2017-07-20 00:44:30 +0200 |
---|---|---|
committer | nicodebo <nico.debo@openmailbox.org> | 2017-07-22 17:16:08 +0200 |
commit | 518862a660e467648ca0d4f860389f3bb2d9a4ce (patch) | |
tree | 949826376ffc39b32a82dffd4c01dbb92d40d8bf /clerk_helper | |
parent | bad17e074fdc3686c5cabb60ab6470143c4a1924 (diff) | |
download | perl-app-clerk-518862a660e467648ca0d4f860389f3bb2d9a4ce.tar.gz perl-app-clerk-518862a660e467648ca0d4f860389f3bb2d9a4ce.tar.xz |
Implement xdg specification base directory
Follow xdg base directory specification,
see https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
- Use $XDG_CONFIG_HOME if it is set, otherwise use $HOME/.config
- Use $XDG_DATA_HOME if it is set, othewise use $HOME/.local/share
- split the clerk files between those two hereabove metionned
directories by keeping the clerk/config and clerk/podcasts inside
$XDG_CONFIG_HOME, and the rest inside $XDG_DATA_HOME
- Put all the file variables definition in a centralized location for
easier maintenance.
- Updated the README to reflect the XDG support
Diffstat (limited to 'clerk_helper')
-rwxr-xr-x | clerk_helper | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/clerk_helper b/clerk_helper index ee4fa88..4418cb6 100755 --- a/clerk_helper +++ b/clerk_helper @@ -90,7 +90,7 @@ def prune_fastlist(fastlist, mpdcachefile): def rateAlbum(args): try: - fastlist = load_fastlist(os.getenv('HOME')+'/.config/clerk/albumratings.json') + fastlist = load_fastlist(os.getenv('db_rate_album')) entry = get_entry(fastlist, args.artist, args.album, args.date) entry["rating"] = args.rating except KeyError: @@ -101,7 +101,7 @@ def rateAlbum(args): 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) + save_fastlist(os.getenv('db_rate_album'), 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) @@ -164,7 +164,7 @@ def rateTrack(args): sticker database """ try: - fastlist = load_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json') + fastlist = load_fastlistTrack(os.getenv('db_rate_track')) entry = get_entryTrack(fastlist, args.artist, args.album, args.track, args.title) entry["rating"] = args.rating except KeyError: @@ -175,7 +175,7 @@ def rateTrack(args): 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) + save_fastlistTrack(os.getenv('db_rate_track'), 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) @@ -183,12 +183,12 @@ def rateTrack(args): def cleanRatings(args): - fastlist = load_fastlist(os.getenv('HOME')+'/.config/clerk/albumratings.json') - prunedlist = prune_fastlist(fastlist, os.getenv('HOME')+'/.config/clerk/albums.cache.json') - save_fastlist(os.getenv('HOME')+'/.config/clerk/albumratings.json', prunedlist) - fastlist = load_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json') - prunedlist = prune_fastlistTrack(fastlist, os.getenv('HOME')+'/.config/clerk/tracks.cache.json') - save_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json', prunedlist) + fastlist = load_fastlist(os.getenv('db_rate_album')) + prunedlist = prune_fastlist(fastlist, os.getenv('cache_album')+'.json') + save_fastlist(os.getenv('db_rate_album'), prunedlist) + fastlist = load_fastlistTrack(os.getenv('db_rate_track')) + prunedlist = prune_fastlistTrack(fastlist, os.getenv('cache_track')+'.json') + save_fastlistTrack(os.getenv('db_rate_track'), prunedlist) def importTrackRatings(args): @@ -207,7 +207,7 @@ def importTrackRatings(args): track = x['track'] entry = {'artist': artist, 'album': album, 'track': track, 'title': title, 'rating': rating} rated_tracks.append(entry) - with open(os.getenv('HOME')+'/.config/clerk/trackratings.json', 'w') as ratingfile: + with open(os.getenv('db_rate_track'), 'w') as ratingfile: json.dump(rated_tracks, ratingfile) def importAlbumRatings(args): @@ -233,11 +233,11 @@ def importAlbumRatings(args): disc = "" entry = {'albumartist': artist, 'track': track, 'album': album, 'date': date, 'disc': disc, 'rating': rating} rated_tracks.append(entry) - with open(os.getenv('HOME')+'/.config/clerk/albumratings.json', 'w') as ratingfile: + with open(os.getenv('db_rate_album'), 'w') as ratingfile: json.dump(rated_tracks, ratingfile) def sendStickers(args): - with open(os.getenv('HOME')+'/.config/clerk/trackratings.json') as cache_file: + with open(os.getenv('db_rate_track')) as cache_file: content = json.load(cache_file) for track in content: uri = client.find('artist', track['artist'], 'album', track['album'], 'title', track['title'], 'track', track['track']) @@ -246,7 +246,7 @@ def sendStickers(args): client.sticker_set('song', x['file'], 'rating', rating) print("Imported Rating of "+rating+" for file "+x['file']) - with open(os.getenv('HOME')+'/.config/clerk/albumratings.json') as cache_file: + with open(os.getenv('db_rate_album')) as cache_file: content = json.load(cache_file) for album in content: uri = client.find('albumartist', album['albumartist'], 'album', album['album'], 'disc', album['disc'], 'date', album['date'], 'track', album['track']) |