forked from openlp/openlp
fixed long line; use generator
This commit is contained in:
parent
4f38ae2809
commit
49ff37c530
@ -235,7 +235,8 @@ class Ui_ServiceManager(object):
|
|||||||
self.edit_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Edit Item'),
|
self.edit_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Edit Item'),
|
||||||
icon=':/general/general_edit.png', triggers=self.remote_edit)
|
icon=':/general/general_edit.png', triggers=self.remote_edit)
|
||||||
self.rename_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Rename...'),
|
self.rename_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Rename...'),
|
||||||
icon=':/general/general_edit.png', triggers=self.on_service_item_rename)
|
icon=':/general/general_edit.png',
|
||||||
|
triggers=self.on_service_item_rename)
|
||||||
self.maintain_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Reorder Item'),
|
self.maintain_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Reorder Item'),
|
||||||
icon=':/general/general_edit.png',
|
icon=':/general/general_edit.png',
|
||||||
triggers=self.on_service_item_edit_form)
|
triggers=self.on_service_item_edit_form)
|
||||||
|
@ -46,18 +46,16 @@ from openlp.plugins.songs.lib.songcompare import songs_probably_equal
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SongIterator(object):
|
def song_generator(songs):
|
||||||
"""
|
"""
|
||||||
This class implements an iterator for the song duplicate finder. The iterator returns a tuple of two songs. When
|
This is a generator function to return tuples of two songs. When completed then all songs have once been returned
|
||||||
completely iterated then all songs have once been returned combined with any other songs.
|
combined with any other songs.
|
||||||
"""
|
|
||||||
def __init__(self, songs):
|
|
||||||
self.songs = songs
|
|
||||||
|
|
||||||
def __iter__(self):
|
:param songs: All songs in the database.
|
||||||
for outer_song_counter in range(len(self.songs) - 1):
|
"""
|
||||||
for inner_song_counter in range(outer_song_counter + 1, len(self.songs)):
|
for outer_song_counter in range(len(songs) - 1):
|
||||||
yield (self.songs[outer_song_counter], self.songs[inner_song_counter])
|
for inner_song_counter in range(outer_song_counter + 1, len(songs)):
|
||||||
|
yield (songs[outer_song_counter], songs[inner_song_counter])
|
||||||
|
|
||||||
|
|
||||||
class DuplicateSongRemovalForm(OpenLPWizard, RegistryProperties):
|
class DuplicateSongRemovalForm(OpenLPWizard, RegistryProperties):
|
||||||
@ -185,8 +183,7 @@ class DuplicateSongRemovalForm(OpenLPWizard, RegistryProperties):
|
|||||||
# Create a worker/process pool to check the songs.
|
# Create a worker/process pool to check the songs.
|
||||||
process_number = max(1, multiprocessing.cpu_count() - 1)
|
process_number = max(1, multiprocessing.cpu_count() - 1)
|
||||||
pool = multiprocessing.Pool(process_number)
|
pool = multiprocessing.Pool(process_number)
|
||||||
song_list = SongIterator(songs)
|
result = pool.imap_unordered(songs_probably_equal, song_generator(songs), 30)
|
||||||
result = pool.imap_unordered(songs_probably_equal, song_list, 30)
|
|
||||||
# Do not accept any further tasks. Also this closes the processes if all tasks are done.
|
# Do not accept any further tasks. Also this closes the processes if all tasks are done.
|
||||||
pool.close()
|
pool.close()
|
||||||
# While the processes are still working, start to look at the results.
|
# While the processes are still working, start to look at the results.
|
||||||
|
Loading…
Reference in New Issue
Block a user