|
1 | | -from rdopkg.utils.exception import RdopkgException |
2 | | -# TODO before 1.0: merge utils.exception.* here. |
3 | | -# Legacy reasons to have them separate no longer apply. |
4 | | -from rdopkg.utils.exception import BranchNotFound # NOQA |
5 | | -from rdopkg.utils.exception import BuildArchSanityCheckFailed # NOQA |
6 | | -from rdopkg.utils.exception import CommandFailed # NOQA |
7 | | -from rdopkg.utils.exception import CommandNotFound # NOQA |
8 | | -from rdopkg.utils.exception import DuplicatePatchesBaseError # NOQA |
9 | | -from rdopkg.utils.exception import IncompleteChangelog # NOQA |
10 | | -from rdopkg.utils.exception import InvalidAction # NOQA |
11 | | -from rdopkg.utils.exception import ModuleNotAvailable # NOQA |
12 | | -from rdopkg.utils.exception import MultipleSpecFilesFound # NOQA |
13 | | -from rdopkg.utils.exception import RpmModuleNotAvailable # NOQA |
14 | | -from rdopkg.utils.exception import SpecFileNotFound # NOQA |
15 | | -from rdopkg.utils.exception import SpecFileParseError # NOQA |
| 1 | +class RdopkgException(Exception): |
| 2 | + msg_fmt = "An unknown error occurred" |
| 3 | + exit_code = 1 |
| 4 | + |
| 5 | + def __init__(self, msg=None, exit_code=None, **kwargs): |
| 6 | + self.kwargs = kwargs |
| 7 | + if not msg: |
| 8 | + try: |
| 9 | + msg = self.msg_fmt % kwargs |
| 10 | + except Exception: |
| 11 | + # kwargs doesn't match those in message. |
| 12 | + # Returning this is still better than nothing. |
| 13 | + msg = self.msg_fmt |
| 14 | + if exit_code is not None: |
| 15 | + self.exit_code = exit_code |
| 16 | + super(RdopkgException, self).__init__(msg) |
| 17 | + |
| 18 | + |
| 19 | +class CommandFailed(RdopkgException): |
| 20 | + msg_fmt = "Command failed: %(cmd)s" |
| 21 | + |
| 22 | + |
| 23 | +class CommandNotFound(RdopkgException): |
| 24 | + msg_fmt = "Command not found: %(cmd)s" |
| 25 | + |
| 26 | + |
| 27 | +class InvalidRemoteBranch(RdopkgException): |
| 28 | + msg_fmt = "Git remote not found for remote branch: %(branch)s" |
| 29 | + |
| 30 | + |
| 31 | +class BranchNotFound(RdopkgException): |
| 32 | + msg_fmt = "Expected git branch not found: %(branch)s" |
| 33 | + |
| 34 | + |
| 35 | +class SpecFileNotFound(RdopkgException): |
| 36 | + msg_fmt = "No .spec files found." |
| 37 | + |
| 38 | + |
| 39 | +class IncompleteChangelog(RdopkgException): |
| 40 | + msg_fmt = "Description of changes is missing in %%changelog." |
| 41 | + |
| 42 | + |
| 43 | +class MultipleSpecFilesFound(RdopkgException): |
| 44 | + msg_fmt = "Multiple .spec files found. Expected only one." |
| 45 | + |
| 46 | + |
| 47 | +class SpecFileParseError(RdopkgException): |
| 48 | + msg_fmt = "Error parsing .spec file '%(spec_fn)s': %(error)s" |
| 49 | + |
| 50 | + |
| 51 | +class ModuleNotAvailable(RdopkgException): |
| 52 | + msg_fmt = "Module %(module)s is not available. Unable to continue." |
| 53 | + |
| 54 | + |
| 55 | +class RpmModuleNotAvailable(ModuleNotAvailable): |
| 56 | + msg_fmt = ("Module rpm is not available. It is required to parse .spec " |
| 57 | + "files. Pro tip: `yum install rpm-python`") |
| 58 | + |
| 59 | + |
| 60 | +class InvalidAction(RdopkgException): |
| 61 | + msg_fmt = "Invalid action: %(action)s" |
| 62 | + |
| 63 | + |
| 64 | +class BuildArchSanityCheckFailed(RdopkgException): |
| 65 | + msg_fmt = ("Due to mysterious ways of rpm, BuildArch needs to be placed " |
| 66 | + "AFTER SourceX and PatchX lines in .spec file, " |
| 67 | + "otherwise %%{patches} macro will be empty " |
| 68 | + "and both %%autosetup and `git am %%{patches}` will fail.\n\n" |
| 69 | + "Please move BuildArch AFTER SourceX and PatchX.") |
| 70 | + |
| 71 | + |
| 72 | +class DuplicatePatchesBaseError(RdopkgException): |
| 73 | + msg_fmt = ("Please make sure to only have one " |
| 74 | + "# patches_base= entry in .spec") |
16 | 75 |
|
17 | 76 |
|
18 | 77 | class UserAbort(RdopkgException): |
|
0 commit comments