forked from openlp/openlp
Fixed a bug where Bible names were being used for file names, and causing issues on various operating systems.
This commit is contained in:
parent
223393e38b
commit
9044ed3a4a
@ -66,15 +66,20 @@ class BibleDB(QtCore.QObject):
|
|||||||
raise KeyError(u'Missing keyword argument "path".')
|
raise KeyError(u'Missing keyword argument "path".')
|
||||||
if u'config' not in kwargs:
|
if u'config' not in kwargs:
|
||||||
raise KeyError(u'Missing keyword argument "config".')
|
raise KeyError(u'Missing keyword argument "config".')
|
||||||
if u'name' not in kwargs:
|
if u'name' not in kwargs and u'file' not in kwargs:
|
||||||
raise KeyError(u'Missing keyword argument "name".')
|
raise KeyError(u'Missing keyword argument "name" or "file".')
|
||||||
self.stop_import_flag = False
|
self.stop_import_flag = False
|
||||||
self.config = kwargs[u'config']
|
self.config = kwargs[u'config']
|
||||||
|
if u'name' in kwargs:
|
||||||
self.name = kwargs[u'name']
|
self.name = kwargs[u'name']
|
||||||
#self.filename = self.clean_filename(kwargs[u'name'])
|
if not isinstance(self.name, unicode):
|
||||||
self.db_file = os.path.join(kwargs[u'path'],
|
self.name = unicode(self.name, u'utf-8')
|
||||||
u'%s.sqlite' % self.name)
|
self.file = self.clean_filename(self.name)
|
||||||
log.debug(u'Load bible %s on path %s', self.name, self.db_file)
|
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_type = self.config.get_config(u'db type', u'sqlite')
|
||||||
db_url = u''
|
db_url = u''
|
||||||
if db_type == u'sqlite':
|
if db_type == u'sqlite':
|
||||||
@ -87,18 +92,30 @@ class BibleDB(QtCore.QObject):
|
|||||||
self.config.get_config(u'db database'))
|
self.config.get_config(u'db database'))
|
||||||
self.metadata, self.session = init_models(db_url)
|
self.metadata, self.session = init_models(db_url)
|
||||||
self.metadata.create_all(checkfirst=True)
|
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):
|
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' ']:
|
for char in [u'\\', u'/', u':', u'*', u'?', u'"', u'<', u'>', u'|', u' ']:
|
||||||
old_filename = old_filename.replace(char, u'_')
|
old_filename = old_filename.replace(char, u'_')
|
||||||
old_filename = re.sub(r'[_]+', u'_', old_filename).strip(u'_')
|
old_filename = re.sub(r'[_]+', u'_', old_filename).strip(u'_')
|
||||||
return old_filename
|
return old_filename + u'.sqlite'
|
||||||
|
|
||||||
def register(self, wizard):
|
def register(self, wizard):
|
||||||
"""
|
"""
|
||||||
This method basically just initialialises the database. It is called
|
This method basically just initialialises the database. It is called
|
||||||
from the Bible Manager when a Bible is imported. Descendant classes
|
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.
|
initialisation as well.
|
||||||
"""
|
"""
|
||||||
self.wizard = wizard
|
self.wizard = wizard
|
||||||
|
@ -123,17 +123,21 @@ class BibleManager(object):
|
|||||||
log.debug(u'Bible Files %s', files)
|
log.debug(u'Bible Files %s', files)
|
||||||
self.db_cache = {}
|
self.db_cache = {}
|
||||||
for filename in files:
|
for filename in files:
|
||||||
name, extension = os.path.splitext(filename)
|
bible = BibleDB(self.parent, path=self.path, file=filename,
|
||||||
self.db_cache[name] = BibleDB(self.parent, path=self.path,
|
config=self.config)
|
||||||
name=name, 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.
|
# look to see if lazy load bible exists and get create getter.
|
||||||
source = self.db_cache[name].get_meta(u'download source')
|
source = self.db_cache[name].get_meta(u'download source')
|
||||||
if source:
|
if source:
|
||||||
download_name = self.db_cache[name].get_meta(u'download name').value
|
download_name = self.db_cache[name].get_meta(u'download name').value
|
||||||
meta_proxy = self.db_cache[name].get_meta(u'proxy url')
|
meta_proxy = self.db_cache[name].get_meta(u'proxy url')
|
||||||
web_bible = HTTPBible(self.parent, path=self.path, name=name,
|
web_bible = HTTPBible(self.parent, path=self.path,
|
||||||
config=self.config, download_source=source.value,
|
file=filename, config=self.config,
|
||||||
download_name=download_name)
|
download_source=source.value, download_name=download_name)
|
||||||
if meta_proxy:
|
if meta_proxy:
|
||||||
web_bible.set_proxy_server(meta_proxy.value)
|
web_bible.set_proxy_server(meta_proxy.value)
|
||||||
#del self.db_cache[name]
|
#del self.db_cache[name]
|
||||||
|
Loading…
Reference in New Issue
Block a user