diff --git a/beetsplug/permissions.py b/beetsplug/permissions.py index 1d2c45f0f..aaf923fe8 100644 --- a/beetsplug/permissions.py +++ b/beetsplug/permissions.py @@ -13,15 +13,17 @@ import os from beets import config, util from beets.plugins import BeetsPlugin from beets.util import ancestry +import six def convert_perm(perm): - """If the perm is a int then just return it, otherwise convert it to oct. + """Convert a string to an integer, interpreting the text as octal. + Or, if `perm` is an integer, reinterpret it as an octal number that + has been "misinterpreted" as decimal. """ - if isinstance(perm, int): - return perm - else: - return int(perm, 8) + if isinstance(perm, six.integer_types): + perm = six.text_type(perm) + return int(perm, 8) def check_permissions(path, permission): @@ -63,7 +65,7 @@ class Permissions(BeetsPlugin): # Adding defaults. self.config.add({ u'file': '644', - u'dir': '755' + u'dir': '755', }) self.register_listener('item_imported', self.fix) @@ -72,11 +74,12 @@ class Permissions(BeetsPlugin): def fix(self, lib, item=None, album=None): """Fix the permissions for an imported Item or Album. """ - # Getting the config. + # Get the configured permissions. The user can specify this either a + # string (in YAML quotes) or, for convenience, as an integer so the + # quotes can be omitted. In the latter case, we need to reinterpret the + # integer as octal, not decimal. file_perm = config['permissions']['file'].get() dir_perm = config['permissions']['dir'].get() - - # Converts permissions to oct. file_perm = convert_perm(file_perm) dir_perm = convert_perm(dir_perm) diff --git a/docs/changelog.rst b/docs/changelog.rst index 8e780b9a6..ef91a11da 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,9 +13,15 @@ New features: 'path' tag to the json outpu of a file which shows the relative path to the file. :bug:`2050` -Other fixes: +Fixes: * :doc:`/plugins/web`: Normalized the json output +* :doc:`/plugins/permissions`: Fix a regression in the previous release where + the plugin would always fail to set permissions (and log a warning). + :bug:`2089` + +The last release, 1.3.19, also erroneously reported its version as "1.3.18" +when you typed ``beet version``. This has been corrected. .. _six: https://pythonhosted.org/six/ diff --git a/test/test_permissions.py b/test/test_permissions.py index c6b1837b4..7234ec30d 100644 --- a/test/test_permissions.py +++ b/test/test_permissions.py @@ -74,6 +74,9 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper): def test_convert_perm_from_string(self): self.assertEqual(convert_perm('10'), 8) + def test_convert_perm_from_int(self): + self.assertEqual(convert_perm(10), 8) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)