Rearranged regex config options to reduce hierarchies

This commit is contained in:
Malte Ried 2014-12-31 11:56:50 +01:00
parent 8addf3ef39
commit 0e74c5dbaa
3 changed files with 15 additions and 22 deletions

View file

@ -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):

View file

@ -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.

View file

@ -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],