2 # Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
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.
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.
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.
22 sys
.stderr
.write('Please run this first: ./build_errcodedb.py >errcodedb.py\n')
25 def to_pxenv_status(errno
):
29 return (errno
>> 8) & 0x1f
31 def to_errfile(errno
):
32 return (errno
>> 13) & 0x7ff
34 def to_posix_errno(errno
):
35 return (errno
>> 24) & 0x7f
37 def lookup_errno_component(defines
, component
):
38 if component
in defines
:
39 return defines
[component
]
41 return '0x%x' % component
43 class Errcode(object):
44 def __init__(self
, errno
):
45 self
.pxenv_status
= to_pxenv_status(errno
)
46 self
.uniq
= to_uniq(errno
)
47 self
.errfile
= to_errfile(errno
)
48 self
.posix_errno
= to_posix_errno(errno
)
51 return 'pxenv_status=0x%x uniq=%d errfile=0x%x posix_errno=0x%x' % (self
.pxenv_status
, self
.uniq
, self
.errfile
, self
.posix_errno
)
54 return 'pxenv_status=%s uniq=%d errfile=%s posix_errno=%s' % (
55 lookup_errno_component(errcodedb
.pxenv_status
, self
.pxenv_status
),
57 lookup_errno_component(errcodedb
.errfile
, self
.errfile
),
58 lookup_errno_component(errcodedb
.posix_errno
, self
.posix_errno
)
62 return self
.prettystr()
65 sys
.stderr
.write('usage: %s ERROR_NUMBER\n' % sys
.argv
[0])
68 if __name__
== '__main__':
69 if len(sys
.argv
) != 2:
73 errno
= int(sys
.argv
[1], 16)