From 0e74c5dbaa5556a8667d6c1fb62ada1e91aeed5f Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Wed, 31 Dec 2014 11:56:50 +0100 Subject: [PATCH] Rearranged regex config options to reduce hierarchies --- beetsplug/ihate.py | 13 ++++--------- docs/plugins/ihate.rst | 16 +++++++--------- test/test_ihate.py | 8 ++++---- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/beetsplug/ihate.py b/beetsplug/ihate.py index b7980e02c..3fdcb26f7 100644 --- a/beetsplug/ihate.py +++ b/beetsplug/ihate.py @@ -57,17 +57,12 @@ class IHatePlugin(BeetsPlugin): self.path_singleton_regex = \ re.compile(self.config['path'].get()) - if 'album' in self.config: - album_config = self.config['album'] - if 'path' in album_config: - self.path_album_regex = re.compile( - album_config['path'].get()) + if 'album_path' in self.config: + self.path_album_regex = re.compile(self.config['album_path'].get()) - if 'singleton' in self.config: - singleton_config = self.config['singleton'] - if 'path' in singleton_config: + if 'singleton_path' in self.config: self.path_singleton_regex = re.compile( - singleton_config['path'].get()) + self.config['singleton_path'].get()) @classmethod def do_i_hate_this(cls, task, action_patterns): diff --git a/docs/plugins/ihate.rst b/docs/plugins/ihate.rst index 3fb5e4ffc..14d1219ec 100644 --- a/docs/plugins/ihate.rst +++ b/docs/plugins/ihate.rst @@ -22,11 +22,11 @@ file. The available options are: Default: ``[]``. - **path**: A regular expression to filter files based on its path and name. Default: ``.*`` (everything) -- **album** and **singleton**: You may specify different regular expressions - used for imports of albums and singletons. This way, you can automatically - skip singletons when importing albums if the names (and paths) of the files - are distinguishable via a regex. The path regex defined here take precedence - over the global ``path`` option. +- **album_path** and **singleton_path**: You may specify different regular + expressions used for imports of albums and singletons. This way, you can + automatically skip singletons when importing albums if the names (and paths) + of the files are distinguishable via a regex. The path regex defined here + take precedence over the global ``path`` option. Here's an example:: @@ -43,10 +43,8 @@ Here's an example:: - album:christmas path: .*\d\d[^/]+$ # will only import files which names start with two digits - album: - path: .*\d\d[^/]+$ - singleton: - path: .*/(?!\d\d)[^/]+$ + album_path: .*\d\d[^/]+$ + singleton_path: .*/(?!\d\d)[^/]+$ The plugin trusts your decision in "as-is" imports. diff --git a/test/test_ihate.py b/test/test_ihate.py index af996e740..7d25f5938 100644 --- a/test/test_ihate.py +++ b/test/test_ihate.py @@ -157,7 +157,7 @@ class IHatePluginTest(unittest.TestCase, ImportHelper): # Album options def test_import_album(self): self.__reset_config() - config['ihate']['album']['path'] = '.*track_1.*\.mp3' + config['ihate']['album_path'] = '.*track_1.*\.mp3' self.__run([self.artist_paths[0], self.misc_paths[0]]) self.__run(self.all_paths, singletons=True) @@ -165,7 +165,7 @@ class IHatePluginTest(unittest.TestCase, ImportHelper): # Singleton options def test_import_singleton(self): self.__reset_config() - config['ihate']['singleton']['path'] = '.*track_1.*\.mp3' + config['ihate']['singleton_path'] = '.*track_1.*\.mp3' self.__run([self.artist_paths[0], self.misc_paths[0]], singletons=True) self.__run(self.all_paths) @@ -173,8 +173,8 @@ class IHatePluginTest(unittest.TestCase, ImportHelper): # Album and singleton options def test_import_both(self): self.__reset_config() - config['ihate']['album']['path'] = '.*track_1.*\.mp3' - config['ihate']['singleton']['path'] = '.*track_2.*\.mp3' + config['ihate']['album_path'] = '.*track_1.*\.mp3' + config['ihate']['singleton_path'] = '.*track_2.*\.mp3' self.__run([self.artist_paths[0], self.misc_paths[0]]) self.__run([self.artist_paths[1],