Permissions plugins listens now for album_imported and item_imported

This commit is contained in:
Marvin Steadfast 2014-11-24 18:41:50 +01:00
parent daeab3d3a9
commit d3b76d83d2
2 changed files with 33 additions and 12 deletions

View file

@ -35,9 +35,9 @@ class Permissions(BeetsPlugin):
})
@Permissions.listen('item_moved')
@Permissions.listen('item_copied')
def permissions(item, source, destination):
@Permissions.listen('item_imported')
@Permissions.listen('album_imported')
def permissions(lib, item=None, album=None):
"""Running the permission fixer.
"""
# Getting the config.
@ -46,11 +46,21 @@ def permissions(item, source, destination):
# Converts file permissions to oct.
file_perm = convert_perm(file_perm)
# Changing permissions on the destination path.
os.chmod(util.bytestring_path(destination), file_perm)
# Create chmod_queue.
chmod_queue = []
if item:
chmod_queue.append(item.path)
elif album:
for album_item in album.items():
chmod_queue.append(album_item.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)
# Setting permissions for every path in the queue.
for path in chmod_queue:
# Changing permissions on the destination path.
os.chmod(util.bytestring_path(path), file_perm)
# Checks if the destination 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)
print(message)

View file

@ -15,9 +15,8 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper):
def tearDown(self):
self.teardown_beets()
self.unload_plugins()
def test_perm(self):
def test_permissions_on_album_imported(self):
self.importer = self.create_importer()
self.importer.run()
item = self.lib.items().get()
@ -25,6 +24,18 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper):
config_perm = convert_perm(config_perm)
self.assertTrue(check_permissions(item.path, config_perm))
self.assertFalse(check_permissions(item.path, convert_perm(644)))
def test_permissions_on_item_imported(self):
self.config['import']['singletons'] = True
self.importer = self.create_importer()
self.importer.run()
item = self.lib.items().get()
config_perm = self.config['permissions']['file'].get()
config_perm = convert_perm(config_perm)
self.assertTrue(check_permissions(item.path, config_perm))
self.assertFalse(check_permissions(item.path, convert_perm(644)))
def suite():