Modified ftp upload behaviour
This commit is contained in:
parent
3d21f93dd3
commit
e93c892459
|
@ -18,7 +18,7 @@
|
||||||
import sys, os, ConfigParser, subprocess, shutil, re, ftputil
|
import sys, os, ConfigParser, subprocess, shutil, re, ftputil
|
||||||
|
|
||||||
class InternalCommands:
|
class InternalCommands:
|
||||||
|
|
||||||
project = 'synergy-plus'
|
project = 'synergy-plus'
|
||||||
setup_version = 4 # increment to force setup/config
|
setup_version = 4 # increment to force setup/config
|
||||||
website_url = 'http://code.google.com/p/synergy-plus'
|
website_url = 'http://code.google.com/p/synergy-plus'
|
||||||
|
@ -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,11 +421,18 @@ 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:
|
|
||||||
name = self.dist_name(type)
|
def distftp(self, type, ftp):
|
||||||
print 'Uploading %s to FTP server %s...' % (name, ftp.host)
|
if not type:
|
||||||
ftp.run('bin/' + name, self.dist_name_rev(type))
|
raise Exception('Type not specified.')
|
||||||
print 'Done'
|
|
||||||
|
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):
|
def dist_name(self, type):
|
||||||
ext = None
|
ext = None
|
||||||
|
@ -824,28 +831,35 @@ class CommandHandler:
|
||||||
type = None
|
type = None
|
||||||
if len(self.args) > 0:
|
if len(self.args) > 0:
|
||||||
type = 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
|
if len(self.args) > 0:
|
||||||
ftp_user = None
|
type = self.args[0]
|
||||||
ftp_password = None
|
|
||||||
ftp_dir = None
|
|
||||||
|
|
||||||
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()
|
||||||
|
|
|
@ -22,13 +22,21 @@ 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()
|
||||||
|
|
||||||
ftp.close()
|
ftp.close()
|
||||||
|
|
12
hm.py
12
hm.py
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue