Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2007-01-26 14:23:21 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2007-01-26 14:23:21 (GMT)
commit110a8ef3e260d360b333e9e8f1562affdd864515 (patch)
treefa76cc42c2e7acede4dca5c501952eb14267af7d
parenta5a9c0fb4f20eaae3c43b586170a805cf42567de (diff)
Copy some code from jhbuild so that we display help and support all the options.
-rw-r--r--config.py17
-rw-r--r--main.py116
-rwxr-xr-xsugar-jhbuild30
3 files changed, 126 insertions, 37 deletions
diff --git a/config.py b/config.py
index c3d7c92..dd5b057 100644
--- a/config.py
+++ b/config.py
@@ -3,21 +3,20 @@ import os
import jhbuild.config
class Config(jhbuild.config.Config):
- def __init__(self, base_dir):
- self._base_dir = base_dir
+ def __init__(self, rc_file):
+ self._base_dir = os.path.abspath(os.path.dirname(__file__))
self.xulrunner_sdk = 'xulrunner-1.9a2pre'
- jhbuild.config.Config.__init__(self, self._get_rc_file())
+ jhbuild.config.Config.__init__(self, self._ensure_rc_file(rc_file))
self._setup()
- def _get_rc_file(self):
- rc = os.path.expanduser('~/.olpc.jhbuildrc')
- if not os.path.exists(rc):
- f = open(rc, 'w')
- f.write('# Create by sugar-jhbuild')
+ def _ensure_rc_file(self, rc_file):
+ if not os.path.exists(rc_file):
+ f = open(rc_file, 'w')
+ f.write('# Created by sugar-jhbuild')
f.close
- return rc
+ return rc_file
def _setup(self):
self.moduleset = []
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..ac15e70
--- /dev/null
+++ b/main.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2001-2006 James Henstridge
+#
+# main.py: parses command line arguments and starts the build
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import sys, os
+import optparse
+import traceback
+
+import bundlemodule
+import mozillamodule
+import sanitycheck
+
+from config import Config
+
+import jhbuild.commands
+from jhbuild.errors import UsageError, FatalError
+
+def help_commands(option, opt_str, value, parser):
+ commands = [
+ ('build', 'update and compile (the default)'),
+ ('build-base', 'build the base sugar dependencies'),
+ ('buildone', 'modules build a single module'),
+ ('update', 'update from version control'),
+ ('updateone', 'update a fixed set of modules'),
+ ('list', 'list what modules would be built'),
+ ('info', 'prints information about modules'),
+ ('tinderbox', 'build non-interactively with logging'),
+ ('gui', 'build targets from a gui app'),
+ ('run', 'run a command in the build environment'),
+ ('shell', 'start a shell in the build environment'),
+ ('sanitycheck', 'check that required dependencies exists'),
+ ('dot', 'output a dependency graph for processing with graphviz'),
+ ]
+ print 'sugar-jhbuild commands are:'
+ for (cmd, description) in commands:
+ print ' %-15s %s' % (cmd, description)
+ print
+ print 'For more information run "sugar-jhbuild <command> --help"'
+ parser.exit()
+
+def main(args):
+ parser = optparse.OptionParser(
+ usage='%prog [ -f config ] command [ options ... ]',
+ description='Build sugar and his dependencies.')
+ parser.disable_interspersed_args()
+ parser.add_option('--help-commands', action='callback',
+ callback=help_commands,
+ help='Information about available jhbuild commands')
+ parser.add_option('-f', '--file', action='store', metavar='CONFIG',
+ type='string', dest='configfile',
+ default=os.path.join(os.environ['HOME'], '.olpc.jhbuildrc'),
+ help='use a non default configuration file')
+ parser.add_option('-m', '--moduleset', action='store', metavar='URI',
+ type='string', dest='moduleset', default=None,
+ help='use a non default module set')
+ parser.add_option('--no-interact', action='store_true',
+ dest='nointeract', default=False,
+ help='do not prompt for input')
+
+ options, args = parser.parse_args(args)
+
+ try:
+ config = Config(options.configfile)
+ except FatalError, exc:
+ sys.stderr.write('sugar-jhbuild: %s\n' % (str(exc)))
+ sys.exit(1)
+
+ 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
+ else:
+ command = args[0]
+ args = args[1:]
+
+ if command == 'build':
+ print 'Checking dependencies...'
+ jhbuild.commands.run('sanitycheck', config, [])
+ elif command == 'build-base':
+ command = 'build'
+ args.append('meta-sugar-base')
+ elif command == 'run' and len(args) == 0:
+ args.append('sugar-emulator')
+
+ try:
+ jhbuild.commands.run(command, config, args)
+ except UsageError, exc:
+ sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, str(exc)))
+ parser.print_usage()
+ sys.exit(1)
+ except FatalError, exc:
+ sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, str(exc)))
+ sys.exit(1)
+ except KeyboardInterrupt:
+ print "Interrupted"
+ sys.exit(1)
+ except EOFError:
+ print "EOF"
+ sys.exit(1)
diff --git a/sugar-jhbuild b/sugar-jhbuild
index ad084e3..99fa61a 100755
--- a/sugar-jhbuild
+++ b/sugar-jhbuild
@@ -6,32 +6,6 @@ import sys
base_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.join(base_dir, 'build-scripts', 'jhbuild'))
-import jhbuild.commands
+import main
-import bundlemodule
-import mozillamodule
-import sanitycheck
-
-from config import Config
-
-config = Config(base_dir)
-
-args = []
-command = 'build'
-
-if len(sys.argv) > 0:
- command = sys.argv[1]
-
-if len(sys.argv) > 1:
- args = sys.argv[2:]
-
-if command == 'build':
- print 'Checking dependencies...'
- jhbuild.commands.run('sanitycheck', config, [])
-elif command == 'build-base':
- command = 'build'
- args.append('meta-sugar-base')
-elif command == 'run' and len(args) == 0:
- args.append('sugar-emulator')
-
-jhbuild.commands.run(command, config, args)
+main.main(sys.argv[1:])