3 # which-error.py: Print semantic Subversion error code names mapped from
4 # their numeric error code values
6 # ====================================================================
7 # Copyright (c) 2005 CollabNet. All rights reserved.
9 # * This software is licensed as described in the file COPYING, which
10 # you should have received as part of this distribution. The terms
11 # are also available at http://subversion.tigris.org/license-1.html.
12 # If newer versions of this license are posted there, you may use a
13 # newer version instead, at your option.
15 # * This software consists of voluntary contributions made by many
16 # individuals. For exact contribution history, see the revision
17 # history and logs, available at http://subversion.tigris.org/.
18 # ====================================================================
23 # $LastChangedRevision$
32 except ImportError, e
:
33 print >> sys
.stderr
, \
34 "ERROR: Unable to import Subversion's Python bindings: '%s'\n" \
35 "Hint: Set your PYTHONPATH environment variable, or adjust your " \
36 "PYTHONSTARTUP\nfile to point to your Subversion install " \
37 "location's svn-python directory." % e
42 progname
= os
.path
.basename(sys
.argv
[0])
43 sys
.stderr
.write("""Usage: 1. %s ERRNUM [...]
47 Print numeric and semantic error code information for Subversion error
48 codes. This can be done in variety of ways:
50 1. For each ERRNUM, list the error code information.
52 2. Parse standard input as if it was error stream from a debug-mode
53 Subversion command-line client, echoing that input to stdout,
54 followed by the error code information for codes found in use in
57 3. Simply list the error code information for all known such
60 """ % (progname
, progname
, progname
))
65 for key
in vars(core
):
66 if key
.find('SVN_ERR_') == 0:
68 val
= int(vars(core
)[key
])
74 def print_error(code
):
76 print '%08d %s' % (code
, __svn_error_codes
[code
])
78 print '%08d *** UNKNOWN ERROR CODE ***' % (code
)
80 if __name__
== "__main__":
81 global __svn_error_codes
82 __svn_error_codes
= get_errors()
87 # Get a list of known codes
88 if sys
.argv
[1] == 'list':
91 codes
= __svn_error_codes
.keys()
94 # Get a list of code by parsing stdin for apr_err=CODE instances
95 elif sys
.argv
[1] == 'parse':
99 line
= sys
.stdin
.readline()
102 sys
.stdout
.write(line
)
103 match
= re
.match(r
'^.*apr_err=([0-9]+)[^0-9].*$', line
)
105 codes
.append(int(match
.group(1)))
107 # Get the list of requested codes
109 for code
in sys
.argv
[1:]:
111 codes
.append(int(code
))
115 # Print the harvest codes