From f7b0e24a6e499aa4427dca4de1af6db8d2540ef4 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 21 Jun 2010 23:37:21 +0000 Subject: [PATCH] Merge in 1.3.6 r656:660 into 1.4.2 and trunk --- build/commands.py | 73 ++++++++++++++++++++++++++++++++++++++--------- build/ftputil.py | 34 ++++++++++++++++++++++ hm.py | 6 ++-- 3 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 build/ftputil.py diff --git a/build/commands.py b/build/commands.py index 7a93af8d..6c6d92a8 100644 --- a/build/commands.py +++ b/build/commands.py @@ -15,7 +15,7 @@ # TODO: split this file up, it's too long! -import sys, os, ConfigParser, subprocess, shutil, re +import sys, os, ConfigParser, subprocess, shutil, re, ftputil class InternalCommands: @@ -39,6 +39,7 @@ class InternalCommands: xcodeproj_filename = '%s.xcodeproj' % project config_filename = '%s.cfg' % this_cmd qtpro_filename = 'qsynergy.pro' + package_filename_re = 'synergy-plus-\d\.\d\.\d-.*' # try_chdir(...) and restore_chdir() will use this prevdir = '' @@ -372,18 +373,28 @@ class InternalCommands: raise Exception('Could not update from repository with error code code: ' + str(err)) def revision(self): - # While this doesn't print out the revision specifically, it will do. - err = os.system('svn info') - if err != 0: - raise Exception('Could not get revision info with error code code: ' + str(err)) + print self.find_revision() + def find_revision(self): + p = subprocess.Popen(['svn', 'info'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + stdout, stderr = p.communicate() + + if p.returncode != 0: + raise Exception('Could not get revision info with error code code: ' + str(p.returncode)) + + m = re.search('.*Revision: (\d+).*', stdout) + if not m: + raise Exception('Could not find revision number in svn info output.') + + return m.group(1) + def kill(self): if sys.platform == 'win32': return os.system('taskkill /F /FI "IMAGENAME eq synergy*"') else: raise Exception('Not implemented for platform: ' + sys.platform) - def package(self, type): + def package(self, type, ftp=None): # Package is supported by default. package_unsupported = False @@ -422,6 +433,23 @@ class InternalCommands: raise Exception( ("Package type, '%s' is not supported for platform, '%s'") % (type, sys.platform)) + + if ftp: + print 'Uploading package to FTP...' + ftp.run('bin/' + self.dist_name(), self.dist_name_rev()) + + def dist_name(self): + for filename in os.listdir(self.bin_dir): + if re.search(self.package_filename_re, filename): + return filename + + # still here? package probably not created yet. + raise Exception('Could not find package name.') + + def dist_name_rev(self): + pattern = '(.*\d+\.\d+\.\d+)(.*)' + replace = '\g<1>-r' + self.find_revision() + '\g<2>' + return re.sub(pattern, replace, self.dist_name()) def package_run(self, command): self.try_chdir(self.bin_dir) @@ -758,16 +786,35 @@ class CommandHandler: print 'Not yet implemented: install' def package(self): - self.ic.package() - - def destroy(self): - self.ic.destroy() - - def package(self): + type = None if len(self.args) > 0: type = self.args[0] - self.ic.package(type) + + ftp_host = None + ftp_user = None + ftp_password = None + ftp_dir = None + + 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 + + ftp = None + if ftp_host: + ftp = ftputil.FtpUploader( + ftp_host, ftp_user, ftp_password, ftp_dir) + + self.ic.package(type, ftp) + + def destroy(self): + self.ic.destroy() def kill(self): self.ic.kill() diff --git a/build/ftputil.py b/build/ftputil.py new file mode 100644 index 00000000..450410c4 --- /dev/null +++ b/build/ftputil.py @@ -0,0 +1,34 @@ +# synergy-plus -- mouse and keyboard sharing utility +# Copyright (C) 2010 The Synergy+ Project +# +# This package is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# found in the file COPYING that should have accompanied this file. +# +# This package is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from ftplib import FTP + +class FtpUploader: + def __init__(self, host, user, password, dir): + self.host = host + self.user = user + self.password = password + self.dir = dir + + def run(self, src, dest): + + ftp = FTP(self.host, self.user, self.password) + ftp.cwd(self.dir) + + f = open(src, 'rb') + ftp.storbinary('STOR ' + dest, f) + f.close() + + ftp.close() \ No newline at end of file diff --git a/hm.py b/hm.py index 07c5b848..21e9619f 100644 --- a/hm.py +++ b/hm.py @@ -31,7 +31,7 @@ import sys, os from build import commands -from getopt import getopt +from getopt import gnu_getopt # options used by all commands global_options = 'g:v' @@ -51,7 +51,7 @@ cmd_opt_dict = { 'clean' : [build_options, build_options_long], 'update' : ['', []], 'install' : ['', []], - 'package' : ['', []], + 'package' : ['', ['ftp-host=', 'ftp-user=', 'ftp-pass=', 'ftp-dir=']], 'kill' : ['', []], 'usage' : ['', []], 'revision' : ['', []], @@ -151,7 +151,7 @@ def run_cmd(cmd, argv = []): options_long.extend(global_options_long) options_long.extend(options_pair[1]) - opts, args = getopt(argv, options, options_long) + opts, args = gnu_getopt(argv, options, options_long) for o, a in opts: if o in ('-v', '--verbose'):