tinyxml2

FORK: TinyXML2 is a simple, small, efficient, C++ XML parser that can be easily integrated into other programs.
git clone https://git.neptards.moe/neptards/tinyxml2.git
Log | Files | Refs

setversion.py (3731B)


      1 # Python program to set the version.
      2 ##############################################
      3 
      4 import re
      5 import sys
      6 import optparse
      7 
      8 def fileProcess( name, lineFunction ):
      9 	filestream = open( name, 'r' )
     10 	if filestream.closed:
     11 		print( "file " + name + " not open." )
     12 		return
     13 
     14 	output = ""
     15 	print( "--- Processing " + name + " ---------" )
     16 	while 1:
     17 		line = filestream.readline()
     18 		if not line: break
     19 		output += lineFunction( line )
     20 	filestream.close()
     21 	
     22 	if not output: return			# basic error checking
     23 	
     24 	print( "Writing file " + name )
     25 	filestream = open( name, "w" );
     26 	filestream.write( output );
     27 	filestream.close()
     28 	
     29 def echoInput( line ):
     30 	return line
     31 
     32 parser = optparse.OptionParser( "usage: %prog major minor build" )
     33 (options, args) = parser.parse_args()
     34 if len(args) != 3:
     35 	parser.error( "incorrect number of arguments" );
     36 
     37 major = args[0]
     38 minor = args[1]
     39 build = args[2]
     40 versionStr = major + "." + minor + "." + build
     41 
     42 print ("Setting dox,tinyxml2.h")
     43 print ("Version: " + major + "." + minor + "." + build)
     44 
     45 #### Write the tinyxml.h ####
     46 
     47 def engineRule( line ):
     48 
     49 	matchMajor = "static const int TIXML2_MAJOR_VERSION"
     50 	matchMinor = "static const int TIXML2_MINOR_VERSION"
     51 	matchBuild = "static const int TIXML2_PATCH_VERSION"
     52 
     53 	if line[0:len(matchMajor)] == matchMajor:
     54 		print( "1)tinyxml2.h Major found" )
     55 		return matchMajor + " = " + major + ";\n"
     56 
     57 	elif line[0:len(matchMinor)] == matchMinor:
     58 		print( "2)tinyxml2.h Minor found" )
     59 		return matchMinor + " = " + minor + ";\n"
     60 
     61 	elif line[0:len(matchBuild)] == matchBuild:
     62 		print( "3)tinyxml2.h Build found" )
     63 		return matchBuild + " = " + build + ";\n"
     64 
     65 	else:
     66 		return line;
     67 
     68 fileProcess( "tinyxml2.h", engineRule )
     69 
     70 def macroVersionRule( line ):
     71 
     72 	matchMajor = "#define TINYXML2_MAJOR_VERSION"
     73 	matchMinor = "#define TINYXML2_MINOR_VERSION"
     74 	matchBuild = "#define TINYXML2_PATCH_VERSION"
     75 
     76 	if line[0:len(matchMajor)] == matchMajor:
     77 		print( "1)macro Major found" )
     78 		return matchMajor + " " + major + "\n"
     79 
     80 	elif line[0:len(matchMinor)] == matchMinor:
     81 		print( "2)macro Minor found" )
     82 		return matchMinor + " " + minor + "\n"
     83 
     84 	elif line[0:len(matchBuild)] == matchBuild:
     85 		print( "3)macro Build found" )
     86 		return matchBuild + " " + build + "\n"
     87 
     88 	else:
     89 		return line;
     90 
     91 fileProcess("tinyxml2.h", macroVersionRule)
     92 
     93 #### Write the dox ####
     94 
     95 def doxRule( line ):
     96 
     97 	match = "PROJECT_NUMBER"
     98 
     99 	if line[0:len( match )] == match:
    100 		print( "dox project found" )
    101 		return "PROJECT_NUMBER = " + major + "." + minor + "." + build + "\n"
    102 
    103 	else:
    104 		return line;
    105 
    106 fileProcess( "dox", doxRule )
    107 
    108 
    109 #### Write the CMakeLists.txt ####
    110 
    111 def cmakeRule1( line ):
    112 
    113 	matchVersion = "set(GENERIC_LIB_VERSION"
    114 
    115 	if line[0:len(matchVersion)] == matchVersion:
    116 		print( "1)tinyxml2.h Major found" )
    117 		return matchVersion + " \"" + major + "." + minor + "." + build + "\")" + "\n"
    118 
    119 	else:
    120 		return line;
    121 
    122 fileProcess( "CMakeLists.txt", cmakeRule1 )
    123 
    124 def cmakeRule2( line ):
    125 
    126 	matchSoversion = "set(GENERIC_LIB_SOVERSION"
    127 
    128 	if line[0:len(matchSoversion)] == matchSoversion:
    129 		print( "1)tinyxml2.h Major found" )
    130 		return matchSoversion + " \"" + major + "\")" + "\n"
    131 
    132 	else:
    133 		return line;
    134 
    135 fileProcess( "CMakeLists.txt", cmakeRule2 )
    136 
    137 print( "Release note:" )
    138 print( '1. Build.   g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe' )
    139 print( '2. Commit.  git commit -am"setting the version to ' + versionStr + '"' )
    140 print( '3. Tag.     git tag ' + versionStr )
    141 print( '   OR       git tag -a ' + versionStr + ' -m [tag message]' )
    142 print( 'Remember to "git push" both code and tag. For the tag:' )
    143 print( 'git push origin [tagname]')
    144 
    145