From e93c89245921b757b11c964d0e0574def20c52bc Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Fri, 10 Sep 2010 14:14:52 +0000 Subject: [PATCH] Modified ftp upload behaviour --- build/commands.py | 58 +++++++++++++++++++++++++++++------------------ build/ftputil.py | 12 ++++++++-- hm.py | 12 +++++++++- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/build/commands.py b/build/commands.py index 2deba7fb..e6327e32 100644 --- a/build/commands.py +++ b/build/commands.py @@ -18,7 +18,7 @@ import sys, os, ConfigParser, subprocess, shutil, re, ftputil class InternalCommands: - + project = 'synergy-plus' setup_version = 4 # increment to force setup/config website_url = 'http://code.google.com/p/synergy-plus' @@ -374,7 +374,7 @@ class InternalCommands: if err != 0: raise Exception('doxygen failed with error code: ' + str(err)) - def dist(self, type, ftp=None): + def dist(self, type): # Package is supported by default. package_unsupported = False @@ -421,11 +421,18 @@ class InternalCommands: ("Package type, '%s' is not supported for platform, '%s'") % (type, sys.platform)) - if type and ftp: - name = self.dist_name(type) - print 'Uploading %s to FTP server %s...' % (name, ftp.host) - ftp.run('bin/' + name, self.dist_name_rev(type)) - print 'Done' + + def distftp(self, type, ftp): + if not type: + raise Exception('Type not specified.') + + if not ftp: + raise Exception('FTP info not defined.') + + name = self.dist_name(type) + print 'Uploading %s to FTP server %s...' % (name, ftp.host) + ftp.run('bin/' + name, self.dist_name_rev(type)) + print 'Done' def dist_name(self, type): ext = None @@ -824,28 +831,35 @@ class CommandHandler: type = None if len(self.args) > 0: type = self.args[0] + + self.ic.dist(type) + + def distftp(self): + type = None + host = None + user = None + password = None + dir = None - ftp_host = None - ftp_user = None - ftp_password = None - ftp_dir = None + if len(self.args) > 0: + type = self.args[0] for o, a in self.opts: - if o == '--ftp-host': - ftp_host = a - elif o == '--ftp-user': - ftp_user = a - elif o == '--ftp-pass': - ftp_password = a - elif o == '--ftp-dir': - ftp_dir = a + if o == '--host': + host = a + elif o == '--user': + user = a + elif o == '--pass': + password = a + elif o == '--dir': + dir = a ftp = None - if ftp_host: + if host: ftp = ftputil.FtpUploader( - ftp_host, ftp_user, ftp_password, ftp_dir) + host, user, password, dir) - self.ic.dist(type, ftp) + self.ic.distftp(type, ftp) def destroy(self): self.ic.destroy() diff --git a/build/ftputil.py b/build/ftputil.py index 450410c4..7b0c592a 100644 --- a/build/ftputil.py +++ b/build/ftputil.py @@ -22,13 +22,21 @@ class FtpUploader: self.password = password self.dir = dir - def run(self, src, dest): + def run(self, src, dest, replace=False): ftp = FTP(self.host, self.user, self.password) ftp.cwd(self.dir) + + # check to see if we should stop here + if not replace: + files = ftp.nlst() + if dest in files: + print 'Already exists, skipping.' + ftp.close() + return f = open(src, 'rb') ftp.storbinary('STOR ' + dest, f) f.close() - ftp.close() \ No newline at end of file + ftp.close() diff --git a/hm.py b/hm.py index 9d92df14..bf9ad0ae 100644 --- a/hm.py +++ b/hm.py @@ -52,7 +52,8 @@ cmd_opt_dict = { 'update' : ['', []], 'install' : ['', []], 'doxygen' : ['', []], - 'dist' : ['', ['ftp-host=', 'ftp-user=', 'ftp-pass=', 'ftp-dir=']], + 'dist' : ['', []], + 'distftp' : ['', ['host=', 'user=', 'pass=', 'dir=']], 'kill' : ['', []], 'usage' : ['', []], 'revision' : ['', []], @@ -74,10 +75,19 @@ def complete_command(arg): completions = [] for cmd, optarg in cmd_opt_dict.iteritems(): + # if command was matched fully, return only this, so that + # if `dist` is typed, it will return only `dist` and not + # `dist` and `distftp` for example. + if cmd == arg: + return [cmd,] if cmd.startswith(arg): completions.append(cmd) for alias, cmd in cmd_alias_dict.iteritems(): + # don't know if this will work just like above, but it's + # probably worth adding. + if alias == arg: + return [alias,] if alias.startswith(arg): completions.append(alias)