Add config option to disable changing file permissions (advanced feature for now).

This commit is contained in:
Bas Stottelaar
2015-09-10 20:17:27 +02:00
parent c4403cc4de
commit 07b28605b5
3 changed files with 32 additions and 16 deletions

View File

@@ -85,8 +85,10 @@ _CONFIG_DEFINITIONS = {
'EXTRA_TORZNABS': (list, 'Torznab', ''),
'FILE_FORMAT': (str, 'General', 'Track Artist - Album [Year] - Title'),
'FILE_PERMISSIONS': (str, 'General', '0644'),
'FILE_PERMISSIONS_ENABLED': (bool_int, 'General', True),
'FILE_UNDERSCORES': (int, 'General', 0),
'FOLDER_FORMAT': (str, 'General', 'Artist/Album [Year]'),
'FOLDER_PERMISSIONS_ENABLED': (bool_int, 'General', True),
'FOLDER_PERMISSIONS': (str, 'General', '0755'),
'FREEZE_DB': (int, 'General', 0),
'GIT_BRANCH': (str, 'General', 'master'),

View File

@@ -809,10 +809,13 @@ def moveFiles(albumpath, release, tracks):
temp_f = os.path.join(temp_f, f)
try:
os.chmod(os.path.normpath(temp_f).encode(headphones.SYS_ENCODING, 'replace'), int(headphones.CONFIG.FOLDER_PERMISSIONS, 8))
except Exception as e:
logger.error("Error trying to change permissions on folder: %s. %s", temp_f.decode(headphones.SYS_ENCODING, 'replace'), e)
if headphones.CONFIG.FOLDER_PERMISSIONS_ENABLED:
try:
os.chmod(os.path.normpath(temp_f).encode(headphones.SYS_ENCODING, 'replace'), int(headphones.CONFIG.FOLDER_PERMISSIONS, 8))
except Exception as e:
logger.error("Error trying to change permissions on folder: %s. %s", temp_f.decode(headphones.SYS_ENCODING, 'replace'), e)
else:
logger.debug("Not changing folder permissions, since it is disabled: %s", temp_f.decode(headphones.SYS_ENCODING, 'replace'))
# If we failed to move all the files out of the directory, this will fail too
try:
@@ -1037,11 +1040,14 @@ def updateFilePermissions(albumpaths):
for r, d, f in os.walk(folder):
for files in f:
full_path = os.path.join(r, files)
try:
os.chmod(full_path, int(headphones.CONFIG.FILE_PERMISSIONS, 8))
except:
logger.error("Could not change permissions for file: %s", full_path)
continue
if headphones.CONFIG.FILE_PERMISSIONS_ENABLED:
try:
os.chmod(full_path, int(headphones.CONFIG.FILE_PERMISSIONS, 8))
except:
logger.error("Could not change permissions for file: %s", full_path)
continue
else:
logger.debug("Not changing file permissions, since it is disabled: %s", full_path.decode(headphones.SYS_ENCODING, 'replace'))
def renameUnprocessedFolder(path, tag):

View File

@@ -79,16 +79,24 @@ def torrent_to_file(target_file, data):
with open(target_file, "wb") as fp:
fp.write(data)
except IOError as e:
logger.error("Could not write torrent file '%s': %s. Skipping.",
logger.error(
"Could not write torrent file '%s': %s. Skipping.",
target_file, e.message)
return
# Try to change permissions
try:
os.chmod(target_file, int(headphones.CONFIG.FILE_PERMISSIONS, 8))
except OSError as e:
logger.warn("Could not change permissions for file '%s': %s. " \
"Continuing.", target_file, e.message)
if headphones.CONFIG.FILE_PERMISSIONS_ENABLED:
try:
os.chmod(target_file, int(headphones.CONFIG.FILE_PERMISSIONS, 8))
except OSError as e:
logger.warn(
"Could not change permissions for file '%s': %s. Continuing.",
target_file.decode(headphones.SYS_ENCODING, "replace"),
e.message)
else:
logger.debug(
"Not changing file permissions, since it is disabled: %s",
target_file.decode(headphones.SYS_ENCODING, "replace"))
# Done
return True
@@ -203,7 +211,7 @@ def searchforalbum(albumid=None, new=False, losslessOnly=False,
if release_date > datetime.datetime.today():
logger.info("Skipping: %s. Waiting for release date of: %s" % (album['AlbumTitle'], album['ReleaseDate']))
continue
new = True
if album['Status'] == "Wanted Lossless":