Modified ftp upload behaviour

This commit is contained in:
Nick Bolton 2010-09-10 14:14:52 +00:00
parent 3d21f93dd3
commit e93c892459
3 changed files with 57 additions and 25 deletions

View File

@ -374,7 +374,7 @@ class InternalCommands:
if err != 0: if err != 0:
raise Exception('doxygen failed with error code: ' + str(err)) 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 is supported by default.
package_unsupported = False package_unsupported = False
@ -421,7 +421,14 @@ class InternalCommands:
("Package type, '%s' is not supported for platform, '%s'") ("Package type, '%s' is not supported for platform, '%s'")
% (type, sys.platform)) % (type, sys.platform))
if type and ftp:
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) name = self.dist_name(type)
print 'Uploading %s to FTP server %s...' % (name, ftp.host) print 'Uploading %s to FTP server %s...' % (name, ftp.host)
ftp.run('bin/' + name, self.dist_name_rev(type)) ftp.run('bin/' + name, self.dist_name_rev(type))
@ -825,27 +832,34 @@ class CommandHandler:
if len(self.args) > 0: if len(self.args) > 0:
type = self.args[0] type = self.args[0]
ftp_host = None self.ic.dist(type)
ftp_user = None
ftp_password = None def distftp(self):
ftp_dir = None type = None
host = None
user = None
password = None
dir = None
if len(self.args) > 0:
type = self.args[0]
for o, a in self.opts: for o, a in self.opts:
if o == '--ftp-host': if o == '--host':
ftp_host = a host = a
elif o == '--ftp-user': elif o == '--user':
ftp_user = a user = a
elif o == '--ftp-pass': elif o == '--pass':
ftp_password = a password = a
elif o == '--ftp-dir': elif o == '--dir':
ftp_dir = a dir = a
ftp = None ftp = None
if ftp_host: if host:
ftp = ftputil.FtpUploader( 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): def destroy(self):
self.ic.destroy() self.ic.destroy()

View File

@ -22,11 +22,19 @@ class FtpUploader:
self.password = password self.password = password
self.dir = dir self.dir = dir
def run(self, src, dest): def run(self, src, dest, replace=False):
ftp = FTP(self.host, self.user, self.password) ftp = FTP(self.host, self.user, self.password)
ftp.cwd(self.dir) 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') f = open(src, 'rb')
ftp.storbinary('STOR ' + dest, f) ftp.storbinary('STOR ' + dest, f)
f.close() f.close()

12
hm.py
View File

@ -52,7 +52,8 @@ cmd_opt_dict = {
'update' : ['', []], 'update' : ['', []],
'install' : ['', []], 'install' : ['', []],
'doxygen' : ['', []], 'doxygen' : ['', []],
'dist' : ['', ['ftp-host=', 'ftp-user=', 'ftp-pass=', 'ftp-dir=']], 'dist' : ['', []],
'distftp' : ['', ['host=', 'user=', 'pass=', 'dir=']],
'kill' : ['', []], 'kill' : ['', []],
'usage' : ['', []], 'usage' : ['', []],
'revision' : ['', []], 'revision' : ['', []],
@ -74,10 +75,19 @@ def complete_command(arg):
completions = [] completions = []
for cmd, optarg in cmd_opt_dict.iteritems(): 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): if cmd.startswith(arg):
completions.append(cmd) completions.append(cmd)
for alias, cmd in cmd_alias_dict.iteritems(): 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): if alias.startswith(arg):
completions.append(alias) completions.append(alias)