forked from openlp/openlp
parent
7697febb2a
commit
94dd107abe
@ -343,7 +343,7 @@ def delete_file(file_path):
|
||||
if file_path.exists():
|
||||
file_path.unlink()
|
||||
return True
|
||||
except (IOError, OSError):
|
||||
except OSError:
|
||||
log.exception('Unable to delete file {file_path}'.format(file_path=file_path))
|
||||
return False
|
||||
|
||||
|
@ -97,8 +97,8 @@ def get_web_page(url, headers=None, update_openlp=False, proxies=None):
|
||||
response = requests.get(url, headers=headers, proxies=proxies, timeout=float(CONNECTION_TIMEOUT))
|
||||
log.debug('Downloaded page {url}'.format(url=response.url))
|
||||
break
|
||||
except IOError:
|
||||
# For now, catch IOError. All requests errors inherit from IOError
|
||||
except OSError:
|
||||
# For now, catch OSError. All requests errors inherit from OSError
|
||||
log.exception('Unable to connect to {url}'.format(url=url))
|
||||
response = None
|
||||
if retries >= CONNECTION_RETRIES:
|
||||
@ -127,7 +127,7 @@ def get_url_file_size(url):
|
||||
try:
|
||||
response = requests.head(url, timeout=float(CONNECTION_TIMEOUT), allow_redirects=True)
|
||||
return int(response.headers['Content-Length'])
|
||||
except IOError:
|
||||
except OSError:
|
||||
if retries > CONNECTION_RETRIES:
|
||||
raise ConnectionError('Unable to download {url}'.format(url=url))
|
||||
else:
|
||||
@ -173,7 +173,7 @@ def url_get_file(callback, url, file_path, sha256=None):
|
||||
file_path.unlink()
|
||||
return False
|
||||
break
|
||||
except IOError:
|
||||
except OSError:
|
||||
trace_error_handler(log)
|
||||
if retries > CONNECTION_RETRIES:
|
||||
if file_path.exists():
|
||||
|
@ -233,7 +233,7 @@ def create_paths(*paths, **kwargs):
|
||||
try:
|
||||
if not path.exists():
|
||||
path.mkdir(parents=True)
|
||||
except IOError:
|
||||
except OSError:
|
||||
if not kwargs.get('do_not_log', False):
|
||||
log.exception('failed to check if directory exists or create directory')
|
||||
|
||||
|
@ -103,7 +103,7 @@ def get_text_file_string(text_file_path):
|
||||
# no BOM was found
|
||||
file_handle.seek(0)
|
||||
content = file_handle.read()
|
||||
except (IOError, UnicodeError):
|
||||
except (OSError, UnicodeError):
|
||||
log.exception('Failed to open text file {text}'.format(text=text_file_path))
|
||||
return content
|
||||
|
||||
|
@ -155,7 +155,7 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties):
|
||||
try:
|
||||
with file_path.open('w') as report_file:
|
||||
report_file.write(report_text)
|
||||
except IOError:
|
||||
except OSError:
|
||||
log.exception('Failed to write crash report')
|
||||
|
||||
def on_send_report_button_clicked(self):
|
||||
|
@ -1367,7 +1367,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, RegistryProperties):
|
||||
'- Please wait for copy to finish').format(path=self.new_data_path))
|
||||
dir_util.copy_tree(str(old_data_path), str(self.new_data_path))
|
||||
log.info('Copy successful')
|
||||
except (IOError, os.error, DistutilsFileError) as why:
|
||||
except (OSError, DistutilsFileError) as why:
|
||||
self.application.set_normal_cursor()
|
||||
log.exception('Data copy failed {err}'.format(err=str(why)))
|
||||
err_text = translate('OpenLP.MainWindow',
|
||||
|
@ -609,7 +609,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
|
||||
if not os.path.exists(save_file):
|
||||
shutil.copy(audio_from, save_file)
|
||||
zip_file.write(audio_from, audio_to)
|
||||
except IOError:
|
||||
except OSError:
|
||||
self.log_exception('Failed to save service to disk: {name}'.format(name=temp_file_name))
|
||||
self.main_window.error_message(translate('OpenLP.ServiceManager', 'Error Saving File'),
|
||||
translate('OpenLP.ServiceManager', 'There was an error saving your file.'))
|
||||
@ -670,7 +670,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
|
||||
zip_file = zipfile.ZipFile(temp_file_name, 'w', zipfile.ZIP_STORED, True)
|
||||
# First we add service contents.
|
||||
zip_file.writestr(service_file_name, service_content)
|
||||
except IOError:
|
||||
except OSError:
|
||||
self.log_exception('Failed to save service to disk: {name}'.format(name=temp_file_name))
|
||||
self.main_window.error_message(translate('OpenLP.ServiceManager', 'Error Saving File'),
|
||||
translate('OpenLP.ServiceManager', 'There was an error saving your file.'))
|
||||
@ -802,11 +802,11 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
|
||||
else:
|
||||
critical_error_message_box(message=translate('OpenLP.ServiceManager', 'File is not a valid service.'))
|
||||
self.log_error('File contains no service data')
|
||||
except (IOError, NameError):
|
||||
except (OSError, NameError):
|
||||
self.log_exception('Problem loading service file {name}'.format(name=file_name))
|
||||
critical_error_message_box(message=translate('OpenLP.ServiceManager',
|
||||
'File could not be opened because it is corrupt.'))
|
||||
except zipfile.BadZipfile:
|
||||
except zipfile.BadZipFile:
|
||||
if os.path.getsize(file_name) == 0:
|
||||
self.log_exception('Service file is zero sized: {name}'.format(name=file_name))
|
||||
QtWidgets.QMessageBox.information(self, translate('OpenLP.ServiceManager', 'Empty File'),
|
||||
|
@ -604,7 +604,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
else:
|
||||
with full_name.open('wb') as out_file:
|
||||
out_file.write(theme_zip.read(zipped_file))
|
||||
except (IOError, zipfile.BadZipfile):
|
||||
except (OSError, zipfile.BadZipFile):
|
||||
self.log_exception('Importing theme from zip failed {name}'.format(name=file_path))
|
||||
raise ValidationError
|
||||
except ValidationError:
|
||||
@ -667,7 +667,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
theme_path = theme_dir / '{file_name}.json'.format(file_name=name)
|
||||
try:
|
||||
theme_path.write_text(theme_pretty)
|
||||
except IOError:
|
||||
except OSError:
|
||||
self.log_exception('Saving theme to file failed')
|
||||
if image_source_path and image_destination_path:
|
||||
if self.old_background_image_path and image_destination_path != self.old_background_image_path:
|
||||
@ -675,7 +675,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
if image_source_path != image_destination_path:
|
||||
try:
|
||||
copyfile(image_source_path, image_destination_path)
|
||||
except IOError:
|
||||
except OSError:
|
||||
self.log_exception('Failed to save theme image')
|
||||
self.generate_and_save_image(name, theme)
|
||||
|
||||
|
@ -96,7 +96,7 @@ class VersionWorker(QtCore.QObject):
|
||||
remote_version = response.text
|
||||
log.debug('New version found: %s', remote_version)
|
||||
break
|
||||
except IOError:
|
||||
except OSError:
|
||||
log.exception('Unable to connect to OpenLP server to download version file')
|
||||
retries += 1
|
||||
else:
|
||||
@ -182,7 +182,7 @@ def get_version():
|
||||
try:
|
||||
version_file = open(file_path, 'r')
|
||||
full_version = str(version_file.read()).rstrip()
|
||||
except IOError:
|
||||
except OSError:
|
||||
log.exception('Error in version file.')
|
||||
full_version = '0.0.0-bzr000'
|
||||
finally:
|
||||
|
@ -70,7 +70,7 @@ class PptviewController(PresentationController):
|
||||
try:
|
||||
self.start_process()
|
||||
return self.process.CheckInstalled()
|
||||
except WindowsError:
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
def start_process(self):
|
||||
|
@ -233,7 +233,7 @@ class TestHttpUtils(TestCase, TestMixin):
|
||||
Test socket timeout gets caught
|
||||
"""
|
||||
# GIVEN: Mocked urlopen to fake a network disconnect in the middle of a download
|
||||
mocked_requests.get.side_effect = IOError
|
||||
mocked_requests.get.side_effect = OSError
|
||||
|
||||
# WHEN: Attempt to retrieve a file
|
||||
url_get_file(MagicMock(), url='http://localhost/test', file_path=Path(self.tempfile))
|
||||
|
@ -371,13 +371,13 @@ class TestPath(TestCase):
|
||||
@patch('openlp.core.common.path.log')
|
||||
def test_create_paths_dir_io_error(self, mocked_logger):
|
||||
"""
|
||||
Test the create_paths() when an IOError is raised
|
||||
Test the create_paths() when an OSError is raised
|
||||
"""
|
||||
# GIVEN: A `Path` to check with patched out mkdir and exists methods
|
||||
mocked_path = MagicMock()
|
||||
mocked_path.exists.side_effect = IOError('Cannot make directory')
|
||||
mocked_path.exists.side_effect = OSError('Cannot make directory')
|
||||
|
||||
# WHEN: An IOError is raised when checking the if the path exists.
|
||||
# WHEN: An OSError is raised when checking the if the path exists.
|
||||
create_paths(mocked_path)
|
||||
|
||||
# THEN: The Error should have been logged
|
||||
@ -385,7 +385,7 @@ class TestPath(TestCase):
|
||||
|
||||
def test_create_paths_dir_value_error(self):
|
||||
"""
|
||||
Test the create_paths() when an error other than IOError is raised
|
||||
Test the create_paths() when an error other than OSError is raised
|
||||
"""
|
||||
# GIVEN: A `Path` to check with patched out mkdir and exists methods
|
||||
mocked_path = MagicMock()
|
||||
|
@ -168,7 +168,7 @@ class TestLib(TestCase):
|
||||
patch.object(Path, 'open'):
|
||||
file_path = Path('testfile.txt')
|
||||
file_path.is_file.return_value = True
|
||||
file_path.open.side_effect = IOError()
|
||||
file_path.open.side_effect = OSError()
|
||||
|
||||
# WHEN: get_text_file_string is called
|
||||
result = get_text_file_string(file_path)
|
||||
|
@ -40,7 +40,7 @@ class TestFirstTimeWizard(TestMixin, TestCase):
|
||||
Test get_web_page will attempt CONNECTION_RETRIES+1 connections - bug 1409031
|
||||
"""
|
||||
# GIVEN: Initial settings and mocks
|
||||
mocked_requests.get.side_effect = IOError('Unable to connect')
|
||||
mocked_requests.get.side_effect = OSError('Unable to connect')
|
||||
|
||||
# WHEN: A webpage is requested
|
||||
try:
|
||||
|
@ -144,7 +144,7 @@ class TestPresentationController(TestCase):
|
||||
# GIVEN: A mocked open, get_thumbnail_folder and exists
|
||||
with patch('openlp.plugins.presentations.lib.presentationcontroller.Path.read_text') as mocked_read_text, \
|
||||
patch(FOLDER_TO_PATCH) as mocked_get_thumbnail_folder:
|
||||
mocked_read_text.side_effect = IOError()
|
||||
mocked_read_text.side_effect = OSError()
|
||||
mocked_get_thumbnail_folder.return_value = Path('test')
|
||||
|
||||
# WHEN: calling get_titles_and_notes
|
||||
|
@ -36,7 +36,7 @@ def convert_file_service_item(test_path, name, row=0):
|
||||
try:
|
||||
items = json.load(open_file)
|
||||
first_line = items[row]
|
||||
except IOError:
|
||||
except OSError:
|
||||
first_line = ''
|
||||
finally:
|
||||
open_file.close()
|
||||
|
Loading…
Reference in New Issue
Block a user