diff --git a/mac_upload_post.sh b/mac_upload_post.sh deleted file mode 100755 index 1aae1e0..0000000 --- a/mac_upload_post.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -if [ $# -lt 1 ]; then - echo "Must supply FlightGear version as an argument, eg 3.5.2" - exit -fi - -FG_VERSION = $1 -SF_FRS_PATH = "jmturner@frs.sourceforge.net:/home/frs/project/f/fl/flightgear/unstable/" - -echo "Running Mac upload post-processing steps" - -cd /var/www/html/builds/nightly - -# first, remove any existing DMG binaries -rm FlightGear-*.dmg - -# move newly upload files -mv $HOME/nightly-incoming/FlightGear-$FG_VERSION-nightly.dmg . -mv $HOME/nightly-incoming/FlightGear-$FG_VERSION-nightly-full.dmg . - -# rsync to SourceForge -rsync -avP -e ssh FlightGear-$FG_VERSION-nightly.dmg $SF_FRS_PATH -rsync -avP -e ssh FlightGear-$FG_VERSION-nightly-full.dmg $SF_FRS_PATH - diff --git a/post_upload.py b/post_upload.py new file mode 100644 index 0000000..73239d2 --- /dev/null +++ b/post_upload.py @@ -0,0 +1,92 @@ +#!/usr/bin/python + +import os, sys, re, fnmatch +from subprocess import call + +suffix = '.dmg' +if sys.argv[1] == 'windows': + suffix = '.exe' + +allSuffix = '*' + suffix + +print "Wildcard pattern is:" + allSuffix + +pattern = r'FlightGear-(?P\d+)\.(?P\d+)\.(?P\d+)-([\w-]+)' + suffix +publicNightlyRoot = "/var/www/html/builds/nightly" +incomingDir = "/home/jenkins/nightly-incoming" +sourceForgePath = "/home/frs/project/f/fl/flightgear/unstable/" +sourceForgeUserHost = "jmturner@frs.sourceforge.net" +sftpCommandFile = "sftp-commands" + +os.chdir(publicNightlyRoot) + +def findFileVersion(dir): + for file in os.listdir(dir): + if fnmatch.fnmatch(file, allSuffix): + m = re.match(pattern, file) + if (m is not None): + return (m.group('major'), m.group('minor'), m.group('patch')) + + return None + +incomingVer = findFileVersion(incomingDir) +if incomingVer is None: + print "No incoming files found matching " + allSuffix + exit() + +existingVer = findFileVersion('.') + +# if files in dest location mis-match the version, archive them +# and re-create the symlinks + +versionChange = (existingVer != incomingVer) + +oldFiles = [] +newFiles = [] + +if versionChange: + print "Version number changing" + + for file in os.listdir('.'): + if fnmatch.fnmatch(file, allSuffix): + if not os.path.islink(file): + oldFiles.append(file) + os.remove(file) + +for file in os.listdir(incomingDir): + if fnmatch.fnmatch(file, allSuffix): + newFiles.append(file) + +# copy and symlink +for file in newFiles: + # move it to the public location + srcFile = os.path.join(incomingDir, file) + os.rename(srcFile, file) + + # symlink for stable web URL + m = re.match(r'FlightGear-\d+\.\d+\.\d+-([\w-]+)' + suffix, file) + latestName = 'FlightGear-latest-' + m.group(1) + suffix + + if os.path.exists(latestName): + os.remove(latestName) + os.symlink(file, latestName) + +# remove files from SF +if len(oldFiles) > 0: + f = open(sftpCommandFile, 'w') + f.write("cd " + sourceForgePath + '\n') + for file in oldFiles: + print "Removing file " + file + " from SourceForge" + f.write("rm " + file + '\n') + f.write("bye\n") + f.close() + + call(["sftp", "-b", sftpCommandFile, sourceForgeUserHost]) + os.remove(sftpCommandFile) + +# upload to SourceForge +for file in newFiles: + print "Uploading " + file + " to SourceForge" + call(["scp", file, sourceForgeUserHost + ":" + sourceForgePath + file]) + + \ No newline at end of file