1 # jhbuild - a build script for GNOME 1.x and 2.x
2 # Copyright (C) 2001-2006 James Henstridge
4 # main.py: parses command line arguments and starts the build
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 __builtin__
.__dict
__['N_'] = lambda x
: x
30 import jhbuild
.commands
31 from jhbuild
.errors
import UsageError
, FatalError
32 from jhbuild
.utils
.cmds
import get_output
33 from jhbuild
.moduleset
import warn_local_modulesets
36 if sys
.platform
== 'darwin':
37 # work around locale.getpreferredencoding() returning an empty string in
38 # Mac OS X, see http://bugzilla.gnome.org/show_bug.cgi?id=534650 and
39 # http://bazaar-vcs.org/DarwinCommandLineArgumentDecoding
40 sys
.platform
= 'posix'
44 sys
.platform
= 'darwin'
49 _encoding
= locale
.getpreferredencoding()
51 except (locale
.Error
, AssertionError):
55 if type(s
) is unicode:
56 return s
.encode(_encoding
, 'replace')
61 '''Print Unicode string encoded for the terminal'''
67 __builtin__
.__dict
__['uprint'] = uprint
68 __builtin__
.__dict
__['uencode'] = uencode
70 class LoggingFormatter(logging
.Formatter
):
72 logging
.Formatter
.__init
__(self
, '%(level_name_initial)s: %(message)s')
74 def format(self
, record
):
75 record
.level_name_initial
= record
.levelname
[0]
76 return logging
.Formatter
.format(self
, record
)
78 def print_help(parser
):
81 jhbuild
.commands
.print_help()
85 localedir
= os
.path
.abspath(os
.path
.join(os
.path
.dirname(__file__
), '..', 'mo'))
86 if not os
.path
.exists(localedir
):
88 gettext
.install('jhbuild', localedir
=localedir
, unicode=True)
90 logging
.getLogger().setLevel(logging
.INFO
)
91 logging_handler
= logging
.StreamHandler()
92 logging_handler
.setFormatter(LoggingFormatter())
93 logging
.getLogger().addHandler(logging_handler
)
94 parser
= optparse
.OptionParser(
95 usage
=_('%prog [ -f config ] command [ options ... ]'),
96 add_help_option
=False,
97 description
=_('Build a set of modules from diverse repositories in correct dependency order (such as GNOME).'))
98 parser
.disable_interspersed_args()
99 parser
.add_option('-h', '--help', action
='callback',
100 callback
=lambda *args
: print_help(parser
),
101 help=_("Display this help and exit"))
102 parser
.add_option('--help-commands', action
='callback',
103 callback
=lambda *args
: print_help(parser
),
104 help=optparse
.SUPPRESS_HELP
)
105 parser
.add_option('-f', '--file', action
='store', metavar
='CONFIG',
106 type='string', dest
='configfile',
107 default
=os
.environ
.get("JHBUILDRC", os
.path
.join(os
.environ
['HOME'], '.jhbuildrc')),
108 help=_('use a non default configuration file'))
109 parser
.add_option('-m', '--moduleset', action
='store', metavar
='URI',
110 type='string', dest
='moduleset', default
=None,
111 help=_('use a non default module set'))
112 parser
.add_option('--no-interact', action
='store_true',
113 dest
='nointeract', default
=False,
114 help=_('do not prompt for input'))
116 options
, args
= parser
.parse_args(args
)
119 config
= jhbuild
.config
.Config(options
.configfile
)
120 except FatalError
, exc
:
121 sys
.stderr
.write('jhbuild: %s\n' % exc
.args
[0].encode(_encoding
, 'replace'))
124 if options
.moduleset
: config
.moduleset
= options
.moduleset
125 if options
.nointeract
: config
.interact
= False
127 if not args
or args
[0][0] == '-':
128 command
= 'build' # default to cvs update + compile
133 warn_local_modulesets(config
)
136 rc
= jhbuild
.commands
.run(command
, config
, args
, help=lambda: print_help(parser
))
137 except UsageError
, exc
:
138 sys
.stderr
.write('jhbuild %s: %s\n' % (command
, exc
.args
[0].encode(_encoding
, 'replace')))
141 except FatalError
, exc
:
142 sys
.stderr
.write('jhbuild %s: %s\n' % (command
, exc
.args
[0].encode(_encoding
, 'replace')))
144 except KeyboardInterrupt:
145 uprint(_('Interrupted'))
151 if e
.errno
!= errno
.EPIPE
: