HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/commands.cpython-39.pyc
a

�*�^��@s~ddlmZddlZddlZddlmZmZmZddlmZee	�d�ddl
mZddlmZdd	lm
Z
dd
lmZmZmZddlmZmZddlmZGd
d�dej�ZGdd�de�ZGdd�de�ZGdd�dej�Ze�ae�Zet_ dcdd�Z!dd�Z"dd�Z#dd�Z$dd�Z%d d!�Z&d"d#�Z'd$d%�Z(d&d'�Z)d(d)diiZ*d*d+�Z+ddd-d.�Z,ded/d0�Z-Gd1d2�d2ej.�Z/d3d4�Z0d5d6�Z1d7d8�Z2d9d:�Z3d;d<�Z4Gd=d>�d>e�Z5Gd?d@�d@e�Z6e6�e5_
dfdAdB�Z7dCdD�Z8dEdF�Z9dGdH�Z:dIdJ�Z;dKdL�Z<dgdMdN�Z=eefdOdP�Z>dQdR�Z?dSdT�Z@dUdV�ZAdhdWdX�ZBdYdZ�ZCd[d\�ZDGd]d^�d^e�ZEGd_d`�d`e�ZFGdadb�dbej�ZGeG�ZHdS)i�)�absolute_importN�)�i18n�option�osutils)�lazy_importzp
import errno

import breezy
from breezy import (
    cleanup,
    cmdline,
    debug,
    trace,
    ui,
    )
)�Hooks)�gettext)�Option)�disable_plugins�load_plugins�plugin_name)�errors�registry)�string_typesc@seZdZdZdS)�BzrOptionErrorzError in command line optionsN)�__name__�
__module__�__qualname__�_fmt�rr�1/usr/lib/python3/dist-packages/breezy/commands.pyr<src@s eZdZdZdd�Zdd�ZdS)�CommandAvailableInPluginFcCs||_||_||_dS�N)�plugin_metadata�cmd_name�provider)�selfrrrrrr�__init__Esz!CommandAvailableInPlugin.__init__cCs d|j|jd|jdf}|S)Nz�"%s" is not a standard brz command. 
However, the following official plugin provides this command: %s
You can install it by going to: %s�nameZurl)rr)rrrrr�__str__Ks��z CommandAvailableInPlugin.__str__N)rrr�internal_errorrr rrrrrAsrc@s$eZdZdZdd�Zedd��ZdS)�CommandInfozInformation about a command.cCs
||_dS)z$The list of aliases for the command.N��aliases)rr$rrrrYszCommandInfo.__init__cCs
||j�S)z2Factory to construct a CommandInfo from a command.r#)�klass�commandrrr�from_command]szCommandInfo.from_commandN)rrr�__doc__r�classmethodr'rrrrr"Vsr"c@s>eZdZdZdd�Zdd�Zedd��Zdd	d
�Zdd�Z	d
S)�CommandRegistryaSpecial registry mapping command names to command classes.

    :ivar overridden_registry: Look in this registry for commands being
        overridden by this registry.  This can be used to tell plugin commands
        about the builtin they're decorating.
    cCstj�|�d|_i|_dSr)r�Registryr�overridden_registry�_alias_dict�rrrrrkszCommandRegistry.__init__cCs|j�||�}tj�||�Sr)r-�getrr+)r�command_nameZ	real_namerrrr/qszCommandRegistry.getcCs|�d�rt|�S|SdS�N�cmd_)�
startswith�_unsquish_command_name)r0rrr�	_get_nameus
zCommandRegistry._get_nameFcCs�|j}|�|�}z|�|�}Wn@ty^d}|jrZz|j�|�}WntyXYn0Yn0t�|�}ztjj	|||||d�WnLty�t
�d|�t
�dtj
|j�t
�dtj
|j�Yn0|jD]}||j|<q�|S)aFUtility function to help register a command

        :param cmd: Command subclass to register
        :param decorate: If true, allow overriding an existing command
            of the same name; the old command is returned by this function.
            Otherwise it is an error to try to override an existing command.
        N)Zoverride_existing�infoz(Two plugins defined the same command: %rzNot loading the one in %rz.Previously this command was registered from %r)rr5r/�KeyErrorr,r"r'rr+�register�trace�warning�sys�modulesrr$r-)r�cmd�decorate�kZk_unsquishedZpreviousr6�arrrr8|s6

�

�
�
zCommandRegistry.registercCs<|�|�}tjj||||t|�d�|D]}||j|<q(dS)z�Register a command without loading its module.

        :param command_name: The primary name of the command.
        :param aliases: A list of aliases for the command.
        :module_name: The module that the command lives in.
        )r6N)r5rr+�
register_lazyr"r-)rr0r$Zmodule_name�keyr@rrrrA�s
�zCommandRegistry.register_lazyN)F)
rrrr(rr/�staticmethodr5r8rArrrrr*cs

!r*FcCst�||�S)z_Register a plugin command.

    Should generally be avoided in favor of lazy registration.
    )�plugin_cmdsr8)r=r>rrr�register_command�srEcCsd|�dd�S)Nr2�-�_��replace�r=rrr�_squish_command_name�srKcCs|dd��dd�S)N�rGrFrHrJrrrr4�sr4cCs<t��rdSddl}t|j�D]}t�|�q|j��dS)Nr)�builtin_command_registry�keysZbreezy.builtins�_scan_module_for_commands�builtinsr8Z_register_lazy_builtins)�breezy�	cmd_classrrr�_register_builtin_commands�srSccs(|j}|D]}|�d�r
||Vq
dSr1)�__dict__r3)�moduleZmodule_dictrrrrrO�s
rOcCs|�t��|�t��|S)z�Find commands from bzr's core and plugins.

    This is not the public interface, just the default hook called by
    all_command_names.
    )�update�builtin_command_names�plugin_command_names)�namesrrr�_list_bzr_commands�srZcCs>t�}tjdD](}||�}|durtdtj�|���q|S)z"Return a set of all command names.�
list_commandsNzhook %s returned None)�set�Command�hooks�AssertionErrorZ
get_hook_name)rY�hookrrr�all_command_names�s�racCst�t��S)z�Return list of builtin command names.

    Use of all_command_names() is encouraged rather than builtin_command_names
    and/or plugin_command_names.
    )rSrMrNrrrrrW�srWcCst��S)z:Returns command names from commands registered by plugins.)rDrNrrrrrX�srXZicZcics<t�}t�D]"}|�|�t|�}|�|j�qi�ddl}t|�D]�}|�d||�}d}|�	�}|D]r\}}	}
}}|dkr�||
|	7}qf|dkr�|t
|
|	||	�7}qf|dkr�|||7}qf|dkrf|d|
|	8}qf|�|<qD��t�|i��t�fd	d
��D�����sdS�dddk�r,dS�dd}
|
S)
z�Guess what command a user typoed.

    :param cmd_name: Command to search for
    :return: None if no command was found, name of a command otherwise
    rNg�deleterI�insertZequalg�������?c3s|]}�||fVqdSrr)�.0rB�Zcostsrr�	<genexpr>�z guess_command.<locals>.<genexpr>rLr)
r\ra�add�get_cmd_objectrVr$�patiencediff�sortedZPatienceSequenceMatcherZget_opcodes�max�_GUESS_OVERRIDESr/)rrYrr=rjZmatcherZdistanceZopcodesZopcode�l1�l2Zr1Zr2�	candidaterrer�
guess_command�s:


rqTcCs\zt||�WStyVt|�}|dur@t�td�||f��t�td�|��Yn0dS)z{Return the command object for a command.

    plugins_override
        If true, plugin commands can override builtins.
    Nz,unknown command "%s". Perhaps you meant "%s"zunknown command "%s")�_get_cmd_objectr7rqr�BzrCommandErrorr	)r�plugins_overriderprrrri&s��
�ricCs�d}tjdD]&}|||�}|dur|s|��sq6q|durf|rftjdD]}||�}|durLqfqL|durrt�tjdD]}||�q|t|dd�dur�||_|S)aSGet a command object.

    :param cmd_name: The name of the command.
    :param plugins_override: Allow plugins to override builtins.
    :param check_missing: Look up commands not found in the regular index via
        the get_missing_command hook.
    :return: A Command object instance
    :raises KeyError: If no command is found.
    N�get_command�get_missing_command�extend_command�
invoked_as)r]r^r
r7�getattrrx)rrt�
check_missingr=r`rrrrr9s"

rrc@seZdZdS)�NoPluginAvailableN)rrrrrrrr{_sr{cCs4zt|�\}}t|||��Wnty.Yn0dS)z,Probe for a plugin provider having cmd_name.N)�probe_for_providerrr{)rrrrrr�_try_plugin_providercs
r}c	Cs>tD],}z|�|�|fWSty.Yq0qt|��dS)z�Look for a provider for cmd_name.

    :param cmd_name: The command name.
    :return: plugin_metadata, provider for getting cmd_name.
    :raises NoPluginAvailable: When no provider can supply the plugin.
    N)�command_providers_registry�plugin_for_commandr{)rrrrrr|lsr|cCs,zt�|�}Wnty Yn0|�S|S)zGet a command from bzr's core.)rMr/r7)�cmd_or_NonerrRrrr�_get_bzr_command|sr�cCs.|dur|Sddlm}|�|�}|r*|SdS)z(Lookup a command that is a shell script.Nr)�ExternalCommand)Zbreezy.externalcommandr�Zfind_command)r�rr��cmd_objrrr�_get_external_command�s
r�cCsXzt�|��WSty Yn0t��D](}t�|�}||jvr*t�|��Sq*|S)z!Get a command from brz's plugins.)rDr/r7rNZget_infor$)r�rrBr6rrr�_get_plugin_command�s

r�c@s�eZdZdZgZgZgZdZdZdZ	dZ
dd�Zdd	�Zd
d�Z
dd
�Zdd�Zd*dd�Zedd��Zdd�Zd+dd�Zdd�Zdd�Zd,dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�ZdS)-r]a�	Base class for commands.

    Commands are the heart of the command-line brz interface.

    The command object mostly handles the mapping of command-line
    parameters into one or more breezy operations, and of the results
    into textual output.

    Commands normally don't have any state.  All their arguments are
    passed in to the run method.  (Subclasses may take a different
    policy if the behaviour of the instance needs to depend on e.g. a
    shell plugin and not just its Python class.)

    The docstring for an actual command should give a single-line
    summary, then a complete description of the command.  A grammar
    description will be inserted.

    :cvar aliases: Other accepted names for this command.

    :cvar takes_args: List of argument forms, marked with whether they are
        optional, repeated, etc.  Examples::

            ['to_location', 'from_branch?', 'file*']

        * 'to_location' is required
        * 'from_branch' is optional
        * 'file' can be specified 0 or more times

    :cvar takes_options: List of options that may be given for this command.
        These can be either strings, referring to globally-defined options, or
        option objects.  Retrieve through options().

    :cvar hidden: If true, this command isn't advertised.  This is typically
        for commands intended for expert users.

    :cvar encoding_type: Command objects will get a 'outf' attribute, which has
        been setup to properly handle encoding of unicode strings.
        encoding_type determines what will happen when characters cannot be
        encoded:

        * strict - abort if we cannot decode
        * replace - put in a bogus character (typically '?')
        * exact - do not encode sys.stdout

        NOTE: by default on Windows, sys.stdout is opened as a text stream,
        therefore LF line-endings are converted to CRLF.  When a command uses
        encoding_type = 'exact', then sys.stdout is forced to be a binary
        stream, and line-endings will not mangled.

    :cvar invoked_as:
        A string indicating the real name under which this command was
        invoked, before expansion of aliases.
        (This may be None if the command was constructed and run in-process.)

    :cvar hooks: An instance of CommandHooks.

    :cvar __doc__: The help shown by 'brz help command' for this command.
        This is set by assigning explicitly to __doc__ so that -OO can
        be used::

            class Foo(Command):
                __doc__ = "My help goes here"
    �strictNTFcCsg|_|��dS)z&Construct an instance of this command.N)�supported_std_options�
_setup_runr.rrrr�szCommand.__init__cOs|jj|g|�Ri|��dS)zwRegister a function to call after self.run returns or raises.

        Functions will be called in LIFO order.
        N)�_exit_stack�callback)rZcleanup_func�args�kwargsrrr�add_cleanup�szCommand.add_cleanupcCs|j��dS)a�Execute and empty pending cleanup functions immediately.

        After cleanup_now all registered cleanups are forgotten.  add_cleanup
        may be called again after cleanup_now; these cleanups will be called
        after self.run returns or raises (or when cleanup_now is next called).

        This is useful for releasing expensive or contentious resources (such
        as write locks) before doing further work that does not require those
        resources (such as writing results to self.outf). Note though, that
        as it releases all resources, this may release locks that the command
        wants to hold, so use should be done with care.
        N)r��closer.rrr�cleanup_now�s
zCommand.cleanup_nowcCs|j�|�Sr)r��
enter_context)r�cmrrrr�szCommand.enter_contextcCs�d|��d}|jD]x}|��}|ddvr@|dd�d}nB|ddkrbd|dd�d	}n |dd
kr�d|dd�d}||d7}q|dd�}|S)zeReturn single-line grammar for this command.

        Only describes arguments, not options.
        zbrz � ���)�$�+Nz...�?�[�]�*z...])r�
takes_args�upper)r�sZanamerrr�_usages
zCommand._usagecCs�|jrt��|��}|r&|�|�}ntd�}|�|�\}}}d|vrR|�d�}	n|��}	d}
|
td�|f7}
|	�d�dkr�|
td�|	f7}
n|
td�|	f7}
|
d7}
t	�
d	d
�t|���
��D��}|��}|s�|�d�dkr�|�d
dd�}|�d��r |
td�|td�d�f7}
n|
|7}
|
d7}
|�r�d|v�rj|�d�}
d�|
���}
|
td�|
f7}
|�r�|D]$}||v�rt|
d|||f7}
�qt|
d7}
n|
td�|��7}
|j�r�|
td�7}
|
d�|j�d7}
|��}|du�r|
td�|7}
|�|�}|�r||�sb|�rbg}|D]6}|dk�r@|�|�ntd��||�}|�|��q&|}|
td�d�|�d7}
|�r�ddl}|j�|
�}
|
S)a�Return a text string with help for this command.

        :param additional_see_also: Additional help topics to be
            cross-referenced.
        :param plain: if False, raw help (reStructuredText) is
            returned instead of plain text.
        :param see_also_as_links: if True, convert items in 'See also'
            list to internal links (used by bzr_man rstx generator)
        :param verbose: if True, display the full help, otherwise
            leave out the descriptive sections and just display
            usage help (e.g. Purpose, Usage, Options) with a
            message explaining how to obtain full help.
        zNo help for this command.ZUsage�z
:Purpose: %s
�
rz:Usage:
%s
z
:Usage:   %s
cSsg|]\}}|�qSrr�rdr?�vrrr�
<listcomp>Mrgz)Command.get_help_text.<locals>.<listcomp>z
  --1.14  r�z	 format:
z format::

rzOptions:z:Options:%szoptions:Nz
  z:Description:
  %s

z:%s:
%s
z0See brz help %s for more details and examples.

z:Aliases:  z, z:From:     plugin "%s"
Ztopicsz:doc:`{0} <{1}-help>`z
:See also: %s)�l10nrZinstall�helpr	�_get_help_parts�popr��findr�
get_optparserrk�options�itemsZformat_option_helprIr3�len�join�
splitlinesrr$r
�get_see_also�append�formatZbreezy.help_topicsZhelp_topicsZhelp_as_plain_text)rZadditional_see_alsoZplainZsee_also_as_links�verbose�docZpurpose�sections�order�usage�result�parserr��text�labelr
�see_alsoZsee_also_links�itemZ	link_textrQrrr�
get_help_texts|� 



�


�zCommand.get_help_textc	Cs�dd�}|����}|�d�}i}g}d\}}|D]�}|�d�rx|�d�rxt|�dkrx|||||�|dd�d	}}q2|d
ur�t|�dkr�|d��s�|||||�d
|}}q2t|�dkr�|d|7}q2|}q2|||||�|||fS)aSplit help text into a summary and named sections.

        :return: (summary,sections,order) where summary is the top line and
            sections is a dictionary of the rest indexed by section name.
            order is the order the section appear in the text.
            A section starts with a heading line of the form ":xxx:".
            Indented text on following lines is the section value.
            All text found outside a named section is assigned to the
            default section which is given the key of None.
        cSs@t|�dkr<||vr*||d|7<n|�|�|||<dS)Nrr�)r�r�)r�r�r��sectionrrr�save_section�s

z-Command._get_help_parts.<locals>.save_sectionr)Nr��:�rr�r�Nr�)�rstripr�r�r3�endswithr��isspace)	r�r��linesZsummaryr�r�r�r��linerrrr��s(
 
�zCommand._get_help_partscCs|��S)z*Return the commands help topic - its name.)rr.rrr�get_help_topic�szCommand.get_help_topiccCs&tt|dg��}|r|�|�t|�S)aLReturn a list of help topics that are related to this command.

        The list is derived from the content of the _see_also attribute. Any
        duplicates are removed and the result is in lexical order.
        :param additional_terms: Additional help topics to cross-reference.
        :return: A list of help topics.
        Z	_see_also)r\ryrVrk)rZadditional_termsr�rrrr��s
zCommand.get_see_alsocCsZtj��}t|�}|jD]<}t|t�r2tjj|}|||j	<|j	|vr|j
�|j	�q|S)zdReturn dict of valid options for this command.

        Maps from long option name to option object.)r
ZSTD_OPTIONS�copyr\�
takes_options�
isinstancerrZOPTIONSrr�r�)r�rZ	std_names�orrrr��s




zCommand.optionscCstjj|jd�|_dS)z:Return a file linked to stdout, which has proper encoding.)�
encoding_typeN)�ui�
ui_factoryZmake_output_streamr��outfr.rrr�_setup_outf�s�zCommand._setup_outfc
	CsLt|||�\}}|��d|vr4|j�|���dSd|vrT|j�|jdd��dSt�tj�d|j	vrxt�
�|d<nd|vr�|d=d|j	vr�t��|d<nd|vr�|d=t|�
�|j|�}i}|��D]\}}|||�dd	�<q�|��}	|	�|�z0|jfi|	��Wtjjd
tjvd�t�d�Stjjd
tjvd�t�d�0dS)
z@Parse the command line and run with extra aliases in alias_argv.r�rr�F)r�r��quietrFrG�bytes)ZdisplayN)�
parse_argsr�r��writer�r9Zset_verbosity_levelr�_verbosity_levelr�Z
is_verboseZis_quiet�_match_argformrr�r�rIr�rV�runr�r�Zlog_transport_activity�debug�debug_flags)
r�argv�
alias_argvr��optsZcmdargsZcmdoptsr?r�Zall_cmd_argsrrr�run_argv_aliases�sL


�
����zCommand.run_argv_aliasescs�j���fdd�}|�_dS)aDWrap the defined run method on self with a cleanup.

        This is called by __init__ to make the Command be able to be run
        by just calling run(), as it could be before cleanups were added.

        If a different form of cleanups are in use by your Command subclass,
        you can override this method.
        c	s�tjdD]}|��q
znt���:�_�|i|��Wd�WtjdD]}|��qLS1sb0YWtjdD]}|��qxntjdD]}|��q�0dS)N�pre_command�post_command)r]r^Zcleanup�	ExitStackr�)r�r�r`�Z	class_runrrrr�s

��zCommand._setup_run.<locals>.runN)r�)rr�rr�rr�s		zCommand._setup_runcCstd|����dS)a�Actually run the command.

        This is invoked with the options and arguments bound to
        keyword parameters.

        Return 0 or None if the command was successful, or a non-zero
        shell error code if not.  It's OK for this method to allow
        an exception to raise up.

        This method is automatically wrapped by Command.__init__ with a
        ExitStack, stored as self._exit_stack. This can be used
        via self.add_cleanup to perform automatic cleanups at the end of
        run().

        The argument for run are assembled by introspection. So for instance,
        if your command takes an argument files, you would declare::

            def run(self, files=None):
                pass
        zno implementation of command %rN)�NotImplementedErrorrr.rrrr�s�zCommand.runcCs$ddlm}|jtjurdS||�S)z#Return help message for this class.r)�getdocN)�inspectr�r(r])rr�rrrr�1szCommand.helpcCs
t�|�S)z�Returns the gettext function used to translate this command's help.

        Commands provided by plugins should override this to use their
        own i18n system.
        )rZgettext_per_paragraph)r�messagerrrr	8szCommand.gettextcCst|jj�S)z�Return the canonical name for this command.

        The name under which it was actually invoked is available in invoked_as
        )r4�	__class__rr.rrrr@szCommand.namecCs
t|j�S)z�Get the name of the plugin that provides this command.

        :return: The name of the plugin or None if the command is builtin.
        )r
rr.rrrr
GszCommand.plugin_name)NTFT)N)N)rrrr(r$r�r�r�rxr�Zhiddenrr�r�r�r�r�rCr�r�r�r�r�r�r�r�r�r	rr
rrrrr]�s:?�
u
(


(r]c@seZdZdZdd�ZdS)�CommandHooksz5Hooks related to Command object creation/enumeration.cCsft�|dd�|�ddd�|�ddd�|�d	d
d�|�ddd�|�d
dd�|�ddd�dS)z�Create the default hooks.

        These are all empty initially, because by default nothing should get
        notified.
        zbreezy.commandsz
Command.hooksrwz�Called after creating a command object to allow modifications such as adding or removing options, docs etc. Called with the new breezy.commands.Command object.)r�
ruahCalled when creating a single command. Called with (cmd_or_None, command_name). get_command should either return the cmd_or_None parameter, or a replacement Command object that should be used for the command. Note that the Command.hooks hooks are core infrastructure. Many users will prefer to use breezy.commands.register_command or plugin_cmds.register_lazy.)r�rvz�Called when creating a single command if no command could be found. Called with (command_name). get_missing_command should either return None, or a Command object to be used for the command.r[z�Called when enumerating commands. Called with a set of cmd_name strings for all the commands found so far. This set  is safe to mutate - e.g. to remove a command. list_commands should return the updated set of command names.r�zDCalled prior to executing a command. Called with the command object.)r��r�zACalled after executing a command. Called with the command object.N)rrZadd_hookr.rrrrRs>��	����zCommandHooks.__init__N)rrrr(rrrrrr�Osr�cCs�t�dd�t|�����D��}|dur2||}n|}z|�|�\}}Wn tyht�t	d���Yn0t
dd�|j��D��}||fS)aParse command line.

    Arguments and options are parsed at this level before being passed
    down to specific command handlers.  This routine knows, from a
    lookup table, something about the available options, what optargs
    they take, and which commands will accept them.
    cSsg|]\}}|�qSrrr�rrrr��rgzparse_args.<locals>.<listcomp>Nz$Only ASCII permitted in option namescss&|]\}}|tjjur||fVqdSr)rZOptionParserZ
DEFAULT_VALUEr�rrrrf�s
�zparse_args.<locals>.<genexpr>)rr�rkr�r�r��UnicodeEncodeErrorrrsr	�dictrT)r&r�r�r�r�r�r�rrrr��s	�
�
r�cCshi}|D�]8}|dd�}|ddkr:|r8|�d�||<q|ddkrr|rd|dd�||d<g}nd||d<q|ddkr�|s�t�td��||�����n|dd�||d<g}q|ddk�rt|�d	kr�t�td��||�����|dd�||d<g|dd�<q|}|�s4t�td
��||�����q|�d�||<q|�rdt�td��||d���|S)Nr�r�rr�Z_listr�z#command {0!r} needs one or more {1}r�r�z#command {0!r} requires argument {1}z"extra argument to command {0}: {1})r�rrsr	r�r�r�)r=r�r�ZargdictZap�argnamerrrr��sX
��������r�cOs�ddl}|��}z|jj}Wnty4|j}Yn0|tjd<|��z(t|g|�Ri|��W|�	�|�
�S|�	�|�
�0dS)NrZCOVERAGE_PROCESS_START)�coverageZCoverage�config�config_file�AttributeError�os�environ�start�exception_to_return_code�stop�save)�the_callabler�r�r�Zcovr�rrr�apply_coveraged�s"
��r�c
	Os�ddl}ddl}ddl}|��\}}z�|�|�}z*|jt|g|�Ri|��pNd}W|��n
|��0|j�	|�}	|	�
�|	�d�|	�d�|Wt
�|�t
�|�St
�|�t
�|�0dS)NrZcum�)�hotshot�tempfileZ
hotshot.statsZmkstempZProfileZruncallr�r��stats�loadZ
strip_dirsZ
sort_statsZprint_statsr��remove)
r�r�r�r�r�ZpffilenoZpfnameZprof�retr�rrr�apply_profiled�s2
��



��
rc	Ospz||i|��WSttfyjt��}t�|tj�}tj�	d�rbt
d�ddl}|�|d�|YS0dS)z�UI level helper for profiling and coverage.

    This transforms exceptions into a return value of 3. As such its only
    relevant to the UI layer, and should never be called where catching
    exceptions may be desirable.
    ZBRZ_PDBz**** entering debuggerrNr�)
�KeyboardInterrupt�	Exceptionr;�exc_infor9�report_exception�stderrr�r�r/�print�pdbZpost_mortem)r�r�r�rZexitcoderrrrr��sr�cOs`ddlm}|t|g|�Ri|��\}}|��|durB|��n|�|�t�td�|�|S)Nr)�profilezProfile data written to "%s".)	Z
breezy.lsprofr	r��sortZpprintr�r9Znoter	)�filenamer�r�r�r	rr�rrr�apply_lsprofileds��


rcCs6|durddl}|j��}|�|�}|r2t�|�SdS)aReturn an expanded alias, or None if no alias exists.

    cmd
        Command to be checked for an alias.
    config
        Used to specify an alternative config to use,
        which is especially useful for testing.
        If it is unspecified, the global config will be used.
    Nr)Z
breezy.configr�ZGlobalConfig�	get_aliasZcmdline�split)r=r�rQ�aliasrrrr
s



r
c
Cs.t�dtj�t|�}t�d|�d}}}}}}}	d}
g}d}g}
|t|�k�rt||}|dkrtd}n�|dkr�d}n�|d	kr�d}||d
}
|d
7}n�|dkr�d}n�|dkr�d}	n�|d
kr�d}n�|dkr�d}n�|dk�r||d
tjd<|d
7}nh|dk�rd}nX|dk�rnL|�d��r@t	j
�|dd��n*|�d��r`|
�|dd��n
|�|�|d
7}qPt�
�j}|�|
�t	��|�s�|�n|�|}|�s�td��g�dS|ddk�r�td��g�dSd}|	�s
t|d�}|�r
|�d�|d<|�d�}t||d�}|�r.d|_|j}||g}z�tj}dt_|�rt|�r`t�d�t|
|g|�R�}nH|�r�|�r�t�d�t|g|�R�}n |�r�t|g|�R�}n||�}|�p�dWdt	j
v�r�tjddd�|t_|��S|t_|��n*dt	j
v�rtjddd�|t_|��0dS)a�Execute a command.

    :param argv: The command-line arguments, without the program name from
        argv[0] These should already be decoded. All library/test code calling
        run_bzr should be passing valid strings (don't need decoding).
    :param load_plugins: What function to call when triggering plugin loading.
        This function should take no arguments and cause all plugins to be
        loaded.
    :param disable_plugins: What function to call when disabling plugin
        loading. This function should take no arguments and cause all plugin
        loading to be prohibited (so that code paths in your application that
        know about some plugins possibly being present will fail to import
        those plugins even if they are installed.)
    :return: Returns a command exit code or raises an exception.

    Special master options: these must come before the command because
    they control how the command is interpreted.

    --no-plugins
        Do not load plugin modules at all

    --no-aliases
        Do not allow aliases

    --builtin
        Only use builtin commands.  (Plugins are still allowed to change
        other behaviour.)

    --profile
        Run under the Python hotshot profiler.

    --lsprof
        Run under the Python lsprof profiler.

    --coverage
        Generate code coverage report

    --concurrency
        Specify the number of processes that can be run concurrently
        (selftest).
    zbreezy version: zbrz arguments: %rFNrz	--profileTz--lsprofz
--lsprof-filerz--no-pluginsz--no-aliasesz	--no-l10nz	--builtinz
--concurrencyZBRZ_CONCURRENCYz
--coveragez--profile-importsz-Dr�z-Or�z	--version�version)rtz/--coverage ignored, because --lsprof is in use.z0--coverage ignored, because --profile is in use.ZmemoryzProcess status after command:)Zshort)r9�mutterrQ�__version__�_specified_or_unicode_argvr�r�r�r3r�r�rhr�Zget_global_state�cmdline_overridesZ
_from_cmdlineZset_debug_flags_from_configrir�r
r�r�rr�r:rrr�Zdebug_memoryZ_reset)r�rrZ
opt_lsprofZopt_profileZopt_no_pluginsZopt_builtinZopt_coverageZopt_no_l10nZopt_no_aliasesZopt_lsprof_fileZ	argv_copy�iZoverride_configr@rr�r=r�r�Zrun_argvZsaved_verbosity_levelrrrr�run_bzr+s�*��









��
�
�rcs�fdd�}|S)z0Decorator that suppresses pipe/interrupt errors.c
s�z�|i|��}tj��|WSty|}zFt|dd�dur@�|jtjkrhtjdksf|jdtjfvrh�WYd}~nd}~0t	y�Yn0dS)N�errnoZwin32r)
r;�stdout�flush�IOErrorryrZEPIPE�platformZEINVALr)r�r�r��e��funcrr�ignore_pipe�s
z$display_command.<locals>.ignore_piper)rrrrr�display_command�sr cCsfttjdvrdStj�dtd�tj�dtd�tj�dtd�tj�dtd�tj�dtd�dS)	z/Install the hooks to supply bzr's own commands.r[Nzbzr commandsruzbzr plugin commandszbzr external command lookuprvzbzr plugin-provider-db check)rZr]r^Zinstall_named_hookr�r�r�r}rrrr�install_bzr_command_hooks�s$
�
�
�
��r!c	Cs~|durt��Sg}zD|D]:}t|t�s6td|f��t|t�rJ|�d�}|�|�qWn ttfyxt	�
d��Yn0|S)Nznot native str or unicode: %r�asciiz'argv should be list of unicode strings.)rZget_unicode_argvr�r�
ValueErrorr��decoder��UnicodeDecodeErrorr�BzrError)r�Znew_argvr@rrrr�s


rcCs2|dur|dd�}t�t|�}t�d|�|S)a�Main entry point of command-line interface.

    Typically `breezy.initialize` should be called first.

    :param argv: list of unicode command-line arguments similar to sys.argv.
        argv[0] is script name usually, it will be ignored.
        Don't pass here sys.argv because this list contains plain strings
        and not unicode; pass None instead.

    :return: exit code of brz command.
    Nrzreturn code %d)rS�run_bzr_catch_errorsr9r)r�rrrr�main�sr(cCst�tt|�S)z�Run a bzr command with parameters as described by argv.

    This function assumed that that UI layer is setup, that symbol deprecations
    are already applied, and that unicode decoding has already been performed
    on argv.
    )r!r�r)r�rrrr'sr'c
Csvt�z
t|�WStyp}zHt|ttf�s:t|dd�sZt�t	�
�t	j�WYd}~dS�WYd}~n
d}~00dS)z�Run brz and report user errors, but let internal errors propagate.

    This is used for the test suite, and might be useful for other programs
    that want to wrap the commandline interface.
    r!TN�)r!rrr��OSErrorrryr9rr;rr)r�rrrr�run_bzr_catch_user_errorss

�r+c@s eZdZdZdd�Zdd�ZdS)�HelpCommandIndexz+A index for bzr help that returns commands.cCs
d|_dS)Nz	commands/)�prefixr.rrrr4szHelpCommandIndex.__init__cCsT|r"|�|j�r"|t|j�d�}zt|dd�}WntyHgYS0|gSdS)z�Search for topic amongst commands.

        :param topic: A topic to search for.
        :return: A list which is either empty or contains a single
            Command entry.
        NF)rz)r3r-r�rrr7)rZtopicr=rrr�
get_topics7s
zHelpCommandIndex.get_topicsN)rrrr(rr.rrrrr,1sr,c@seZdZdZdd�ZdS)�Providerz(Generic class to be overriden by pluginscCst�dS)z�Takes a command and returns the information for that plugin

        :return: A dictionary with all the available information
            for the requested plugin
        N)r�)rrrrrrKszProvider.plugin_for_commandN)rrrr(rrrrrr/Hsr/c@seZdZdZdd�ZdS)�ProvidersRegistryz6This registry exists to allow other providers to existccs|��D]\}}|VqdSr)r�)rrBrrrr�__iter__WszProvidersRegistry.__iter__N)rrrr(r1rrrrr0Tsr0)F)T)TT)N)N)N)IZ
__future__rr�r;r�rrrr�globalsr^rr	r
Zpluginrrr
rrZsixishrrsrrr�objectr"r+r*rDrMr,rErKr4rSrOrZrarWrXrmrqrirrr&r{r}r|r�r�r�r]r�r�r�r�rr�rr
rr r!rr(r'r+r,r/r0r~rrrr�<module>s~	

H
	

�(

&	
3/
0