diff options
| -rwxr-xr-x | scripts/uploadrelease.py | 158 |
1 files changed, 115 insertions, 43 deletions
diff --git a/scripts/uploadrelease.py b/scripts/uploadrelease.py index 7fb4a08e..04e13ed9 100755 --- a/scripts/uploadrelease.py +++ b/scripts/uploadrelease.py @@ -3,23 +3,24 @@ ADOdb release upload script ''' +from distutils.version import LooseVersion import getopt import glob import os from os import path +import re import subprocess import sys # Directories and files to exclude from release tarballs -sf_files = "frs.sourceforge.net:/home/frs/project/adodb" \ - "/adodb-php5-only/adodb-{ver}-for-php5/" +sf_files = "frs.sourceforge.net:/home/frs/project/adodb/" sf_doc = "web.sourceforge.net:/home/project-web/adodb/htdocs/" rsync_cmd = "rsync -vP --rsh ssh {opt} {src} {usr}@{dst}" # Command-line options -options = "hfd" -long_options = ["help", "files", "doc"] +options = "hfdn" +long_options = ["help", "files", "doc", "dry-run"] def usage(): @@ -37,13 +38,75 @@ def usage(): -h | --help Show this usage message -f | --files Upload release files only -d | --doc Upload documentation only + -n | --dry-run Do not upload the files ''' % ( path.basename(__file__) ) #end usage() -def main(): +def call_rsync(usr, opt, src, dst): + ''' Calls rsync to upload files with given parameters + usr = ssh username + opt = options + src = source directory + dst = target directory + ''' + global dry_run + + command = rsync_cmd.format(usr=usr, opt=opt, src=src, dst=dst) + + if dry_run: + print command + else: + subprocess.call(command, shell=True) + + +def get_release_version(): + ''' Get the version number from the zip file to upload + ''' + try: + zipfile = glob.glob('adodb-*.zip')[0] + except IndexError: + print "ERROR: release zip file not found in '%s'" % release_path + sys.exit(1) + + try: + version = re.search( + "^adodb-([\d]+\.[\d]+\.[\d]+)\.zip$", + zipfile + ).group(1) + except AttributeError: + print "ERROR: unable to extract version number from '%s'" % zipfile + print " Only 3 groups of digits separated by periods are allowed" + sys.exit(1) + + return version + + +def sourceforge_target_dir(version): + ''' Returns the sourceforge target directory + Base directory as defined in sf_files global variable, plus + - if version >= 5.21: adodb-X.Y + - for older versions: adodb-XYZ-for-php5 + ''' + # Keep only X.Y (discard patch number) + short_version = version.rsplit('.', 1)[0] + + directory = 'adodb-php5-only/' + if LooseVersion(version) >= LooseVersion('5.21'): + directory += "adodb-" + short_version + else: + directory += "adodb-{}-for-php5".format(short_version.replace('.', '')) + + return directory + + +def process_command_line(): + ''' Retrieve command-line options and set global variables accordingly + ''' + global upload_files, upload_doc, dry_run, username, release_path + # Get command-line options try: opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options) @@ -57,8 +120,10 @@ def main(): print "ERROR: please specify the Sourceforge user and release_path" sys.exit(1) + # Default values for flags upload_files = True upload_doc = True + dry_run = False for opt, val in opts: if opt in ("-h", "--help"): @@ -71,57 +136,64 @@ def main(): elif opt in ("-d", "--doc"): upload_files = False + elif opt in ("-n", "--dry-run"): + dry_run = True + # Mandatory parameters username = args[0] + # Change to release directory, current if not specified try: release_path = args[1] os.chdir(release_path) except IndexError: release_path = os.getcwd() - # Upload release files - if upload_files: - # Get the version number from the zip file to upload - try: - zipfile = glob.glob('*.zip')[0] - except IndexError: - print "ERROR: release zip file not found in '%s'" % release_path - sys.exit(1) - version = zipfile[5:8] - # Start upload process - print "ADOdb release upload script" +def upload_release_files(): + ''' Upload release files from source directory to SourceForge + ''' + version = get_release_version() + target = sf_files + sourceforge_target_dir(version) + + print + print "Uploading release files..." + print " Source:", release_path + print " Target: " + target + print + call_rsync( + username, + "--exclude=docs", + path.join(release_path, "*"), + target + ) + - target = sf_files.format(ver=version) - print - print "Uploading release files..." - print " Target: " + target - print - subprocess.call( - rsync_cmd.format( - usr=username, - opt="--exclude=docs", - src=path.join(release_path, "*"), - dst=target - ), - shell=True - ) +def upload_documentation(): + ''' Upload documentation to Sourceforge web site + ''' + print + print "Uploading documentation..." + print + call_rsync( + username, + "", + path.join(release_path, "docs", "*"), + sf_doc + ) + + +def main(): + process_command_line() + + # Start upload process + print "ADOdb release upload script" + + if upload_files: + upload_release_files() - # Upload documentation if upload_doc: - print - print "Uploading documentation..." - print - subprocess.call( - rsync_cmd.format( - usr=username, - opt="", - src=path.join(release_path, "docs", "*"), - dst=sf_doc - ), - shell=True - ) + upload_documentation() #end main() |
