only try to import a database when it is a v1 database, clean ups

This commit is contained in:
Andreas Preikschat 2011-04-15 16:10:31 +02:00
parent 342a5d8e84
commit 237cabfeff
3 changed files with 58 additions and 57 deletions

View File

@ -459,10 +459,7 @@ class SongImportForm(OpenLPWizard):
"""
Return a list of file from the listbox
"""
files = []
for row in range(0, listbox.count()):
files.append(unicode(listbox.item(row).text()))
return files
return [unicode(listbox.item(i).text()) for i in range(listbox.count())]
def removeSelectedItems(self, listbox):
"""

View File

@ -61,10 +61,12 @@ class OpenLP1SongImport(SongImport):
"""
Run the import for an openlp.org 1.x song database.
"""
# Connect to the database
if not self.import_source.endswith(u'.olp'):
return False
encoding = self.get_encoding()
if not encoding:
return False
# Connect to the database
connection = sqlite.connect(self.import_source, mode=0444,
encoding=(encoding, 'replace'))
cursor = connection.cursor()

View File

@ -78,58 +78,60 @@ class SongBeamerImport(SongImport):
"""
Receive a single file or a list of files to import.
"""
if isinstance(self.import_source, list):
self.import_wizard.progressBar.setMaximum(
len(self.import_source))
for file in self.import_source:
# TODO: check that it is a valid SongBeamer file
self.set_defaults()
self.current_verse = u''
self.current_verse_type = VerseType.Tags[VerseType.Verse]
read_verses = False
file_name = os.path.split(file)[1]
self.import_wizard.incrementProgressBar(
WizardStrings.ImportingType % file_name, 0)
if os.path.isfile(file):
detect_file = open(file, u'r')
details = chardet.detect(detect_file.read(2048))
detect_file.close()
infile = codecs.open(file, u'r', details['encoding'])
songData = infile.readlines()
infile.close()
else:
return False
self.title = file_name.split('.sng')[0]
read_verses = False
for line in songData:
# Just make sure that the line is of the type 'Unicode'.
line = unicode(line).strip()
if line.startswith(u'#') and not read_verses:
self.parse_tags(line)
elif line.startswith(u'---'):
if self.current_verse:
self.replace_html_tags()
self.add_verse(self.current_verse,
self.current_verse_type)
self.current_verse = u''
self.current_verse_type = VerseType.Tags[VerseType.Verse]
read_verses = True
verse_start = True
elif read_verses:
if verse_start:
verse_start = False
if not self.check_verse_marks(line):
self.current_verse = line + u'\n'
else:
self.current_verse += line + u'\n'
if self.current_verse:
self.replace_html_tags()
self.add_verse(self.current_verse, self.current_verse_type)
if self.check_complete():
self.finish()
self.import_wizard.incrementProgressBar(
WizardStrings.ImportingType % file_name)
return True
self.import_wizard.progressBar.setMaximum(len(self.import_source))
if not isinstance(self.import_source, list):
return False
for file in self.import_source:
# TODO: check that it is a valid SongBeamer file
if self.stop_import_flag:
return False
self.set_defaults()
self.current_verse = u''
self.current_verse_type = VerseType.Tags[VerseType.Verse]
read_verses = False
file_name = os.path.split(file)[1]
self.import_wizard.incrementProgressBar(
WizardStrings.ImportingType % file_name, 0)
if os.path.isfile(file):
detect_file = open(file, u'r')
details = chardet.detect(detect_file.read(2048))
detect_file.close()
infile = codecs.open(file, u'r', details['encoding'])
songData = infile.readlines()
infile.close()
else:
return False
self.title = file_name.split('.sng')[0]
read_verses = False
for line in songData:
# Just make sure that the line is of the type 'Unicode'.
line = unicode(line).strip()
if line.startswith(u'#') and not read_verses:
self.parse_tags(line)
elif line.startswith(u'---'):
if self.current_verse:
self.replace_html_tags()
self.add_verse(self.current_verse,
self.current_verse_type)
self.current_verse = u''
self.current_verse_type = VerseType.Tags[VerseType.Verse]
read_verses = True
verse_start = True
elif read_verses:
if verse_start:
verse_start = False
if not self.check_verse_marks(line):
self.current_verse = line + u'\n'
else:
self.current_verse += line + u'\n'
if self.current_verse:
self.replace_html_tags()
self.add_verse(self.current_verse, self.current_verse_type)
if self.check_complete():
self.finish()
self.import_wizard.incrementProgressBar(
WizardStrings.ImportingType % file_name)
return True
def replace_html_tags(self):
"""