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

@ -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()

View File

@ -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()
ftp.close()

12
hm.py
View File

@ -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)