dsdb:schema: use NUMERIC_CMP in place of uint32_cmp
[Samba.git] / source4 / scripting / bin / gen_error_common.py
blob390d1d701b611fdaba4e433933ecd75808da54c7
1 #!/usr/bin/env python3
4 # Unix SMB/CIFS implementation.
6 # Utility methods for generating error codes from a file.
8 # Copyright (C) Noel Power <noel.power@suse.com> 2014
9 # Copyright (C) Catalyst IT Ltd. 2017
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # error data model
26 class ErrorDef:
27 def __init__(self):
28 self.err_code = None
29 self.err_define = None
30 self.err_string = ""
31 self.isWinError = False
32 self.linenum = None
34 def escapeString( input ):
35 output = input.replace('"','\\"')
36 output = output.replace("\\<","\\\\<")
37 output = output.replace('\t',"")
38 return output
40 # Parse error descriptions from a file which is the content
41 # of an HTML table.
42 # The file must be formatted as:
43 # [error code hex]
44 # [error name short]
45 # [error description]
46 # Blank lines are allowed and errors do not have to have a
47 # description.
48 # Returns a list of ErrorDef objects.
49 def parseErrorDescriptions( file_contents, isWinError, transformErrorFunction ):
50 errors = []
51 count = 0
52 for line in file_contents:
53 if line is None or line == '\t' or line == "" or line == '\n':
54 continue
55 content = line.strip().split(None,1)
56 # start new error definition ?
57 if len(content) == 0:
58 continue
59 if line.startswith("0x"):
60 newError = ErrorDef()
61 newError.err_code = int(content[0],0)
62 # escape the usual suspects
63 if len(content) > 1:
64 newError.err_string = escapeString(content[1])
65 newError.linenum = count
66 newError.isWinError = isWinError
67 errors.append(newError)
68 else:
69 if len(errors) == 0:
70 continue
71 err = errors[-1]
72 if err.err_define is None:
73 err.err_define = transformErrorFunction(content[0])
74 else:
75 if len(content) > 0:
76 desc = escapeString(line.strip())
77 if len(desc):
78 if err.err_string == "":
79 err.err_string = desc
80 else:
81 err.err_string = err.err_string + " " + desc
82 count = count + 1
83 print("parsed %d lines generated %d error definitions"%(count,len(errors)))
84 return errors