forked from openlp/openlp
create temp directory name in constructor
This commit is contained in:
parent
928467847e
commit
c70ac5e656
@ -70,6 +70,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
self.suffix = u'.sqlite'
|
self.suffix = u'.sqlite'
|
||||||
self.settingsSection = u'bibles'
|
self.settingsSection = u'bibles'
|
||||||
self.path = AppLocation.get_section_data_path(self.settingsSection)
|
self.path = AppLocation.get_section_data_path(self.settingsSection)
|
||||||
|
self.temp_dir = os.path.join(gettempdir(), u'openlp')
|
||||||
self.files = self.manager.old_bible_databases
|
self.files = self.manager.old_bible_databases
|
||||||
self.success = {}
|
self.success = {}
|
||||||
self.newbibles = {}
|
self.newbibles = {}
|
||||||
@ -420,14 +421,14 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
elif self.currentPage() == self.selectPage:
|
elif self.currentPage() == self.selectPage:
|
||||||
temp_dir = os.path.join(gettempdir(), u'openlp')
|
check_directory_exists(self.temp_dir)
|
||||||
check_directory_exists(temp_dir)
|
|
||||||
for number, filename in enumerate(self.files):
|
for number, filename in enumerate(self.files):
|
||||||
if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
||||||
continue
|
continue
|
||||||
# Move bibles to temp dir.
|
# Move bibles to temp dir.
|
||||||
if not os.path.exists(os.path.join(temp_dir, filename[0])):
|
if not os.path.exists(os.path.join(self.temp_dir, filename[0])):
|
||||||
shutil.move(os.path.join(self.path, filename[0]), temp_dir)
|
shutil.move(
|
||||||
|
os.path.join(self.path, filename[0]), self.temp_dir)
|
||||||
else:
|
else:
|
||||||
delete_file(os.path.join(self.path, filename[0]))
|
delete_file(os.path.join(self.path, filename[0]))
|
||||||
return True
|
return True
|
||||||
@ -488,7 +489,6 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
for number, file in enumerate(self.files):
|
for number, file in enumerate(self.files):
|
||||||
if self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
if self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
||||||
max_bibles += 1
|
max_bibles += 1
|
||||||
temp_dir = os.path.join(gettempdir(), u'openlp')
|
|
||||||
oldBible = None
|
oldBible = None
|
||||||
for number, filename in enumerate(self.files):
|
for number, filename in enumerate(self.files):
|
||||||
# Close the previous bible's connection.
|
# Close the previous bible's connection.
|
||||||
@ -504,7 +504,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
||||||
continue
|
continue
|
||||||
self.progressBar.reset()
|
self.progressBar.reset()
|
||||||
oldBible = OldBibleDB(self.mediaItem, path=temp_dir,
|
oldBible = OldBibleDB(self.mediaItem, path=self.temp_dir,
|
||||||
file=filename[0])
|
file=filename[0])
|
||||||
name = filename[1]
|
name = filename[1]
|
||||||
if name is None:
|
if name is None:
|
||||||
@ -694,7 +694,6 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
"""
|
"""
|
||||||
Clean up the UI after the import has finished.
|
Clean up the UI after the import has finished.
|
||||||
"""
|
"""
|
||||||
temp_dir = os.path.join(gettempdir(), u'openlp')
|
|
||||||
successful_import = 0
|
successful_import = 0
|
||||||
failed_import = 0
|
failed_import = 0
|
||||||
for number, filename in enumerate(self.files):
|
for number, filename in enumerate(self.files):
|
||||||
@ -704,12 +703,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
# Delete upgraded (but not complete, corrupted, ...) bible.
|
# Delete upgraded (but not complete, corrupted, ...) bible.
|
||||||
delete_file(os.path.join(self.path, filename[0]))
|
delete_file(os.path.join(self.path, filename[0]))
|
||||||
# Copy not upgraded bible back.
|
# Copy not upgraded bible back.
|
||||||
try:
|
shutil.move(os.path.join(self.temp_dir, filename[0]), self.path)
|
||||||
shutil.move(os.path.join(temp_dir, filename[0]), self.path)
|
|
||||||
except shutil.Error:
|
|
||||||
# We can ignore any error, because the temp directory is
|
|
||||||
# will be deleted later.
|
|
||||||
pass
|
|
||||||
if self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
if self.checkBox[number].checkState() == QtCore.Qt.Checked:
|
||||||
failed_import += 1
|
failed_import += 1
|
||||||
if failed_import > 0:
|
if failed_import > 0:
|
||||||
@ -735,5 +729,5 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
self.progressLabel.setText(translate(
|
self.progressLabel.setText(translate(
|
||||||
'BiblesPlugin.UpgradeWizardForm', 'Upgrade failed.'))
|
'BiblesPlugin.UpgradeWizardForm', 'Upgrade failed.'))
|
||||||
# Remove temp directory.
|
# Remove temp directory.
|
||||||
shutil.rmtree(temp_dir, True)
|
shutil.rmtree(self.temp_dir, True)
|
||||||
OpenLPWizard.postWizard(self)
|
OpenLPWizard.postWizard(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user