2015-03-24 00:36:39 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2015-09-04 15:34:05 +08:00
|
|
|
# this file runs on the download server (download.flightgear.org)
|
|
|
|
# from the Jenkins upload-via-ssh jobs. It ensures that only complete
|
|
|
|
# uploads are visible (and mirrored to SF).
|
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
import os, sys, re, fnmatch
|
|
|
|
from subprocess import call
|
|
|
|
|
2021-03-22 19:06:24 +08:00
|
|
|
suffixes = ['dmg']
|
|
|
|
|
2017-02-10 00:46:09 +08:00
|
|
|
release_version = "unknown"
|
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
if sys.argv[1] == 'windows':
|
2021-03-22 19:06:24 +08:00
|
|
|
suffixes = ['exe']
|
2015-08-31 15:39:30 +08:00
|
|
|
if sys.argv[1] == 'linux':
|
2021-03-22 19:06:24 +08:00
|
|
|
suffixes = ['tar.bz2', 'tar.xz', 'txz', 'AppImage']
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2017-02-10 00:46:09 +08:00
|
|
|
isRelease = False
|
2015-08-31 15:39:30 +08:00
|
|
|
if len(sys.argv) > 2 and sys.argv[2] == 'release':
|
2017-02-10 00:46:09 +08:00
|
|
|
isRelease = True
|
|
|
|
|
|
|
|
if len(sys.argv) > 3:
|
|
|
|
release_version = sys.argv[3]
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2021-03-22 19:06:24 +08:00
|
|
|
print "are we doing an RC:" + str(isRelease)
|
2020-08-24 18:38:55 +08:00
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
sourceForgeUserHost = "jmturner@frs.sourceforge.net"
|
|
|
|
sftpCommandFile = "sftp-commands"
|
2015-09-04 15:34:05 +08:00
|
|
|
symbolDir = "/home/jenkins/symbols"
|
2015-03-24 00:36:39 +08:00
|
|
|
|
2017-02-10 00:46:09 +08:00
|
|
|
if isRelease:
|
2021-03-22 19:06:24 +08:00
|
|
|
publicRoot = "/var/www/downloads/builds/rc"
|
2015-08-31 15:39:30 +08:00
|
|
|
incomingDir = "/home/jenkins/incoming"
|
2017-02-10 00:46:09 +08:00
|
|
|
sourceForgePath = "/home/frs/project/f/fl/flightgear/release-" + release_version + "/"
|
2015-08-31 15:39:30 +08:00
|
|
|
else:
|
2021-03-22 19:06:24 +08:00
|
|
|
publicRoot = "/var/www/downloads/builds/nightly"
|
2015-08-31 15:39:30 +08:00
|
|
|
incomingDir = "/home/jenkins/nightly-incoming"
|
|
|
|
sourceForgePath = "/home/frs/project/f/fl/flightgear/unstable/"
|
|
|
|
|
|
|
|
os.chdir(publicRoot)
|
2015-03-24 00:36:39 +08:00
|
|
|
|
2021-03-22 19:06:24 +08:00
|
|
|
def matchVersionWithSuffix(suffix, file):
|
|
|
|
pattern = r'\w+-(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)([\w-]*)\.' + suffix
|
|
|
|
m = re.match(pattern, file)
|
|
|
|
if (m is None):
|
|
|
|
return None
|
|
|
|
return (m.group('major'), m.group('minor'), m.group('patch'))
|
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
def findFileVersion(dir):
|
|
|
|
for file in os.listdir(dir):
|
2021-03-22 19:06:24 +08:00
|
|
|
for suffix in suffixes:
|
|
|
|
if file.endswith(suffix):
|
|
|
|
v = matchVersionWithSuffix(suffix, file)
|
|
|
|
if v:
|
|
|
|
return v
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
return None
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
incomingVer = findFileVersion(incomingDir)
|
|
|
|
if incomingVer is None:
|
2021-03-22 19:06:24 +08:00
|
|
|
print "No incoming files found matching suffixes:" + ', '.join(suffixes)
|
2015-03-24 00:36:39 +08:00
|
|
|
exit()
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
existingVer = findFileVersion('.')
|
|
|
|
|
|
|
|
# if files in dest location mis-match the version, archive them
|
|
|
|
# and re-create the symlinks
|
|
|
|
|
|
|
|
versionChange = (existingVer != incomingVer)
|
|
|
|
|
|
|
|
oldFiles = []
|
2015-08-31 15:39:30 +08:00
|
|
|
incomingFiles = []
|
2015-03-24 00:36:39 +08:00
|
|
|
newFiles = []
|
|
|
|
|
2021-03-22 19:06:24 +08:00
|
|
|
# remove all files matching a suffix in the current director
|
|
|
|
# record removed files (except symlinks) in global-var
|
|
|
|
# oldFiles, so we could also remove them from SourceForge
|
|
|
|
def removeFilesMatching(suffix):
|
|
|
|
for file in os.listdir('.'):
|
|
|
|
if not fnmatch.fnmatch(file, '*' + suffix):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not os.path.islink(file):
|
|
|
|
oldFiles.append(file)
|
|
|
|
os.remove(file)
|
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
if versionChange:
|
|
|
|
print "Version number changing"
|
2021-03-22 19:06:24 +08:00
|
|
|
for suffix in suffixes:
|
|
|
|
removeFilesMatching(suffix)
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2021-03-22 19:06:24 +08:00
|
|
|
if (sys.argv[1] == 'windows'):
|
|
|
|
removeFilesMatching('.pdb')
|
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
|
2021-03-22 19:06:24 +08:00
|
|
|
# collecting incoming files
|
2015-03-24 00:36:39 +08:00
|
|
|
for file in os.listdir(incomingDir):
|
2021-03-22 19:06:24 +08:00
|
|
|
for suffix in suffixes:
|
|
|
|
if file.endswith(suffix):
|
|
|
|
incomingFiles.append(file)
|
|
|
|
|
|
|
|
if (sys.argv[1] == 'windows') and fnmatch.fnmatch(file, "*.pdb"):
|
|
|
|
# manually copy PDBs, don't add to incoming files
|
|
|
|
srcFile = os.path.join(incomingDir, file)
|
|
|
|
os.rename(srcFile, file)
|
|
|
|
newFiles.append(file)
|
|
|
|
|
|
|
|
print "Incoming files:" + ', '.join(incomingFiles)
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
# copy and symlink
|
2015-08-31 15:39:30 +08:00
|
|
|
for file in incomingFiles:
|
2015-03-24 00:36:39 +08:00
|
|
|
# move it to the public location
|
|
|
|
srcFile = os.path.join(incomingDir, file)
|
2015-08-31 15:39:30 +08:00
|
|
|
|
|
|
|
outFile = file
|
2021-03-22 19:06:24 +08:00
|
|
|
# insert -rc before file extension
|
|
|
|
if isRelease:
|
|
|
|
m = re.match(r'(\w+-\d+\.\d+\.\d+[\w-]*)\.(.*)', file)
|
|
|
|
outFile = m.group(1) + '-rc.' + m.group(2)
|
|
|
|
print "RC out name is " + outFile
|
2015-08-31 15:39:30 +08:00
|
|
|
|
|
|
|
os.rename(srcFile, outFile)
|
|
|
|
newFiles.append(outFile)
|
|
|
|
|
2017-02-10 00:46:09 +08:00
|
|
|
if not isRelease:
|
2015-08-31 15:39:30 +08:00
|
|
|
# symlink for stable web URL
|
2021-03-22 19:06:24 +08:00
|
|
|
m = re.match(r'(\w+)-\d+\.\d+\.\d+(-[\w-]+)?\.(.*)' , file)
|
|
|
|
|
|
|
|
if m.group(2):
|
|
|
|
latestName = m.group(1) + '-latest' + m.group(2) + '.' + m.group(3)
|
|
|
|
else:
|
|
|
|
latestName = m.group(1) + '-latest.' + m.group(3)
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2015-09-02 18:26:39 +08:00
|
|
|
print "Creating symlink from " + file + " to " + latestName
|
2015-08-31 15:39:30 +08:00
|
|
|
if os.path.exists(latestName):
|
2015-09-02 18:26:39 +08:00
|
|
|
print "\tremoving existing target"
|
2015-08-31 15:39:30 +08:00
|
|
|
os.remove(latestName)
|
|
|
|
os.symlink(file, latestName)
|
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
# remove files from SF
|
2017-02-10 00:46:09 +08:00
|
|
|
#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)
|
2015-08-31 15:39:30 +08:00
|
|
|
|
2015-03-24 00:36:39 +08:00
|
|
|
# upload to SourceForge
|
2021-03-22 19:06:24 +08:00
|
|
|
# for file in newFiles:
|
|
|
|
# print "Uploading " + file + " to SourceForge"
|
|
|
|
# print "Skipped until SF FRS is fixed"
|
|
|
|
# # sys.stdout.flush()
|
|
|
|
# # call(["scp", "-v", file, sourceForgeUserHost + ":" + sourceForgePath + file])
|
|
|
|
# # call(["rsync", "-e", "ssh", file, sourceForgeUserHost + ":" + sourceForgePath + file])
|
|
|
|
# # print "...Done"
|
|
|
|
# sys.stdout.flush()
|
2015-09-04 15:34:05 +08:00
|
|
|
|