diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index a09223a20..08c6cbe38 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -66,15 +66,20 @@ class BibleDB(QtCore.QObject): raise KeyError(u'Missing keyword argument "path".') if u'config' not in kwargs: raise KeyError(u'Missing keyword argument "config".') - if u'name' not in kwargs: - raise KeyError(u'Missing keyword argument "name".') + if u'name' not in kwargs and u'file' not in kwargs: + raise KeyError(u'Missing keyword argument "name" or "file".') self.stop_import_flag = False self.config = kwargs[u'config'] - self.name = kwargs[u'name'] - #self.filename = self.clean_filename(kwargs[u'name']) - self.db_file = os.path.join(kwargs[u'path'], - u'%s.sqlite' % self.name) - log.debug(u'Load bible %s on path %s', self.name, self.db_file) + if u'name' in kwargs: + self.name = kwargs[u'name'] + if not isinstance(self.name, unicode): + self.name = unicode(self.name, u'utf-8') + self.file = self.clean_filename(self.name) + if u'file' in kwargs: + self.file = kwargs[u'file'] + + self.db_file = os.path.join(kwargs[u'path'], self.file) + log.debug(u'Load bible %s on path %s', self.file, self.db_file) db_type = self.config.get_config(u'db type', u'sqlite') db_url = u'' if db_type == u'sqlite': @@ -87,18 +92,30 @@ class BibleDB(QtCore.QObject): self.config.get_config(u'db database')) self.metadata, self.session = init_models(db_url) self.metadata.create_all(checkfirst=True) + if u'file' in kwargs: + self.get_name() + + def get_name(self): + version_name = self.get_meta(u'Version') + if version_name: + self.name = version_name.value + else: + self.name = None + return self.name def clean_filename(self, old_filename): + if not isinstance(old_filename, unicode): + old_filename = unicode(old_filename, u'utf-8') for char in [u'\\', u'/', u':', u'*', u'?', u'"', u'<', u'>', u'|', u' ']: old_filename = old_filename.replace(char, u'_') old_filename = re.sub(r'[_]+', u'_', old_filename).strip(u'_') - return old_filename + return old_filename + u'.sqlite' def register(self, wizard): """ This method basically just initialialises the database. It is called from the Bible Manager when a Bible is imported. Descendant classes - may want to override this method to supply their own custom + may want to override this method to suVersionpply their own custom initialisation as well. """ self.wizard = wizard diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 5fc871abc..12b4eeec8 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -123,17 +123,21 @@ class BibleManager(object): log.debug(u'Bible Files %s', files) self.db_cache = {} for filename in files: - name, extension = os.path.splitext(filename) - self.db_cache[name] = BibleDB(self.parent, path=self.path, - name=name, config=self.config) + bible = BibleDB(self.parent, path=self.path, file=filename, + config=self.config) + #self.db_cache[name] = BibleDB(self.parent, path=self.path, + # name=name, config=self.config) + name = bible.get_name() + log.debug(u'Bible Name: "%s"', name) + self.db_cache[name] = bible # look to see if lazy load bible exists and get create getter. source = self.db_cache[name].get_meta(u'download source') if source: download_name = self.db_cache[name].get_meta(u'download name').value meta_proxy = self.db_cache[name].get_meta(u'proxy url') - web_bible = HTTPBible(self.parent, path=self.path, name=name, - config=self.config, download_source=source.value, - download_name=download_name) + web_bible = HTTPBible(self.parent, path=self.path, + file=filename, config=self.config, + download_source=source.value, download_name=download_name) if meta_proxy: web_bible.set_proxy_server(meta_proxy.value) #del self.db_cache[name]