Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / tools / dev / gen-javahl-errors.py
blob0f0ae14e07acb917c845a3fd0f9ee1d21dcf6c0d
1 #!/usr/bin/env python
3 # gen-javahl-errors.py: Generate a Java class containing an enum for the
4 # C error codes
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 # ====================================================================
21 import sys, os
23 try:
24 from svn import core
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
31 sys.exit(1)
33 def get_errors():
34 errs = {}
35 for key in vars(core):
36 if key.find('SVN_ERR_') == 0:
37 try:
38 val = int(vars(core)[key])
39 errs[val] = key
40 except:
41 pass
42 return errs
44 def gen_javahl_class(error_codes, output_filename):
45 jfile = open(output_filename, 'w')
46 jfile.write(
47 """/** ErrorCodes.java - This file is autogenerated by gen-javahl-errors.py
50 package org.tigris.subversion.javahl;
52 /**
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
59 """)
61 keys = error_codes.keys()
62 keys.sort()
64 for key in 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))
71 jfile.write("}\n")
72 jfile.close()
74 if __name__ == "__main__":
75 if len(sys.argv) > 1:
76 output_filename = sys.argv[1]
77 else:
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)