You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

errcode.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. # Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License as
  6. # published by the Free Software Foundation; either version 2 of the
  7. # License, or any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. import sys
  18. try:
  19. import errcodedb
  20. except ImportError:
  21. sys.stderr.write('Please run this first: ./build_errcodedb.py >errcodedb.py\n')
  22. sys.exit(1)
  23. def to_pxenv_status(errno):
  24. return errno & 0xff
  25. def to_uniq(errno):
  26. return (errno >> 8) & 0x1f
  27. def to_errfile(errno):
  28. return (errno >> 13) & 0x7ff
  29. def to_posix_errno(errno):
  30. return (errno >> 24) & 0x7f
  31. def lookup_errno_component(defines, component):
  32. if component in defines:
  33. return defines[component]
  34. else:
  35. return '0x%x' % component
  36. class Errcode(object):
  37. def __init__(self, errno):
  38. self.pxenv_status = to_pxenv_status(errno)
  39. self.uniq = to_uniq(errno)
  40. self.errfile = to_errfile(errno)
  41. self.posix_errno = to_posix_errno(errno)
  42. def rawstr(self):
  43. return 'pxenv_status=0x%x uniq=%d errfile=0x%x posix_errno=0x%x' % (self.pxenv_status, self.uniq, self.errfile, self.posix_errno)
  44. def prettystr(self):
  45. return 'pxenv_status=%s uniq=%d errfile=%s posix_errno=%s' % (
  46. lookup_errno_component(errcodedb.pxenv_status, self.pxenv_status),
  47. self.uniq,
  48. lookup_errno_component(errcodedb.errfile, self.errfile),
  49. lookup_errno_component(errcodedb.posix_errno, self.posix_errno)
  50. )
  51. def __str__(self):
  52. return self.prettystr()
  53. def usage():
  54. sys.stderr.write('usage: %s ERROR_NUMBER\n' % sys.argv[0])
  55. sys.exit(1)
  56. if __name__ == '__main__':
  57. if len(sys.argv) != 2:
  58. usage()
  59. try:
  60. errno = int(sys.argv[1], 16)
  61. except ValueError:
  62. usage()
  63. print Errcode(errno)
  64. sys.exit(0)