190
191
If true, this command isn't advertised. This is typically
191
192
for commands intended for expert users.
195
Command objects will get a 'outf' attribute, which has been
196
setup to properly handle encoding of unicode strings.
197
encoding_type determines what will happen when characters cannot
199
strict - abort if we cannot decode
200
replace - put in a bogus character (typically '?')
201
exact - do not encode sys.stdout
195
206
takes_options = []
207
encoding_type = 'strict'
228
def _setup_outf(self):
229
"""Return a file linked to stdout, which has proper encoding."""
230
assert self.encoding_type in ['strict', 'exact', 'replace']
232
# Originally I was using self.stdout, but that looks
233
# *way* too much like sys.stdout
234
if self.encoding_type == 'exact':
235
self.outf = sys.stdout
238
output_encoding = getattr(sys.stdout, 'encoding', None)
239
if not output_encoding:
240
input_encoding = getattr(sys.stdin, 'encoding', None)
241
if not input_encoding:
242
output_encoding = bzrlib.user_encoding
243
mutter('encoding stdout as bzrlib.user_encoding %r', output_encoding)
245
output_encoding = input_encoding
246
mutter('encoding stdout as sys.stdin encoding %r', output_encoding)
248
mutter('encoding stdout as sys.stdout encoding %r', output_encoding)
250
# use 'replace' so that we don't abort if trying to write out
251
# in e.g. the default C locale.
252
self.outf = codecs.getwriter(output_encoding)(sys.stdout, errors=self.encoding_type)
253
# For whatever reason codecs.getwriter() does not advertise its encoding
254
# it just returns the encoding of the wrapped file, which is completely
255
# bogus. So set the attribute, so we can find the correct encoding later.
256
self.outf.encoding = output_encoding
216
258
@deprecated_method(zero_eight)
217
259
def run_argv(self, argv):
218
260
"""Parse command line and run.
269
313
return _unsquish_command_name(self.__class__.__name__)
315
def plugin_name(self):
316
"""Get the name of the plugin that provides this command.
318
:return: The name of the plugin or None if the command is builtin.
320
mod_parts = self.__module__.split('.')
321
if len(mod_parts) >= 3 and mod_parts[1] == 'plugins':
272
327
def parse_spec(spec):
509
564
The command-line arguments, without the program name from argv[0]
565
These should already be decoded. All library/test code calling
566
run_bzr should be passing valid strings (don't need decoding).
511
568
Returns a command status or raises an exception.
633
690
from bzrlib.ui.text import TextUIFactory
634
691
## bzrlib.trace.enable_default_logging()
635
692
bzrlib.ui.ui_factory = TextUIFactory()
636
ret = run_bzr_catch_errors(argv[1:])
694
argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
695
ret = run_bzr_catch_errors(argv)
637
696
mutter("return code %d", ret)