Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha-org-sugar-git@silbe.org>2010-02-03 10:24:43 (GMT)
committer Sascha Silbe <sascha-org-sugar-git@silbe.org>2010-02-03 10:24:43 (GMT)
commite2ca8c8db80c7bd19db05f05e4619236baa60680 (patch)
treed9b29ee86444bedcdfafbfdb7970d2eb75d68915
parentf5d5b841c9b8c32caabd62d919f8274bb2412430 (diff)
Sync main.py with upstream code.
This also removes the automatic invocation of sugar-emulator if no argument is given to the "run" command. Experience shows that users get confused by that and assume sugar-jhbuild is an alternative to sugar-emulator instead of simply a build tool that can build and run sugar-emulator.
-rw-r--r--sjhbuild/config.py3
-rw-r--r--sjhbuild/main.py112
2 files changed, 25 insertions, 90 deletions
diff --git a/sjhbuild/config.py b/sjhbuild/config.py
index 2c30ce0..259611e 100644
--- a/sjhbuild/config.py
+++ b/sjhbuild/config.py
@@ -11,8 +11,7 @@ class Config(jhbuild.config.Config):
def __init__(self, base_dir, rc_file):
self.base_dir = base_dir
- jhbuild.config.Config.__init__(self, os.path.join(self.base_dir,
- 'sugar.jhbuildrc'))
+ jhbuild.config.Config.__init__(self, rc_file)
self._setup()
def _setup(self):
diff --git a/sjhbuild/main.py b/sjhbuild/main.py
index f0bdb8a..09a75bf 100644
--- a/sjhbuild/main.py
+++ b/sjhbuild/main.py
@@ -19,13 +19,12 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import errno
+import logging
import optparse
import os
import sys
import gettext
-localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../mo'))
-gettext.install('jhbuild', localedir=localedir, unicode=True)
import __builtin__
__builtin__.__dict__['N_'] = lambda x: x
@@ -33,90 +32,35 @@ import jhbuild.commands
from jhbuild.errors import UsageError, FatalError
from jhbuild.moduleset import warn_local_modulesets
+import jhbuild.main
+
import bundlemodule
from config import Config
import depscheck
-if sys.platform == 'darwin':
- # work around locale.getpreferredencoding() returning an empty string in
- # Mac OS X, see http://bugzilla.gnome.org/show_bug.cgi?id=534650 and
- # http://bazaar-vcs.org/DarwinCommandLineArgumentDecoding
- sys.platform = 'posix'
- try:
- import locale
- finally:
- sys.platform = 'darwin'
-else:
- import locale
-
-try:
- _encoding = locale.getpreferredencoding()
- assert _encoding
-except (locale.Error, AssertionError):
- _encoding = 'ascii'
-
-
-def uencode(s):
- if type(s) is unicode:
- return s.encode(_encoding, 'replace')
- else:
- return s
-
-
-def uprint(*args):
- '''Print Unicode string encoded for the terminal'''
- for s in args[:-1]:
- print uencode(s),
- s = args[-1]
- print uencode(s)
-
-
-__builtin__.__dict__['uprint'] = uprint
-__builtin__.__dict__['uencode'] = uencode
-
-
-def help_commands(option, opt_str, value, parser):
- thisdir = os.path.abspath(os.path.dirname(__file__))
- thisdir = os.path.split(thisdir)[0]
- thisdir = os.path.join(thisdir, 'jhbuild', 'jhbuild')
-
- # import all available commands
- for fname in os.listdir(os.path.join(thisdir, 'commands')):
- name, ext = os.path.splitext(fname)
- if not ext == '.py':
- continue
-
- try:
- __import__('jhbuild.commands.%s' % name)
-
- # pylint: disable-msg=W0704
- except ImportError:
- pass
-
- uprint(_('JHBuild commands are:'))
- commands = [(x.name, x.doc)
- for x in jhbuild.commands.get_commands().values()]
- commands.sort()
- for name, description in commands:
- uprint(' %-15s %s' % (name, description))
- print
- uprint(_('For more information run "jhbuild <command> --help"'))
- parser.exit()
-
+# Need a literal copy as there's no other way to use our own Config class :-/
def main(base_dir, args):
+ gettext.install('jhbuild', unicode=True)
+
+ logging.getLogger().setLevel(logging.INFO)
+ logging_handler = logging.StreamHandler()
+ logging_handler.setFormatter(jhbuild.main.LoggingFormatter())
+ logging.getLogger().addHandler(logging_handler)
parser = optparse.OptionParser(
usage=_('%prog [ -f config ] command [ options ... ]'),
- description=_('Build a set of modules from diverse repositories in '
- 'correct dependency order (such as GNOME).'))
+ add_help_option=False,
+ description=_('Build a set of modules from diverse repositories in correct dependency order (such as GNOME).'))
parser.disable_interspersed_args()
+ parser.add_option('-h', '--help', action='callback',
+ callback=lambda *args: jhbuild.main.print_help(parser),
+ help=_("Display this help and exit"))
parser.add_option('--help-commands', action='callback',
- callback=help_commands,
- help=_('Information about available jhbuild commands'))
+ callback=lambda *args: jhbuild.main.print_help(parser),
+ help=optparse.SUPPRESS_HELP)
parser.add_option('-f', '--file', action='store', metavar='CONFIG',
type='string', dest='configfile',
- default=os.environ.get('JHBUILDRC',
- os.path.join(os.environ['HOME'], '.jhbuildrc')),
+ default=os.path.join(base_dir, 'sugar.jhbuildrc'),
help=_('use a non default configuration file'))
parser.add_option('-m', '--moduleset', action='store', metavar='URI',
type='string', dest='moduleset', default=None,
@@ -130,14 +74,11 @@ def main(base_dir, args):
try:
config = Config(base_dir, options.configfile)
except FatalError, exc:
- sys.stderr.write('sugar-jhbuild: %s\n' % \
- exc.args[0].encode(_encoding, 'replace'))
+ sys.stderr.write('sugar-jhbuild: %s\n' % exc.args[0].encode(_encoding, 'replace'))
sys.exit(1)
- if options.moduleset:
- config.moduleset = options.moduleset
- if options.nointeract:
- config.interact = False
+ if options.moduleset: config.moduleset = options.moduleset
+ if options.nointeract: config.interact = False
if not args or args[0][0] == '-':
command = 'build' # default to cvs update + compile
@@ -145,21 +86,16 @@ def main(base_dir, args):
command = args[0]
args = args[1:]
- if command == 'run' and len(args) == 0:
- args.append('sugar-emulator')
-
warn_local_modulesets(config)
try:
- rc = jhbuild.commands.run(command, config, args)
+ rc = jhbuild.commands.run(command, config, args, help=lambda: jhbuild.main.print_help(parser))
except UsageError, exc:
- sys.stderr.write('sugar-jhbuild %s: %s\n' % (command,
- exc.args[0].encode(_encoding, 'replace')))
+ sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
parser.print_usage()
sys.exit(1)
except FatalError, exc:
- sys.stderr.write('sugar-jhbuild %s: %s\n' % (command,
- exc.args[0].encode(_encoding, 'replace')))
+ sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
sys.exit(1)
except KeyboardInterrupt:
uprint(_('Interrupted'))