From cb4b7b6f63658671dc3757df729caa7fbce2d8ef Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 5 Jun 2020 20:00:40 +0200 Subject: [PATCH] File permission is now set to 770 This fixes #19 --- deemix/app/cli.py | 3 ++- deemix/app/downloader.py | 11 +++++++++-- deemix/app/settings.py | 4 +++- deemix/app/spotify.py | 4 +++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/deemix/app/cli.py b/deemix/app/cli.py index a094ac2..d37d560 100644 --- a/deemix/app/cli.py +++ b/deemix/app/cli.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 import os.path as path -from os import mkdir +from os import mkdir, chmod from deemix.utils import localpaths from deemix.api.deezer import Deezer @@ -32,6 +32,7 @@ def login(): arl = requestValidArl() with open(path.join(configFolder, '.arl'), 'w') as f: f.write(arl) + chmod(path.join(configFolder, '.arl'), 0o770) def downloadLink(url, settings, bitrate=None): diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 2ae1094..dbc733a 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -3,7 +3,7 @@ import os.path import re import traceback from concurrent.futures import ThreadPoolExecutor -from os import makedirs, remove, system as execute +from os import makedirs, remove, system as execute, chmod from tempfile import gettempdir from time import sleep @@ -93,7 +93,8 @@ def downloadImage(url, path, overwrite="n"): image.raise_for_status() with open(path, 'wb') as f: f.write(image.content) - return path + chmod(path, 0o770) + return path except ConnectionError: sleep(1) return downloadImage(url, path, overwrite) @@ -674,6 +675,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None if not os.path.isfile(os.path.join(filepath, filename + '.lrc')) or settings['overwriteFile'] in ['y', 't']: with open(os.path.join(filepath, filename + '.lrc'), 'wb') as f: f.write(track['lyrics']['sync'].encode('utf-8')) + chmod(os.path.join(filepath, filename + '.lrc'), 0o770) # Save local album art if coverPath: @@ -710,6 +712,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None try: with open(writepath, 'wb') as stream: stream_track(dz, track, stream, trackAPI, queueItem, interface) + chmod(writepath, 0o770) except downloadCancelled: remove(writepath) result['cancel'] = True @@ -885,13 +888,16 @@ def after_download(tracks, settings, queueItem): if settings['logErrors'] and errors != "": with open(os.path.join(extrasPath, 'errors.txt'), 'wb') as f: f.write(errors.encode('utf-8')) + chmod(os.path.join(extrasPath, 'errors.txt'), 0o770) if settings['logSearched'] and searched != "": with open(os.path.join(extrasPath, 'searched.txt'), 'wb') as f: f.write(searched.encode('utf-8')) + chmod(os.path.join(extrasPath, 'searched.txt'), 0o770) if settings['createM3U8File']: with open(os.path.join(extrasPath, 'playlist.m3u8'), 'wb') as f: for line in playlist: f.write((line + "\n").encode('utf-8')) + chmod(os.path.join(extrasPath, 'playlist.m3u8'), 0o770) if settings['executeCommand'] != "": execute(settings['executeCommand'].replace("%folder%", extrasPath)) return extrasPath @@ -914,6 +920,7 @@ def after_download_single(track, settings, queueItem): orig += "\r\n" orig += track['searched'] + "\r\n" f.write(orig.encode('utf-8')) + chmod(os.path.join(track['extrasPath'], 'searched.txt'), 0o770) if settings['executeCommand'] != "": execute(settings['executeCommand'].replace("%folder%", track['extrasPath'])) return track['extrasPath'] diff --git a/deemix/app/settings.py b/deemix/app/settings.py index ff98097..3966c27 100644 --- a/deemix/app/settings.py +++ b/deemix/app/settings.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import json import os.path as path -from os import makedirs +from os import makedirs, chmod import random import string import logging @@ -30,6 +30,7 @@ def initSettings(localFolder = False, configFolder = None): if not path.isfile(path.join(configFolder, 'config.json')): with open(path.join(configFolder, 'config.json'), 'w') as f: json.dump(defaultSettings, f, indent=2) + chmod(path.join(configFolder, 'config.json'), 0o770) with open(path.join(configFolder, 'config.json'), 'r') as configFile: settings = json.load(configFile) settingsCheck() @@ -59,6 +60,7 @@ def saveSettings(newSettings): settings = newSettings with open(path.join(configDir, 'config.json'), 'w') as configFile: json.dump(settings, configFile, indent=2) + chmod(path.join(configDir, 'config.json'), 0o770) return True diff --git a/deemix/app/spotify.py b/deemix/app/spotify.py index 10dedc7..abfaf5c 100644 --- a/deemix/app/spotify.py +++ b/deemix/app/spotify.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import json import os.path as path -from os import mkdir +from os import mkdir, chmod import spotipy from spotipy.oauth2 import SpotifyClientCredentials @@ -42,6 +42,7 @@ class SpotifyHelper: if not path.isfile(path.join(self.configFolder, 'authCredentials.json')): with open(path.join(self.configFolder, 'authCredentials.json'), 'w') as f: json.dump({'clientId': "", 'clientSecret': ""}, f, indent=2) + chmod(path.join(self.configFolder, 'authCredentials.json'), 0o770) with open(path.join(self.configFolder, 'authCredentials.json'), 'r') as credentialsFile: self.credentials = json.load(credentialsFile) self.checkCredentials() @@ -64,6 +65,7 @@ class SpotifyHelper: def setCredentials(self, spotifyCredentials): with open(path.join(self.configFolder, 'authCredentials.json'), 'w') as f: json.dump(spotifyCredentials, f, indent=2) + chmod(path.join(self.configFolder, 'authCredentials.json'), 0o770) self.credentials = spotifyCredentials self.checkCredentials()