| 1 |
from errno import ENOENT |
| 2 |
|
| 3 |
|
| 4 |
class InvalidArchiveError(Exception): |
| 5 |
"""Raised when libarchive can't open a file""" |
| 6 |
|
| 7 |
def __init__(self, fn, msg, *args, **kw): |
| 8 |
self._pickle_args = (fn, msg, *args) |
| 9 |
msg = ( |
| 10 |
f"Error with archive {fn}. You probably need to delete and re-download " |
| 11 |
f"or re-create this file. Message was:\n\n{msg}" |
| 12 |
) |
| 13 |
self.errno = ENOENT |
| 14 |
super().__init__(msg) |
| 15 |
|
| 16 |
def __reduce__(self): |
| 17 |
return type(self), self._pickle_args, {**self.__dict__, "args": self.args} |
| 18 |
|
| 19 |
|
| 20 |
class ArchiveCreationError(Exception): |
| 21 |
"""Raised when an archive fails during creation""" |
| 22 |
|
| 23 |
pass |
| 24 |
|
| 25 |
|
| 26 |
class CaseInsensitiveFileSystemError(InvalidArchiveError): |
| 27 |
def __init__(self, package_location, extract_location, **kwargs): |
| 28 |
message = f""" |
| 29 |
Cannot extract package to a case-insensitive file system. Your install |
| 30 |
destination does not differentiate between upper and lowercase |
| 31 |
characters, and this breaks things. Try installing to a location that |
| 32 |
is case-sensitive. Windows drives are usually the culprit here - can |
| 33 |
you install to a native Unix drive, or turn on case sensitivity for |
| 34 |
this (Windows) location? |
| 35 |
|
| 36 |
package location: {package_location} |
| 37 |
extract location: {extract_location} |
| 38 |
""" |
| 39 |
self.package_location = package_location |
| 40 |
self.extract_location = extract_location |
| 41 |
super().__init__(package_location, message, **kwargs) |
| 42 |
self._pickle_args = (package_location, extract_location) |
| 43 |
|
| 44 |
|
| 45 |
class ConversionError(Exception): |
| 46 |
def __init__(self, missing_files, mismatching_sizes, *args, **kw): |
| 47 |
self._pickle_args = (missing_files, mismatching_sizes, *args) |
| 48 |
self.missing_files = missing_files |
| 49 |
self.mismatching_sizes = mismatching_sizes |
| 50 |
errors = "" |
| 51 |
if self.missing_files: |
| 52 |
errors = f"Missing files in converted package: {self.missing_files}\n" |
| 53 |
errors = ( |
| 54 |
errors |
| 55 |
+ f"Mismatching sizes (corruption) in converted package: {self.mismatching_sizes}" |
| 56 |
) |
| 57 |
|
| 58 |
super().__init__(errors, *args, **kw) |
| 59 |
|
| 60 |
def __reduce__(self): |
| 61 |
return type(self), self._pickle_args, {**self.__dict__, "args": self.args} |