From 5a8cd52acf35a2bb3cfea38be2b5c1d4c5678d40 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 28 Apr 2010 00:49:21 +0100 Subject: [PATCH] File list refactor --- openlp/core/lib/settingsmanager.py | 23 ++++++++--------------- openlp/plugins/bibles/lib/manager.py | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/openlp/core/lib/settingsmanager.py b/openlp/core/lib/settingsmanager.py index 8d4b18ecd..d859ddea8 100644 --- a/openlp/core/lib/settingsmanager.py +++ b/openlp/core/lib/settingsmanager.py @@ -1,3 +1,4 @@ +import os.path # -*- coding: utf-8 -*- # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 @@ -153,16 +154,16 @@ class SettingsManager(object): return list @staticmethod - def get_files(section=None, suffix=None): + def get_files(section=None, extension=None): """ Get a list of files from the data files path. ``section`` Defaults to *None*. The section of code getting the files - used - to load from section directory. + to load from a section's data subdirectory. - ``suffix`` - Defaults to *None*. The extension to search for. + ``extension`` + Defaults to *None*. The extension to search for. """ path = AppLocation.get_data_path() if section: @@ -171,17 +172,9 @@ class SettingsManager(object): files = os.listdir(path) except: return [] - if suffix: - return_files = [] - for file in files: - if file.find(u'.') != -1: - filename = file.split(u'.') - filesuffix = filename[1].lower() - filesuffix = filesuffix.lower() - # only load files with the correct suffix - if suffix.find(filesuffix) > -1 : - return_files.append(file) - return return_files + if extension: + return [file for file in files + if extension == os.path.splitext(file)[1]] else: # no filtering required return files diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index ad9d4fcc6..1f962be90 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -114,7 +114,7 @@ class BibleManager(object): self.path = AppLocation.get_section_data_path(u'bibles') self.proxy_name = unicode( QtCore.QSettings().value(u'bibles/proxy name', u'').toString()) - self.suffix = u'sqlite' + self.suffix = u'.sqlite' self.import_wizard = None self.reload_bibles() self.media = None