2 # jhbuild - a build script for GNOME 1.x and 2.x
3 # Copyright (C) 2001-2006 James Henstridge
5 # main.py: parses command line arguments and starts the build
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 localedir
= os
.path
.abspath(os
.path
.join(os
.path
.dirname(__file__
), '../mo'))
27 gettext
.install('jhbuild', localedir
=localedir
, unicode=True)
29 __builtin__
.__dict
__['N_'] = lambda x
: x
32 import jhbuild
.commands
33 from jhbuild
.errors
import UsageError
, FatalError
34 from jhbuild
.utils
.cmds
import get_output
35 from jhbuild
.moduleset
import warn_local_modulesets
38 if sys
.platform
== 'darwin':
39 # work around locale.getpreferredencoding() returning an empty string in
40 # Mac OS X, see http://bugzilla.gnome.org/show_bug.cgi?id=534650 and
41 # http://bazaar-vcs.org/DarwinCommandLineArgumentDecoding
42 sys
.platform
= 'posix'
46 sys
.platform
= 'darwin'
51 _encoding
= locale
.getpreferredencoding()
53 except (locale
.Error
, AssertionError):
57 if type(s
) is unicode:
58 return s
.encode(_encoding
, 'replace')
63 '''Print Unicode string encoded for the terminal'''
69 __builtin__
.__dict
__['uprint'] = uprint
70 __builtin__
.__dict
__['uencode'] = uencode
72 def help_commands(option
, opt_str
, value
, parser
):
73 thisdir
= os
.path
.abspath(os
.path
.dirname(__file__
))
75 # import all available commands
76 for fname
in os
.listdir(os
.path
.join(thisdir
, 'commands')):
77 name
, ext
= os
.path
.splitext(fname
)
81 __import__('jhbuild.commands.%s' % name
)
85 uprint(_('JHBuild commands are:'))
86 commands
= [(x
.name
, x
.doc
) for x
in jhbuild
.commands
.get_commands().values()]
88 for name
, description
in commands
:
89 uprint(' %-15s %s' % (name
, description
))
91 uprint(_('For more information run "jhbuild <command> --help"'))
95 parser
= optparse
.OptionParser(
96 usage
=_('%prog [ -f config ] command [ options ... ]'),
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('--help-commands', action
='callback',
100 callback
=help_commands
,
101 help=_('Information about available jhbuild commands'))
102 parser
.add_option('-f', '--file', action
='store', metavar
='CONFIG',
103 type='string', dest
='configfile',
104 default
=os
.environ
.get("JHBUILDRC", os
.path
.join(os
.environ
['HOME'], '.jhbuildrc')),
105 help=_('use a non default configuration file'))
106 parser
.add_option('-m', '--moduleset', action
='store', metavar
='URI',
107 type='string', dest
='moduleset', default
=None,
108 help=_('use a non default module set'))
109 parser
.add_option('--no-interact', action
='store_true',
110 dest
='nointeract', default
=False,
111 help=_('do not prompt for input'))
113 options
, args
= parser
.parse_args(args
)
116 config
= jhbuild
.config
.Config(options
.configfile
)
117 except FatalError
, exc
:
118 sys
.stderr
.write('jhbuild: %s\n' % exc
.args
[0].encode(_encoding
, 'replace'))
121 if options
.moduleset
: config
.moduleset
= options
.moduleset
122 if options
.nointeract
: config
.interact
= False
124 if not args
or args
[0][0] == '-':
125 command
= 'build' # default to cvs update + compile
130 warn_local_modulesets(config
)
133 rc
= jhbuild
.commands
.run(command
, config
, args
)
134 except UsageError
, exc
:
135 sys
.stderr
.write('jhbuild %s: %s\n' % (command
, exc
.args
[0].encode(_encoding
, 'replace')))
138 except FatalError
, exc
:
139 sys
.stderr
.write('jhbuild %s: %s\n' % (command
, exc
.args
[0].encode(_encoding
, 'replace')))
141 except KeyboardInterrupt:
142 uprint(_('Interrupted'))
148 if e
.errno
!= errno
.EPIPE
: