update nss patch to copy files it installs instead of symlinking them
[jhbuild.git] / jhbuild / main.py
blob02271eb710e3a67504140b9c6684d4c4642a12af
1 #!/usr/bin/env python
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
21 import sys, os, errno
22 import optparse
23 import traceback
25 import gettext
26 localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../mo'))
27 gettext.install('jhbuild', localedir=localedir, unicode=True)
28 import __builtin__
29 __builtin__.__dict__['N_'] = lambda x: x
31 import jhbuild.config
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'
43 try:
44 import locale
45 finally:
46 sys.platform = 'darwin'
47 else:
48 import locale
50 try:
51 _encoding = locale.getpreferredencoding()
52 assert _encoding
53 except (locale.Error, AssertionError):
54 _encoding = 'ascii'
56 def uencode(s):
57 if type(s) is unicode:
58 return s.encode(_encoding, 'replace')
59 else:
60 return s
62 def uprint(*args):
63 '''Print Unicode string encoded for the terminal'''
64 for s in args[:-1]:
65 print uencode(s),
66 s = args[-1]
67 print uencode(s)
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)
78 if not ext == '.py':
79 continue
80 try:
81 __import__('jhbuild.commands.%s' % name)
82 except ImportError:
83 pass
85 uprint(_('JHBuild commands are:'))
86 commands = [(x.name, x.doc) for x in jhbuild.commands.get_commands().values()]
87 commands.sort()
88 for name, description in commands:
89 uprint(' %-15s %s' % (name, description))
90 print
91 uprint(_('For more information run "jhbuild <command> --help"'))
92 parser.exit()
94 def main(args):
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)
115 try:
116 config = jhbuild.config.Config(options.configfile)
117 except FatalError, exc:
118 sys.stderr.write('jhbuild: %s\n' % exc.args[0].encode(_encoding, 'replace'))
119 sys.exit(1)
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
126 else:
127 command = args[0]
128 args = args[1:]
130 warn_local_modulesets(config)
132 try:
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')))
136 parser.print_usage()
137 sys.exit(1)
138 except FatalError, exc:
139 sys.stderr.write('jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
140 sys.exit(1)
141 except KeyboardInterrupt:
142 uprint(_('Interrupted'))
143 sys.exit(1)
144 except EOFError:
145 uprint(_('EOF'))
146 sys.exit(1)
147 except IOError, e:
148 if e.errno != errno.EPIPE:
149 raise
150 sys.exit(0)
151 if rc:
152 sys.exit(rc)