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 Return a list of file from the listbox
""" """
files = [] return [unicode(listbox.item(i).text()) for i in range(listbox.count())]
for row in range(0, listbox.count()):
files.append(unicode(listbox.item(row).text()))
return files
def removeSelectedItems(self, listbox): def removeSelectedItems(self, listbox):
""" """

View File

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

View File

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