uploadrelease.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/python -u
  2. '''
  3. ADOdb release upload script
  4. '''
  5. import getopt
  6. import glob
  7. import os
  8. from os import path
  9. import subprocess
  10. import sys
  11. # Directories and files to exclude from release tarballs
  12. sf_files = "frs.sourceforge.net:/home/frs/project/adodb" \
  13. "/adodb-php5-only/adodb-{ver}-for-php5/"
  14. sf_doc = "web.sourceforge.net:/home/project-web/adodb/htdocs/"
  15. rsync_cmd = "rsync -vP --rsh ssh {opt} {src} {usr}@{dst}"
  16. # Command-line options
  17. options = "hfd"
  18. long_options = ["help", "files", "doc"]
  19. def usage():
  20. print '''Usage: %s [options] username [release_path]
  21. This script will upload the files in the given directory (or the
  22. current one if unspecified) to Sourceforge.
  23. Parameters:
  24. username Sourceforge user account
  25. release_path Location of the release files to upload
  26. (see buildrelease.py)
  27. Options:
  28. -h | --help Show this usage message
  29. -f | --files Upload release files only
  30. -d | --doc Upload documentation only
  31. ''' % (
  32. path.basename(__file__)
  33. )
  34. #end usage()
  35. def main():
  36. # Get command-line options
  37. try:
  38. opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options)
  39. except getopt.GetoptError, err:
  40. print str(err)
  41. usage()
  42. sys.exit(2)
  43. if len(args) < 1:
  44. usage()
  45. print "ERROR: please specify the Sourceforge user and release_path"
  46. sys.exit(1)
  47. upload_files = True
  48. upload_doc = True
  49. for opt, val in opts:
  50. if opt in ("-h", "--help"):
  51. usage()
  52. sys.exit(0)
  53. elif opt in ("-f", "--files"):
  54. upload_files = False
  55. elif opt in ("-d", "--doc"):
  56. upload_doc = False
  57. # Mandatory parameters
  58. username = args[0]
  59. try:
  60. release_path = args[1]
  61. os.chdir(release_path)
  62. except IndexError:
  63. release_path = os.getcwd()
  64. # Get the version number from the zip file to upload
  65. try:
  66. zipfile = glob.glob('*.zip')[0]
  67. except IndexError:
  68. print "ERROR: release zip file not found in '%s' " % release_path
  69. sys.exit(1)
  70. version = zipfile[5:8]
  71. # Start upload process
  72. print "ADOdb release upload script"
  73. # Upload release files
  74. if upload_files:
  75. target = sf_files.format(ver=version)
  76. print
  77. print "Uploading release files..."
  78. print " Target: " + target
  79. print
  80. subprocess.call(
  81. rsync_cmd.format(
  82. usr=username,
  83. opt="--exclude=docs",
  84. src=path.join(release_path, "*"),
  85. dst=target
  86. ),
  87. shell=True
  88. )
  89. # Upload documentation
  90. if upload_doc:
  91. print
  92. print "Uploading documentation..."
  93. print
  94. subprocess.call(
  95. rsync_cmd.format(
  96. usr=username,
  97. opt="",
  98. src=path.join(release_path, "docs", "*"),
  99. dst=sf_doc
  100. ),
  101. shell=True
  102. )
  103. #end main()
  104. if __name__ == "__main__":
  105. main()