2009-10-26 07:54:37 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
2011-01-15 04:01:31 +00:00
|
|
|
# synergy -- mouse and keyboard sharing utility
|
|
|
|
# Copyright (C) 2009 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
|
2010-06-20 17:38:51 +00:00
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
# hm.py: 'Help Me', is a simple wrapper for all build tools.
|
2009-10-26 07:54:37 +00:00
|
|
|
#
|
2011-01-15 04:01:31 +00:00
|
|
|
# This script was created for the Synergy project.
|
|
|
|
# http://synergy-foss.org/
|
2009-10-26 07:54:37 +00:00
|
|
|
#
|
2010-04-10 16:04:07 +00:00
|
|
|
# The idea behind this is to simplify the build system,
|
2011-01-15 04:01:31 +00:00
|
|
|
# however, it's not a dependancy of building Synergy.
|
2010-04-10 16:04:07 +00:00
|
|
|
# In other words, you don't need to use this script!
|
2009-10-26 07:54:37 +00:00
|
|
|
#
|
|
|
|
# If you don't wish to run this script, simply run:
|
|
|
|
# cmake .
|
|
|
|
# make
|
|
|
|
# This will create an in-source UNIX Makefile.
|
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
import sys, os
|
2011-04-25 16:20:49 +00:00
|
|
|
sys.path.append('tools')
|
|
|
|
|
2011-04-28 10:42:36 +00:00
|
|
|
# if old build src dir exists, move it, as this will now be used for build
|
|
|
|
# output.
|
|
|
|
if os.path.exists('build/toolchain.py'):
|
2011-04-26 19:55:03 +00:00
|
|
|
print "Removing legacy build dir."
|
|
|
|
os.rename('build', 'build.old')
|
|
|
|
|
2011-01-23 19:48:38 +00:00
|
|
|
from build import toolchain
|
2010-06-21 23:37:21 +00:00
|
|
|
from getopt import gnu_getopt
|
2010-06-15 22:29:32 +00:00
|
|
|
|
2011-01-23 19:48:38 +00:00
|
|
|
# minimum required version
|
|
|
|
requiredMajor = 2
|
|
|
|
requiredMinor = 3
|
|
|
|
|
2010-06-15 22:29:32 +00:00
|
|
|
# options used by all commands
|
|
|
|
global_options = 'g:v'
|
2010-06-20 02:30:45 +00:00
|
|
|
global_options_long = ['no-prompts', 'generator=', 'verbose', 'make-gui']
|
2010-06-15 22:29:32 +00:00
|
|
|
|
|
|
|
# options used by build related commands
|
|
|
|
build_options = 'dr'
|
|
|
|
build_options_long = ['debug', 'release']
|
2009-10-26 07:54:37 +00:00
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
# list of valid commands as keys. the values are optarg strings, but most
|
|
|
|
# are None for now (this is mainly for extensibility)
|
2010-06-15 22:29:32 +00:00
|
|
|
cmd_opt_dict = {
|
2011-01-16 19:06:04 +00:00
|
|
|
'about' : ['', []],
|
|
|
|
'setup' : ['', []],
|
2011-01-22 01:26:58 +00:00
|
|
|
'configure' : [build_options, build_options_long],
|
2011-01-16 19:06:04 +00:00
|
|
|
'build' : [build_options, build_options_long],
|
|
|
|
'clean' : [build_options, build_options_long],
|
|
|
|
'update' : ['', []],
|
|
|
|
'install' : ['', []],
|
2010-09-05 23:36:00 +00:00
|
|
|
'doxygen' : ['', []],
|
2011-01-18 22:55:39 +00:00
|
|
|
'dist' : ['', ['vcredist-dir=', 'qt-dir=']],
|
2011-01-16 19:06:04 +00:00
|
|
|
'distftp' : ['', ['host=', 'user=', 'pass=', 'dir=']],
|
|
|
|
'kill' : ['', []],
|
|
|
|
'usage' : ['', []],
|
|
|
|
'revision' : ['', []],
|
|
|
|
'reformat' : ['', []],
|
|
|
|
'open' : ['', []],
|
2011-01-23 19:48:38 +00:00
|
|
|
'genlist' : ['', []]
|
2010-04-11 02:22:15 +00:00
|
|
|
}
|
2009-10-26 07:54:37 +00:00
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
# aliases to valid commands
|
2010-04-10 16:04:07 +00:00
|
|
|
cmd_alias_dict = {
|
2011-01-16 19:06:04 +00:00
|
|
|
'info' : 'about',
|
|
|
|
'help' : 'usage',
|
|
|
|
'package' : 'dist',
|
|
|
|
'docs' : 'doxygen',
|
|
|
|
'make' : 'build',
|
|
|
|
'cmake' : 'configure',
|
2009-10-26 07:54:37 +00:00
|
|
|
}
|
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
def complete_command(arg):
|
|
|
|
completions = []
|
2009-10-26 07:54:37 +00:00
|
|
|
|
2010-06-15 22:29:32 +00:00
|
|
|
for cmd, optarg in cmd_opt_dict.iteritems():
|
2010-09-10 14:14:52 +00:00
|
|
|
# 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,]
|
2010-04-10 16:04:07 +00:00
|
|
|
if cmd.startswith(arg):
|
|
|
|
completions.append(cmd)
|
2009-10-26 07:54:37 +00:00
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
for alias, cmd in cmd_alias_dict.iteritems():
|
2010-09-10 14:14:52 +00:00
|
|
|
# don't know if this will work just like above, but it's
|
|
|
|
# probably worth adding.
|
|
|
|
if alias == arg:
|
|
|
|
return [alias,]
|
2010-04-10 16:04:07 +00:00
|
|
|
if alias.startswith(arg):
|
|
|
|
completions.append(alias)
|
2009-10-26 07:54:37 +00:00
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
return completions
|
2009-10-26 07:54:37 +00:00
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
def start_cmd(argv):
|
2010-04-11 02:22:15 +00:00
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
cmd_arg = ''
|
2009-10-26 07:54:37 +00:00
|
|
|
if len(argv) > 1:
|
2010-04-10 16:04:07 +00:00
|
|
|
cmd_arg = argv[1]
|
|
|
|
|
|
|
|
# change common help args to help command
|
|
|
|
if cmd_arg in ('--help', '-h', '--usage', '-u', '/?'):
|
|
|
|
cmd_arg = 'usage'
|
2009-10-26 07:54:37 +00:00
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
completions = complete_command(cmd_arg)
|
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
if cmd_arg and len(completions) > 0:
|
2009-10-26 07:54:37 +00:00
|
|
|
|
|
|
|
if len(completions) == 1:
|
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
# get the only completion (since in this case we have 1)
|
2009-10-26 07:54:37 +00:00
|
|
|
cmd = completions[0]
|
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
# build up the first part of the map (for illustrative purposes)
|
2010-04-10 16:04:07 +00:00
|
|
|
cmd_map = list()
|
|
|
|
if cmd_arg != cmd:
|
|
|
|
cmd_map.append(cmd_arg)
|
|
|
|
cmd_map.append(cmd)
|
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
# map an alias to the command, and build up the map
|
2010-04-10 16:04:07 +00:00
|
|
|
if cmd in cmd_alias_dict.keys():
|
|
|
|
alias = cmd
|
|
|
|
if cmd_arg == cmd:
|
|
|
|
cmd_map.append(alias)
|
|
|
|
cmd = cmd_alias_dict[cmd]
|
|
|
|
cmd_map.append(cmd)
|
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
# show command map to avoid confusion
|
2010-04-10 16:04:07 +00:00
|
|
|
if len(cmd_map) != 0:
|
|
|
|
print 'Mapping command: %s' % ' -> '.join(cmd_map)
|
|
|
|
|
2010-05-31 11:39:28 +00:00
|
|
|
run_cmd(cmd, argv[2:])
|
2010-04-10 16:04:07 +00:00
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
return 0
|
2010-04-10 16:04:07 +00:00
|
|
|
|
2009-10-26 07:54:37 +00:00
|
|
|
else:
|
2010-04-11 02:22:15 +00:00
|
|
|
print (
|
|
|
|
'Command `%s` too ambiguous, '
|
2009-10-26 07:54:37 +00:00
|
|
|
'could mean any of: %s'
|
2010-04-10 16:04:07 +00:00
|
|
|
) % (cmd_arg, ', '.join(completions))
|
2009-10-26 07:54:37 +00:00
|
|
|
else:
|
|
|
|
|
|
|
|
if len(argv) == 1:
|
|
|
|
print 'No command specified, showing usage.\n'
|
|
|
|
else:
|
2010-04-10 16:04:07 +00:00
|
|
|
print 'Command not recognised: %s\n' % cmd_arg
|
2010-05-31 11:39:28 +00:00
|
|
|
|
|
|
|
run_cmd('usage')
|
2009-11-02 21:17:45 +00:00
|
|
|
|
2010-04-11 02:22:15 +00:00
|
|
|
# generic error code if not returned sooner
|
|
|
|
return 1
|
2010-05-31 11:39:28 +00:00
|
|
|
|
2010-06-15 22:29:32 +00:00
|
|
|
def run_cmd(cmd, argv = []):
|
|
|
|
|
|
|
|
verbose = False
|
|
|
|
try:
|
2010-06-16 18:55:06 +00:00
|
|
|
options_pair = cmd_opt_dict[cmd]
|
|
|
|
|
|
|
|
options = global_options + options_pair[0]
|
|
|
|
|
|
|
|
options_long = []
|
|
|
|
options_long.extend(global_options_long)
|
|
|
|
options_long.extend(options_pair[1])
|
|
|
|
|
2010-06-21 23:37:21 +00:00
|
|
|
opts, args = gnu_getopt(argv, options, options_long)
|
2010-06-16 18:55:06 +00:00
|
|
|
|
|
|
|
for o, a in opts:
|
|
|
|
if o in ('-v', '--verbose'):
|
|
|
|
verbose = True
|
|
|
|
|
|
|
|
# pass args and optarg data to command handler, which figures out
|
|
|
|
# how to handle the arguments
|
2011-01-23 19:48:38 +00:00
|
|
|
handler = toolchain.CommandHandler(argv, opts, args, verbose)
|
2010-06-16 18:55:06 +00:00
|
|
|
|
|
|
|
# use reflection to get the function pointer
|
|
|
|
cmd_func = getattr(handler, cmd)
|
|
|
|
|
2010-06-15 22:29:32 +00:00
|
|
|
cmd_func()
|
2010-06-16 18:55:06 +00:00
|
|
|
except:
|
2010-06-15 22:29:32 +00:00
|
|
|
if not verbose:
|
|
|
|
# print friendly error for users
|
2010-06-22 00:09:29 +00:00
|
|
|
sys.stderr.write('Error: ' + sys.exc_info()[1].__str__() + '\n')
|
2011-01-23 19:48:38 +00:00
|
|
|
sys.exit(1)
|
2010-06-15 22:29:32 +00:00
|
|
|
else:
|
|
|
|
# if user wants to be verbose let python do it's thing
|
|
|
|
raise
|
2010-05-31 11:39:28 +00:00
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
def main(argv):
|
2009-11-02 21:17:45 +00:00
|
|
|
|
2011-01-23 19:48:38 +00:00
|
|
|
if sys.version_info < (requiredMajor, requiredMinor):
|
|
|
|
print ('Python version must be at least ' +
|
|
|
|
str(requiredMajor) + '.' + str(requiredMinor) + ', but is ' +
|
|
|
|
str(sys.version_info[0]) + '.' + str(sys.version_info[1]))
|
2010-04-10 16:04:07 +00:00
|
|
|
sys.exit(1)
|
2009-11-02 21:17:45 +00:00
|
|
|
|
2010-04-10 16:04:07 +00:00
|
|
|
try:
|
2010-06-16 18:55:06 +00:00
|
|
|
start_cmd(argv)
|
2010-04-10 16:04:07 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print '\n\nUser aborted, exiting.'
|
2009-12-27 20:12:41 +00:00
|
|
|
|
2009-10-26 07:54:37 +00:00
|
|
|
# Start the program.
|
|
|
|
main(sys.argv)
|