Add http errors
[platform/core/api/common.git] / tool / make_msg_header.py
1 #python xml library import 
2 from xml.etree.ElementTree import parse
3 import os
4 import sys
5 import shutil
6
7 curpath = os.path.dirname( os.path.abspath( __file__ ) )
8 msgpath = os.path.join( curpath, "../error_messages/" )
9 headerpath = os.path.join( curpath, "tizen_error_private.h" )
10
11 shutil.copy( os.path.join( curpath, "tizen_error_private_template.h" ), headerpath )
12 fp = open( headerpath, 'a' )
13
14 fp.write( "\n#ifndef __TIZEN_COMMON_ERROR_PRIVATE_H__\n" )
15 fp.write( "#define __TIZEN_COMMON_ERROR_PRIVATE_H__\n\n" )
16
17 fp.write( "#ifdef __cplusplus\n" )
18 fp.write( "extern \"C\" {\n" )
19 fp.write( "#endif\n\n" )
20
21 fp.write( "#define ERR_ENTRY(name, value, msg) {value, name, msg}\n\n" )
22 fp.write( "typedef struct tizen_err_info {\n" )
23 fp.write( "\tint value;\n" )
24 fp.write( "\tconst char *name;\n" )
25 fp.write( "\tconst char *msg;\n" )
26 fp.write( "} err_info;\n\n" )
27
28 fp.write( "static err_info err_list[] = {\n" );
29 for root, dirs, files in os.walk( msgpath ):
30         for file in files:
31                 print ">>>> " + file
32                 targetXML = open( os.path.join( msgpath, file ) )
33                 tree = parse( targetXML )
34                 errorroot = tree.getroot()              
35
36                 for error in errorroot.findall( "error" ):
37                         fp.write( "\tERR_ENTRY(\"" )
38                         fp.write( error.get( "name" ) + "\", ")
39                         fp.write( error.findtext( "value" ) + ", \"" )
40                         fp.write( error.findtext( "msg" ) + "\"),\n" )
41                         print error.get( "name" )
42
43 fp.write( "\t{0, NULL, NULL}\n" )
44 fp.write( "};\n" )
45
46 fp.write( "\n#ifdef __cplusplus\n" )
47 fp.write( "}\n" )
48 fp.write( "#endif\n\n" )
49 fp.write( "#endif\t/**<__TIZEN_COMMON_ERROR_PRIVATE_H__ */\n" )
50 fp.close()
51
52 privatepath = os.path.join( curpath, "../include/private/" )
53 if not os.path.isdir( privatepath ):
54         os.mkdir( privatepath )
55
56 # os.remove( privatepath + "tizen_error_private.h" )
57 # shutil.move( headerpath, privatepath )