2
0

make-panda3d-tgz.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env python
  2. """This script generates the panda3d-date.tar.gz tarball for a file
  3. release of panda3d onto the SourceForge download site.
  4. Options:
  5. -d cvsroot
  6. Specifies the CVSROOT string to use to tag and export the
  7. tree. The default is $SFROOT if it is defined, or $CVSROOT
  8. otherwise.
  9. -r tag
  10. Specifies the tag to export from. If this parameter is
  11. specified, the tree is not tagged again; otherwise, the
  12. current head of the CVS tree is tagged with the file version
  13. name.
  14. -m module
  15. Specifies the module to check out and build. The default is
  16. panda3d.
  17. """
  18. import sys
  19. import os
  20. import os.path
  21. import getopt
  22. import time
  23. import glob
  24. import shutil
  25. CVSROOT = os.getenv('SFROOT') or os.getenv('CVSROOT')
  26. ORIGTAG = ''
  27. MODULE = 'panda3d'
  28. def usage(code, msg = ''):
  29. print >> sys.stderr, __doc__
  30. print >> sys.stderr, msg
  31. sys.exit(code)
  32. try:
  33. opts, args = getopt.getopt(sys.argv[1:], 'd:r:m:h')
  34. except getopt.error, msg:
  35. usage(1, msg)
  36. for opt, arg in opts:
  37. if opt == '-d':
  38. CVSROOT = arg
  39. elif opt == '-r':
  40. ORIGTAG = arg
  41. elif opt == '-m':
  42. MODULE = arg
  43. elif opt == '-h':
  44. usage(0)
  45. if not CVSROOT:
  46. usage(1, 'CVSROOT must have a value.')
  47. if not MODULE:
  48. usage(1, 'MODULE must have a value.')
  49. basename = MODULE + '-' + time.strftime("%Y-%m-%d")
  50. tarfile = basename + '.tar.gz'
  51. zipfile = basename + '.zip'
  52. if os.path.exists(basename):
  53. print basename, 'already exists in the local directory!'
  54. sys.exit(1)
  55. if not ORIGTAG:
  56. # If we weren't given a starting tag, make one.
  57. tag = basename
  58. print 'Tagging sources.'
  59. cmd = 'cvs -f -d "%s" rtag -F -r HEAD "%s" "%s"' % (CVSROOT, tag, MODULE)
  60. if os.system(cmd) != 0:
  61. sys.exit(1)
  62. else:
  63. # Otherwise, we were given a starting tag, so use it.
  64. tag = ORIGTAG
  65. print 'Checking out "%s" as "%s".' % (MODULE, basename)
  66. cmd = 'cvs -z3 -f -d "%s" export -r "%s" -d "%s" "%s"' % (CVSROOT, tag,
  67. basename, MODULE)
  68. if os.system(cmd) != 0:
  69. sys.exit(1)
  70. # Move the contents of the doc module into the root directory where people
  71. # will expect to see it.
  72. docdir = basename + os.sep + 'doc'
  73. if os.path.exists(docdir):
  74. files = glob.glob(docdir + os.sep + '*')
  75. for file in files:
  76. shutil.copy(file, basename)
  77. os.remove(file)
  78. os.rmdir(docdir)
  79. # Generate the autoconf scripts for ppremake.
  80. if MODULE == 'ppremake':
  81. ppremakedir = basename
  82. else:
  83. ppremakedir = basename + os.sep + 'ppremake'
  84. if os.path.exists(ppremakedir):
  85. cmd = 'cd "./%s" && aclocal && autoheader && automake --foreign -a && autoconf' % (ppremakedir)
  86. if os.system(cmd) != 0:
  87. sys.exit(1)
  88. # Generate the tarball.
  89. print 'Generating %s' % (tarfile)
  90. if os.path.exists(tarfile):
  91. os.remove(tarfile)
  92. cmd = 'tar cf - "%s" | gzip -9 > "%s"' % (basename, tarfile)
  93. if os.system(cmd) != 0:
  94. sys.exit(1)
  95. # Also generate a zip file.
  96. print 'Generating %s' % (zipfile)
  97. if os.path.exists(zipfile):
  98. os.remove(zipfile)
  99. cmd = 'zip -9rq "%s" "%s"' % (zipfile, basename)
  100. if os.system(cmd) != 0:
  101. sys.exit(1)
  102. shutil.rmtree(basename)