From 91d05c29dbcaa120a63390b10909775be8a25c5d Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 25 May 2015 16:05:16 +0100 Subject: [PATCH] Upload 'ns' to plugins dir (create if not exists) #4695 --- ext/toolchain/commands1.py | 10 ++-------- ext/toolchain/ftputil.py | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ext/toolchain/commands1.py b/ext/toolchain/commands1.py index feaa9f06..601f04eb 100644 --- a/ext/toolchain/commands1.py +++ b/ext/toolchain/commands1.py @@ -1343,12 +1343,6 @@ class InternalCommands: return major + '.' + minor + '.' + rev - def ftpUpload(self, ftp, source, target): - print "Uploading '%s' as '%s' to FTP server '%s'..." % ( - source, target, ftp.host) - ftp.run(source, target) - print 'Done' - def distftp(self, type, ftp): if not type: raise Exception('Platform type not specified.') @@ -1359,13 +1353,13 @@ class InternalCommands: packageSource = binDir + '/' + self.dist_name(type) packageTarget = self.dist_name_rev(type) - self.ftpUpload(ftp, packageSource, packageTarget) + ftp.upload(packageSource, packageTarget) if (type != 'src'): pluginsDir = binDir + '/plugins' nsPluginSource = self.findLibraryFile(type, pluginsDir, 'ns') nsPluginTarget = self.getLibraryDistFilename(type, pluginsDir, 'ns') - self.ftpUpload(ftp, nsPluginSource, nsPluginTarget) + ftp.upload(nsPluginSource, nsPluginTarget, "plugins") def getLibraryDistFilename(self, type, dir, name): (platform, packageExt, libraryExt) = self.getDistributePlatformInfo(type) diff --git a/ext/toolchain/ftputil.py b/ext/toolchain/ftputil.py index 3cc8c9fe..aef8363e 100644 --- a/ext/toolchain/ftputil.py +++ b/ext/toolchain/ftputil.py @@ -23,13 +23,28 @@ class FtpUploader: self.password = password self.dir = dir - def run(self, src, dest, replace=False): - + def upload(self, src, dest, subDir=None): + print "Connecting to '%s'" % self.host ftp = FTP(self.host, self.user, self.password) - ftp.cwd(self.dir) + + self.changeDir(ftp, self.dir) + + if subDir: + self.changeDir(ftp, subDir) + print "Uploading '%s' as '%s'" % (src, dest) f = open(src, 'rb') ftp.storbinary('STOR ' + dest, f) f.close() ftp.close() + + print "Done" + + def changeDir(self, ftp, dir): + if dir not in ftp.nlst(): + print "Creating dir '%s'" % dir + ftp.mkd(dir) + + print "Changing to dir '%s'" % dir + ftp.cwd(dir)