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 help_commands(option
, opt_str
, value
, parser
):
79 thisdir
= os
.path
.abspath(os
.path
.dirname(__file__
))
81 # import all available commands
82 for fname
in os
.listdir(os
.path
.join(thisdir
, 'commands')):
83 name
, ext
= os
.path
.splitext(fname
)
87 __import__('jhbuild.commands.%s' % name
)
91 uprint(_('JHBuild commands are:'))
92 commands
= [(x
.name
, x
.doc
) for x
in jhbuild
.commands
.get_commands().values()]
94 for name
, description
in commands
:
95 uprint(' %-15s %s' % (name
, description
))
97 uprint(_('For more information run "jhbuild <command> --help"'))
101 localedir
= os
.path
.abspath(os
.path
.join(os
.path
.dirname(__file__
), '..', 'mo'))
102 if not os
.path
.exists(localedir
):
104 gettext
.install('jhbuild', localedir
=localedir
, unicode=True)
106 logging
.getLogger().setLevel(logging
.INFO
)
107 logging_handler
= logging
.StreamHandler()
108 logging_handler
.setFormatter(LoggingFormatter())
109 logging
.getLogger().addHandler(logging_handler
)
110 parser
= optparse
.OptionParser(
111 usage
=_('%prog [ -f config ] command [ options ... ]'),
112 description
=_('Build a set of modules from diverse repositories in correct dependency order (such as GNOME).'))
113 parser
.disable_interspersed_args()
114 parser
.add_option('--help-commands', action
='callback',
115 callback
=help_commands
,
116 help=_('Information about available jhbuild commands'))
117 parser
.add_option('-f', '--file', action
='store', metavar
='CONFIG',
118 type='string', dest
='configfile',
119 default
=os
.environ
.get("JHBUILDRC", os
.path
.join(os
.environ
['HOME'], '.jhbuildrc')),
120 help=_('use a non default configuration file'))
121 parser
.add_option('-m', '--moduleset', action
='store', metavar
='URI',
122 type='string', dest
='moduleset', default
=None,
123 help=_('use a non default module set'))
124 parser
.add_option('--no-interact', action
='store_true',
125 dest
='nointeract', default
=False,
126 help=_('do not prompt for input'))
128 options
, args
= parser
.parse_args(args
)
131 config
= jhbuild
.config
.Config(options
.configfile
)
132 except FatalError
, exc
:
133 sys
.stderr
.write('jhbuild: %s\n' % exc
.args
[0].encode(_encoding
, 'replace'))
136 if options
.moduleset
: config
.moduleset
= options
.moduleset
137 if options
.nointeract
: config
.interact
= False
139 if not args
or args
[0][0] == '-':
140 command
= 'build' # default to cvs update + compile
145 warn_local_modulesets(config
)
148 rc
= jhbuild
.commands
.run(command
, config
, args
)
149 except UsageError
, exc
:
150 sys
.stderr
.write('jhbuild %s: %s\n' % (command
, exc
.args
[0].encode(_encoding
, 'replace')))
153 except FatalError
, exc
:
154 sys
.stderr
.write('jhbuild %s: %s\n' % (command
, exc
.args
[0].encode(_encoding
, 'replace')))
156 except KeyboardInterrupt:
157 uprint(_('Interrupted'))
163 if e
.errno
!= errno
.EPIPE
: