Browse Source

[Contribs] Add README, license text, and invert error code dictionaries.

tags/v0.9.4
Stefan Hajnoczi 16 years ago
parent
commit
fbf9295cbb
4 changed files with 106 additions and 13 deletions
  1. 32
    0
      contrib/errcode/README
  2. 33
    5
      contrib/errcode/build_errcodedb.py
  3. 18
    0
      contrib/errcode/errcode.php
  4. 23
    8
      contrib/errcode/errcode.py

+ 32
- 0
contrib/errcode/README View File

1
+Error Code Lookup for gPXE
2
+==========================
3
+This program looks up gPXE error codes so you can locate the line of source
4
+code which produced the error.
5
+
6
+Setup
7
+-----
8
+You must run:
9
+./build_errcodedb.py >errcodedb.py
10
+
11
+This extracts error code definitions from the gPXE source code and produces a
12
+"database" which is used by the main program.
13
+
14
+Once you have done this errcode.py and errcodedb.py are the only files you
15
+need.  They are now independent of the gPXE source code and can be moved
16
+anywhere.
17
+
18
+[OPTIONAL]
19
+A PHP script is provided as a web interface.  First edit errcode.php to point
20
+$ERRCODE_PATH to the errcode.py script.  Then move errcode.php to a location
21
+visible from your web server.
22
+
23
+Usage
24
+-----
25
+Looking up error codes on the command-line:
26
+./errcode.py 0x12345678
27
+
28
+Further information
29
+-------------------
30
+See http://etherboot.org/.
31
+
32
+Released under the GPL and written by Stefan Hajnoczi <stefanha@gmail.com>.

+ 33
- 5
contrib/errcode/build_errcodedb.py View File

1
 #!/usr/bin/env python
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.
2
 import sys
17
 import sys
3
 import re
18
 import re
4
 
19
 
15
     sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
30
     sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
16
     sys.exit(1)
31
     sys.exit(1)
17
 
32
 
33
+def to_pxenv_status(errno):
34
+    return errno & 0xff
35
+
36
+def to_errfile(errno):
37
+    return (errno >> 13) & 0x7ff
38
+
39
+def to_posix_errno(errno):
40
+    return (errno >> 24) & 0x7f
41
+
18
 def load_header_file(filename, regexp):
42
 def load_header_file(filename, regexp):
19
     defines = {}
43
     defines = {}
20
     for line in open(filename, 'r'):
44
     for line in open(filename, 'r'):
42
         err('invalid expression')
66
         err('invalid expression')
43
     return eval(pyexpr)
67
     return eval(pyexpr)
44
 
68
 
45
-def build(filenames, regexp):
69
+def build(filenames, regexp, selector):
46
     unevaluated = {}
70
     unevaluated = {}
47
     for filename in filenames:
71
     for filename in filenames:
48
         unevaluated.update(load_header_file(filename, regexp))
72
         unevaluated.update(load_header_file(filename, regexp))
59
                 changed = True
83
                 changed = True
60
     if unevaluated:
84
     if unevaluated:
61
         err('unable to evaluate all #defines')
85
         err('unable to evaluate all #defines')
62
-    return evaluated
63
 
86
 
64
-print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE))
65
-print 'errfile =', repr(build(errfile_files, ERRFILE_RE))
66
-print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE))
87
+    lookup = {}
88
+    for key, val in evaluated.iteritems():
89
+        lookup[selector(val)] = key
90
+    return lookup
91
+
92
+print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE, to_pxenv_status))
93
+print 'errfile =', repr(build(errfile_files, ERRFILE_RE, to_errfile))
94
+print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE, to_posix_errno))

+ 18
- 0
contrib/errcode/errcode.php View File

1
 <?
1
 <?
2
+/*
3
+ * Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License as
7
+ * published by the Free Software Foundation; either version 2 of the
8
+ * License, or any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful, but
11
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program; if not, write to the Free Software
17
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
+ */
19
+
2
 // The path to the errcode.py script.
20
 // The path to the errcode.py script.
3
 $ERRCODE_PATH = './errcode.py';
21
 $ERRCODE_PATH = './errcode.py';
4
 ?>
22
 ?>

+ 23
- 8
contrib/errcode/errcode.py View File

1
 #!/usr/bin/env python
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.
2
 import sys
17
 import sys
3
 
18
 
4
 try:
19
 try:
19
 def to_posix_errno(errno):
34
 def to_posix_errno(errno):
20
     return (errno >> 24) & 0x7f
35
     return (errno >> 24) & 0x7f
21
 
36
 
22
-def lookup_errno_component(defines, selector, component):
23
-    for key, val in defines.iteritems():
24
-        if selector(val) == component:
25
-            return key
26
-    return '0x%x' % component
37
+def lookup_errno_component(defines, component):
38
+    if component in defines:
39
+        return defines[component]
40
+    else:
41
+        return '0x%x' % component
27
 
42
 
28
 class Errno(object):
43
 class Errno(object):
29
     def __init__(self, errno):
44
     def __init__(self, errno):
37
 
52
 
38
     def prettystr(self):
53
     def prettystr(self):
39
         return 'pxenv_status=%s uniq=%d errfile=%s posix_errno=%s' % (
54
         return 'pxenv_status=%s uniq=%d errfile=%s posix_errno=%s' % (
40
-                lookup_errno_component(errcodedb.pxenv_status, to_pxenv_status, self.pxenv_status),
55
+                lookup_errno_component(errcodedb.pxenv_status, self.pxenv_status),
41
                 self.uniq,
56
                 self.uniq,
42
-                lookup_errno_component(errcodedb.errfile, to_errfile, self.errfile),
43
-                lookup_errno_component(errcodedb.posix_errno, to_posix_errno, self.posix_errno)
57
+                lookup_errno_component(errcodedb.errfile, self.errfile),
58
+                lookup_errno_component(errcodedb.posix_errno, self.posix_errno)
44
                 )
59
                 )
45
 
60
 
46
     def __str__(self):
61
     def __str__(self):

Loading…
Cancel
Save