setversion.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Python program to set the version.
  2. ##############################################
  3. import re
  4. import sys
  5. def fileProcess( name, lineFunction ):
  6. filestream = open( name, 'r' )
  7. if filestream.closed:
  8. print( "file " + name + " not open." )
  9. return
  10. output = ""
  11. print( "--- Processing " + name + " ---------" )
  12. while 1:
  13. line = filestream.readline()
  14. if not line: break
  15. output += lineFunction( line )
  16. filestream.close()
  17. if not output: return # basic error checking
  18. print( "Writing file " + name )
  19. filestream = open( name, "w" );
  20. filestream.write( output );
  21. filestream.close()
  22. def echoInput( line ):
  23. return line
  24. major = input( "Major: " )
  25. minor = input( "Minor: " )
  26. build = input( "Build: " )
  27. print "Setting dox,tinyxml2.h"
  28. print "Version: " + `major` + "." + `minor` + "." + `build`
  29. #### Write the tinyxml.h ####
  30. def engineRule( line ):
  31. matchMajor = "static const int TIXML2_MAJOR_VERSION"
  32. matchMinor = "static const int TIXML2_MINOR_VERSION"
  33. matchBuild = "static const int TIXML2_PATCH_VERSION"
  34. if line[0:len(matchMajor)] == matchMajor:
  35. print "1)tinyxml2.h Major found"
  36. return matchMajor + " = " + `major` + ";\n"
  37. elif line[0:len(matchMinor)] == matchMinor:
  38. print "2)tinyxml2.h Minor found"
  39. return matchMinor + " = " + `minor` + ";\n"
  40. elif line[0:len(matchBuild)] == matchBuild:
  41. print "3)tinyxml2.h Build found"
  42. return matchBuild + " = " + `build` + ";\n"
  43. else:
  44. return line;
  45. fileProcess( "tinyxml2.h", engineRule )
  46. #### Write the dox ####
  47. def doxRule( line ):
  48. match = "PROJECT_NUMBER"
  49. if line[0:len( match )] == match:
  50. print "dox project found"
  51. return "PROJECT_NUMBER = " + `major` + "." + `minor` + "." + `build` + "\n"
  52. else:
  53. return line;
  54. fileProcess( "dox", doxRule )
  55. #### Write the CMakeLists.txt ####
  56. def cmakeRule1( line ):
  57. matchVersion = "set(GENERIC_LIB_VERSION"
  58. if line[0:len(matchVersion)] == matchVersion:
  59. print "1)tinyxml2.h Major found"
  60. return matchVersion + " \"" + `major` + "." + `minor` + "." + `build` + "\")" + "\n"
  61. else:
  62. return line;
  63. fileProcess( "CMakeLists.txt", cmakeRule1 )
  64. def cmakeRule2( line ):
  65. matchSoversion = "set(GENERIC_LIB_SOVERSION"
  66. if line[0:len(matchSoversion)] == matchSoversion:
  67. print "1)tinyxml2.h Major found"
  68. return matchSoversion + " \"" + `major` + "\")" + "\n"
  69. else:
  70. return line;
  71. fileProcess( "CMakeLists.txt", cmakeRule2 )