From 8784e8d8ca90b0ca058078e4fe5651d801b7bc2e Mon Sep 17 00:00:00 2001 From: Marvin Steadfast Date: Thu, 20 Nov 2014 11:40:02 +0100 Subject: [PATCH] plugin now listens for item_copied instead of after_write. now the test works --- beetsplug/permissions.py | 15 ++++++++------- test/test_permissions.py | 4 +++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/beetsplug/permissions.py b/beetsplug/permissions.py index 2bab18abc..458debc09 100644 --- a/beetsplug/permissions.py +++ b/beetsplug/permissions.py @@ -35,8 +35,8 @@ class Permissions(BeetsPlugin): }) -@Permissions.listen('after_write') -def permissions(path): +@Permissions.listen('item_copied') +def permissions(item, source, destination): """Running the permission fixer. """ # Getting the config. @@ -45,10 +45,11 @@ def permissions(path): # Converts file permissions to oct. file_perm = convert_perm(file_perm) - # Changing permissions on the path. - os.chmod(util.bytestring_path(path), file_perm) + # Changing permissions on the destination path. + os.chmod(util.bytestring_path(destination), file_perm) - # Checks if the path has the permissions configured. - if not check_permissions(util.bytestring_path(path), file_perm): - message = 'There was a problem setting permission on {}'.format(path) + # Checks if the destination path has the permissions configured. + if not check_permissions(util.bytestring_path(destination), file_perm): + message = 'There was a problem setting permission on {}'.format( + destination) print(message) diff --git a/test/test_permissions.py b/test/test_permissions.py index 1b181b901..cad7a47da 100644 --- a/test/test_permissions.py +++ b/test/test_permissions.py @@ -1,3 +1,5 @@ +"""Tests for the 'permissions' plugin. +""" from _common import unittest from helper import TestHelper from beetsplug.permissions import check_permissions, convert_perm @@ -22,7 +24,7 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper): config_perm = self.config['permissions']['file'].get() config_perm = convert_perm(config_perm) - assert check_permissions(item.path, config_perm) + self.assertTrue(check_permissions(item.path, config_perm)) def suite():