Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/main.py
blob: e8dc95964d643e281cb94dd6517e883e6557d2eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/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 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' and len(args) == 0:
        print 'Checking dependencies...'
        jhbuild.commands.run('sanitycheck', config, [])
    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)