dak_exceptions.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. """
  3. Exception classes used in dak
  4. @contact: Debian FTP Master <ftpmaster@debian.org>
  5. @copyright: 2008 Mark Hymers <mhy@debian.org>
  6. @license: GNU General Public License version 2 or later
  7. """
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. class DakError(Exception):
  20. """
  21. Base class for all simple errors in this module.
  22. """
  23. def __init__(self, message=""):
  24. """
  25. @type message: string
  26. @param message: explanation of the error
  27. """
  28. Exception.__init__(self)
  29. self.args = str(message)
  30. self.message = str(message)
  31. def __str__(self):
  32. return self.message
  33. __all__ = ['DakError']
  34. # If you want to have a new exception in dak, add it here.
  35. dakerrors = {
  36. "ParseMaintError": """Exception raised for errors in parsing a maintainer field.""",
  37. "ParseChangesError": """Exception raised for errors in parsing a changes file.""",
  38. "InvalidDscError": """Exception raised for invalid dsc files.""",
  39. "UnknownFormatError": """Exception raised for unknown Format: lines in changes files.""",
  40. "NoFilesFieldError": """Exception raised for missing files field in dsc/changes.""",
  41. "CantOpenError": """Exception raised when files can't be opened.""",
  42. "CantOverwriteError": """Exception raised when files can't be overwritten.""",
  43. "FileExistsError": """Exception raised when destination file exists.""",
  44. "SendmailFailedError": """Exception raised when Sendmail invocation failed.""",
  45. "NoFreeFilenameError": """Exception raised when no alternate filename was found.""",
  46. "TransitionsError": """Exception raised when transitions file can't be parsed.""",
  47. "NoSourceFieldError": """Exception raised - we cant find the source - wtf?""",
  48. "MissingContents": """Exception raised - we could not determine contents for this deb""",
  49. "DBUpdateError": """Exception raised - could not update the database""",
  50. "ChangesUnicodeError": """Exception raised - changes file not properly utf-8 encoded""",
  51. "AlreadyLockedError": """Exception raised - package already locked by someone else""",
  52. "CantGetLockError": """Exception raised - lockfile already in use""",
  53. } #: All dak exceptions
  54. def construct_dak_exception(name, description):
  55. class Er(DakError):
  56. __doc__ = description
  57. setattr(Er, "__name__", name)
  58. return Er
  59. for e in dakerrors.keys():
  60. globals()[e] = construct_dak_exception(e, dakerrors[e])
  61. __all__ += [e]
  62. ################################################################################