/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: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
# TODO: probably should say which arguments are candidates for glob
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
403
404
        return s
404
405
 
405
406
    def get_help_text(self, additional_see_also=None, plain=True,
406
 
                      see_also_as_links=False):
 
407
                      see_also_as_links=False, verbose=True):
407
408
        """Return a text string with help for this command.
408
409
 
409
410
        :param additional_see_also: Additional help topics to be
412
413
            returned instead of plain text.
413
414
        :param see_also_as_links: if True, convert items in 'See also'
414
415
            list to internal links (used by bzr_man rstx generator)
 
416
        :param verbose: if True, display the full help, otherwise
 
417
            leave out the descriptive sections and just display
 
418
            usage help (e.g. Purpose, Usage, Options) with a
 
419
            message explaining how to obtain full help.
415
420
        """
416
421
        doc = self.help()
417
422
        if doc is None:
446
451
            result += options
447
452
        result += '\n'
448
453
 
449
 
        # Add the description, indenting it 2 spaces
450
 
        # to match the indentation of the options
451
 
        if sections.has_key(None):
452
 
            text = sections.pop(None)
453
 
            text = '\n  '.join(text.splitlines())
454
 
            result += ':%s:\n  %s\n\n' % ('Description',text)
 
454
        if verbose:
 
455
            # Add the description, indenting it 2 spaces
 
456
            # to match the indentation of the options
 
457
            if sections.has_key(None):
 
458
                text = sections.pop(None)
 
459
                text = '\n  '.join(text.splitlines())
 
460
                result += ':%s:\n  %s\n\n' % ('Description',text)
455
461
 
456
 
        # Add the custom sections (e.g. Examples). Note that there's no need
457
 
        # to indent these as they must be indented already in the source.
458
 
        if sections:
459
 
            for label in order:
460
 
                if sections.has_key(label):
461
 
                    result += ':%s:\n%s\n\n' % (label,sections[label])
 
462
            # Add the custom sections (e.g. Examples). Note that there's no need
 
463
            # to indent these as they must be indented already in the source.
 
464
            if sections:
 
465
                for label in order:
 
466
                    if sections.has_key(label):
 
467
                        result += ':%s:\n%s\n' % (label,sections[label])
 
468
                result += '\n'
 
469
        else:
 
470
            result += ("See bzr help %s for more details and examples.\n\n"
 
471
                % self.name())
462
472
 
463
473
        # Add the aliases, source (plug-in) and see also links, if any
464
474
        if self.aliases:
595
605
        if 'help' in opts:  # e.g. bzr add --help
596
606
            sys.stdout.write(self.get_help_text())
597
607
            return 0
 
608
        if 'usage' in opts:  # e.g. bzr add --usage
 
609
            sys.stdout.write(self.get_help_text(verbose=False))
 
610
            return 0
598
611
        trace.set_verbosity_level(option._verbosity_level)
599
612
        if 'verbose' in self.supported_std_options:
600
613
            opts['verbose'] = trace.is_verbose()
764
777
 
765
778
    tracer = trace.Trace(count=1, trace=0)
766
779
    sys.settrace(tracer.globaltrace)
 
780
    threading.settrace(tracer.globaltrace)
767
781
 
768
782
    try:
769
783
        return exception_to_return_code(the_callable, *args, **kwargs)
1032
1046
    return ignore_pipe
1033
1047
 
1034
1048
 
1035
 
def main(argv):
 
1049
def main(argv=None):
 
1050
    """Main entry point of command-line interface.
 
1051
 
 
1052
    :param argv: list of unicode command-line arguments similar to sys.argv.
 
1053
        argv[0] is script name usually, it will be ignored.
 
1054
        Don't pass here sys.argv because this list contains plain strings
 
1055
        and not unicode; pass None instead.
 
1056
 
 
1057
    :return: exit code of bzr command.
 
1058
    """
1036
1059
    import bzrlib.ui
1037
1060
    bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
1038
1061
        sys.stdin, sys.stdout, sys.stderr)
1041
1064
    if bzrlib.version_info[3] == 'final':
1042
1065
        from bzrlib import symbol_versioning
1043
1066
        symbol_versioning.suppress_deprecation_warnings(override=False)
1044
 
    try:
1045
 
        user_encoding = osutils.get_user_encoding()
1046
 
        argv = [a.decode(user_encoding) for a in argv[1:]]
1047
 
    except UnicodeDecodeError:
1048
 
        raise errors.BzrError(("Parameter '%r' is unsupported by the current "
1049
 
                                                            "encoding." % a))
 
1067
    if argv is None:
 
1068
        argv = osutils.get_unicode_argv()
 
1069
    else:
 
1070
        new_argv = []
 
1071
        try:
 
1072
            # ensure all arguments are unicode strings
 
1073
            for a in argv[1:]:
 
1074
                if isinstance(a, unicode):
 
1075
                    new_argv.append(a)
 
1076
                else:
 
1077
                    new_argv.append(a.decode('ascii'))
 
1078
        except UnicodeDecodeError:
 
1079
            raise errors.BzrError("argv should be list of unicode strings.")
 
1080
        argv = new_argv
1050
1081
    ret = run_bzr_catch_errors(argv)
1051
1082
    trace.mutter("return code %d", ret)
1052
1083
    return ret