3 # gen-javahl-errors.py: Generate a Java class containing an enum for the
6 # ====================================================================
7 # Copyright (c) 2007 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 # ====================================================================
25 except ImportError, e
:
26 print >> sys
.stderr
, \
27 "ERROR: Unable to import Subversion's Python bindings: '%s'\n" \
28 "Hint: Set your PYTHONPATH environment variable, or adjust your " \
29 "PYTHONSTARTUP\nfile to point to your Subversion install " \
30 "location's svn-python directory." % e
35 for key
in vars(core
):
36 if key
.find('SVN_ERR_') == 0:
38 val
= int(vars(core
)[key
])
44 def gen_javahl_class(error_codes
, output_filename
):
45 jfile
= open(output_filename
, 'w')
47 """/** ErrorCodes.java - This file is autogenerated by gen-javahl-errors.py
50 package org.tigris.subversion.javahl;
53 * Provide mappings from error codes generated by the C runtime to meaningful
54 * Java values. For a better description of each error, please see
55 * svn_error_codes.h in the C source.
57 public class ErrorCodes
61 keys
= error_codes
.keys()
65 # Format the code name to be more Java-esque
66 code_name
= error_codes
[key
][8:].replace('_', ' ').title().replace(' ', '')
67 code_name
= code_name
[0].lower() + code_name
[1:]
69 jfile
.write(" public static final int %s = %d;\n" % (code_name
, key
))
74 if __name__
== "__main__":
76 output_filename
= sys
.argv
[1]
78 output_filename
= os
.path
.join('..', '..', 'subversion', 'bindings',
79 'javahl', 'src', 'org', 'tigris',
80 'subversion', 'javahl', 'ErrorCodes.java')
82 gen_javahl_class(get_errors(), output_filename
)