/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 16:04:39 UTC
  • mfrom: (4387 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4405.
  • Revision ID: jelmer@samba.org-20090528160439-4z0xlrk5nejobm7q
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
lazy_import(globals(), """
36
36
import codecs
37
37
import errno
 
38
import threading
38
39
from warnings import warn
39
40
 
40
41
import bzrlib
682
683
 
683
684
    tracer = trace.Trace(count=1, trace=0)
684
685
    sys.settrace(tracer.globaltrace)
 
686
    threading.settrace(tracer.globaltrace)
685
687
 
686
688
    try:
687
689
        return exception_to_return_code(the_callable, *args, **kwargs)
950
952
    return ignore_pipe
951
953
 
952
954
 
953
 
def main(argv):
 
955
def main(argv=None):
 
956
    """Main entry point of command-line interface.
 
957
 
 
958
    :param argv: list of unicode command-line arguments similar to sys.argv.
 
959
        argv[0] is script name usually, it will be ignored.
 
960
        Don't pass here sys.argv because this list contains plain strings
 
961
        and not unicode; pass None instead.
 
962
 
 
963
    :return: exit code of bzr command.
 
964
    """
954
965
    import bzrlib.ui
955
966
    bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
956
967
        sys.stdin, sys.stdout, sys.stderr)
959
970
    if bzrlib.version_info[3] == 'final':
960
971
        from bzrlib import symbol_versioning
961
972
        symbol_versioning.suppress_deprecation_warnings(override=False)
962
 
    try:
963
 
        user_encoding = osutils.get_user_encoding()
964
 
        argv = [a.decode(user_encoding) for a in argv[1:]]
965
 
    except UnicodeDecodeError:
966
 
        raise errors.BzrError(("Parameter '%r' is unsupported by the current "
967
 
                                                            "encoding." % a))
 
973
    if argv is None:
 
974
        argv = osutils.get_unicode_argv()
 
975
    else:
 
976
        new_argv = []
 
977
        try:
 
978
            # ensure all arguments are unicode strings
 
979
            for a in argv[1:]:
 
980
                if isinstance(a, unicode):
 
981
                    new_argv.append(a)
 
982
                else:
 
983
                    new_argv.append(a.decode('ascii'))
 
984
        except UnicodeDecodeError:
 
985
            raise errors.BzrError("argv should be list of unicode strings.")
 
986
        argv = new_argv
968
987
    ret = run_bzr_catch_errors(argv)
969
988
    trace.mutter("return code %d", ret)
970
989
    return ret