§
    ôc­1  ã                   óØ   — d dl Z d dlZd dlZd dlZd dlZ ej        e¦  «        ZdZdZ	dd„Z
d„ Zd„ Zd„ Zdd„Z e¦   «         Zej        ddd	dddd
fd„Z	 dd„Zej        ddd	dddfd„ZdS )é    Né   é   c                 óþ   — |€dS t          | j        t          ¦  «        r| j                             d¦  «        n| j        }|r*|d         |k    rt	          |dk     p
|t
          k    ¦  «        S t	          |dk    ¦  «        S )zÝ
    Return True if the given exit code from running a command corresponds to an error. If a Borg
    local path is given and matches the process' command, then treat exit code 1 as a warning
    instead of an error.
    NFú r   )Ú
isinstanceÚargsÚstrÚsplitÚboolÚBORG_ERROR_EXIT_CODE)ÚprocessÚ	exit_codeÚborg_local_pathÚcommands       ú3/usr/lib/python3/dist-packages/borgmatic/execute.pyÚexit_code_indicates_errorr      s‚   € ð ÐØˆuå)3°G´LÅ#Ñ)FÔ)FÐXˆgŒl× Ò  Ñ%Ô%Ð%ÈGÌL€Gàð H˜7 1œ:¨Ò8Ð8Ý�I ’MÐF YÕ2FÒ%FÑGÔGÐGå�	˜Q’ÑÔÐó    c                 óx   — t          | j        t          ¦  «        r| j        nd                     | j        ¦  «        S )zw
    Given a process as an instance of subprocess.Popen, return the command string that was used to
    invoke it.
    r   )r   r   r	   Újoin)r   s    r   Úcommand_for_processr      s/   € õ
 & g¤lµCÑ8Ô8ÐTˆ7Œ<ˆ<¸c¿hºhÀwÄ|Ñ>TÔ>TÐTr   c                 ó0   — | j         |v r| j        n| j         S )zë
    Given a process as an instance of subprocess.Popen and a sequence of stdouts to exclude, return
    either the process's stdout or stderr. The idea is that if stdout is excluded for a process, we
    still have stderr to log.
    )ÚstdoutÚstderr)r   Úexclude_stdoutss     r   Úoutput_buffer_for_processr   '   s   € ð %œ^¨Ð>Ð>ˆ7Œ>ˆ>ÀGÄNÐRr   c                 óâ  ‡— t          j        t          ¦  «        }ˆfd„| D ¦   «         }t          |                     ¦   «         ¦  «        }t          j        t          ¦  «        }d}	 |�rQt	          j        |g g ¦  «        \  }	}
}
|	D �]3}|                     |¦  «        }|rW|                     ¦   «         �C| D ]@}|                     ¦   «         €*|j        r#|j        |vr|                     |j        ¦  «         ŒA	 | 	                    ¦   «          
                    ¦   «                              ¦   «         }|r|sn„||         }|                     |¦  «         t          |¦  «        t          k    r|                     d¦  «         |€||                              |¦  «         nt                               ||¦  «         ŒÁ�Œ5|s�nd}| D �]	}|r|                     ¦   «         n|                     ¦   «         }|€d}t%          |||¦  «        rÇt'          |‰¦  «        }|r||         ng }t          |¦  «        t          k    r|                     dd¦  «         | D ]D}|                     ¦   «         €.|j                             d¦  «         |                     ¦   «          ŒEt/          j        |t3          |¦  «        d                     |¦  «        ¦  «        ‚�Œ�Œi|rd„ |                     ¦   «         D ¦   «         S dS )	a  
    Given a sequence of subprocess.Popen() instances for multiple processes, log the output for each
    process with the requested log level. Additionally, raise a CalledProcessError if a process
    exits with an error (or a warning for exit code 1, if that process does not match the Borg local
    path).

    If output log level is None, then instead of logging, capture output for each process and return
    it as a dict from the process to its output.

    For simplicity, it's assumed that the output buffer for each process is its stdout. But if any
    stdouts are given to exclude, then for any matching processes, log from their stderr instead.

    Note that stdout for a process can be None if output is intentionally not captured. In which
    case it won't be logged.
    c                 óN   •— i | ]!}|j         s|j        ¯t          |‰¦  «        |“Œ"S © )r   r   r   )Ú.0r   r   s     €r   ú
<dictcomp>zlog_outputs.<locals>.<dictcomp>B   sI   ø€ ð !ð !ð !àØŒ>ð!ð %œ^ð!Ý! '¨?Ñ;Ô;¸Wð!ð !ð !r   TNr   Fz...ú
c                 ó@   — i | ]\  }}|d                       |¦  «        “ŒS )r!   )r   )r   r   Úoutput_liness      r   r    zlog_outputs.<locals>.<dictcomp>’   s7   € ð 
ð 
ð 
Ù1F°¸,ˆG�T—Y’Y˜|Ñ,Ô,ð
ð 
ð 
r   )ÚcollectionsÚdefaultdictÚlistÚkeysÚselectÚgetÚpollr   ÚappendÚreadlineÚrstripÚdecodeÚlenÚERROR_OUTPUT_MAX_LINE_COUNTÚpopÚloggerÚlogÚwaitr   r   ÚinsertÚreadÚkillÚ
subprocessÚCalledProcessErrorr   r   Úitems)Ú	processesr   Úoutput_log_levelr   Úbuffer_last_linesÚprocess_for_output_bufferÚoutput_buffersÚcaptured_outputsÚstill_runningÚready_buffersÚ_Úready_bufferÚready_processÚother_processÚlineÚ
last_linesr   r   Úoutput_buffers    `                 r   Úlog_outputsrJ   0   sm  ø€ õ" $Ô/µÑ5Ô5Ðð!ð !ð !ð !à ð!ñ !ô !Ðõ
 Ð3×8Ò8Ñ:Ô:Ñ;Ô;€NÝ"Ô.­tÑ4Ô4ÐØ€MðCØñ "	;Ý$*¤M°.À"ÀbÑ$IÔ$IÑ!ˆ]˜A˜qà -ð ;ñ ;�Ø 9× =Ò =¸lÑ KÔ K�ð
 !ð H ]×%7Ò%7Ñ%9Ô%9Ð%EØ)2ð Hð H˜à)×.Ò.Ñ0Ô0Ð8Ø -Ô 4ð 9à -Ô 4¸NÐ JÐ Jð +×1Ò1°-Ô2FÑGÔGÐGøð;Ø'×0Ò0Ñ2Ô2×9Ò9Ñ;Ô;×BÒBÑDÔD�DØð  }ð Øð "3°<Ô!@�JØ×%Ò% dÑ+Ô+Ð+Ý˜:‘”Õ)DÒDÐDØ"Ÿš qÑ)Ô)Ð)à'Ð/Ø(¨Ô7×>Ò>¸tÑDÔDÐDÐDåŸ
š
Ð#3°TÑ:Ô:Ð:ð;ñ ð ð 	Ùàˆà ð 	ñ 	ˆGØ*8ÐL˜Ÿš™œ˜¸g¿lºl¹n¼nˆIàÐ Ø $�õ )¨°)¸_ÑMÔMð õ !:¸'À?Ñ SÔ S�àANÐVÐ.¨}Ô=Ð=ÐTV�
Ý�z‘?”?Õ&AÒAÐAØ×%Ò% a¨Ñ/Ô/Ð/ð &/ð -ð -�MØ$×)Ò)Ñ+Ô+Ð3Ø%Ô,×1Ò1°!Ñ4Ô4Ð4Ø%×*Ò*Ñ,Ô,Ð,øå Ô3ØÕ2°7Ñ;Ô;¸T¿YºYÀzÑ=RÔ=Rñô ð ñ!ñcCðJ ð 
ð
ð 
ØJZ×J`ÒJ`ÑJbÔJbð
ñ 
ô 
ð 	
ð
ð 
r   c           
      ó  — t                                d                     | ¦  «        |r$d                     t	          |dd¦  «        ¦  «        ndz   |r$d                     t	          |dd¦  «        ¦  «        ndz   ¦  «         dS )zu
    Log the given command (a sequence of command/argument strings), along with its input/output file
    paths.
    r   z < {}ÚnameÚ z > {}N)r2   Údebugr   ÚformatÚgetattr)Úfull_commandÚ
input_fileÚoutput_files      r   Úlog_commandrT   —   sŠ   € õ
 ‡L‚LØ�Š�ÑÔØ>HÐPˆ7�>Š>�' *¨f°bÑ9Ô9Ñ:Ô:Ð:Èbñ	Rà?JÐRˆ7�>Š>�' +¨v°rÑ:Ô:Ñ;Ô;Ð;ÐPRñ	Tñô ð ð ð r   FTc	           	      óp  — t          | ||¦  «         |ri t          j        ¥|¥nd}	t          |t          u ¦  «        }
|rd                     | ¦  «        n| }t          j        |||
rdn|pt          j        |
rdn|rt          j        nt          j	        ||	|¬¦  «        }|s|S t          |f||f||¬¦  «         dS )a�  
    Execute the given command (a sequence of command/argument strings) and log its output at the
    given log level. If an open output file object is given, then write stdout to the file and only
    log stderr. If an open input file object is given, then read stdin from the file. If shell is
    True, execute the command within a shell. If an extra environment dict is given, then use it to
    augment the current environment, and pass the result into the command. If a working directory is
    given, use that as the present working directory when running the command. If a Borg local path
    is given, and the command matches it (regardless of arguments), treat exit code 1 as a warning
    instead of an error. If run to completion is False, then return the process for the command
    without executing it to completion.

    Raise subprocesses.CalledProcessError if an error occurs while running the command.
    Nr   ©Ústdinr   r   ÚshellÚenvÚcwd©r   )rT   ÚosÚenvironr   ÚDO_NOT_CAPTUREr   r8   ÚPopenÚPIPEÚSTDOUTrJ   )rQ   r<   rS   rR   rX   Úextra_environmentÚworking_directoryr   Úrun_to_completionÚenvironmentÚdo_not_capturer   r   s                r   Úexecute_commandrg   ©   s÷   € õ0 �˜j¨+Ñ6Ô6Ð6Ø9JÐTÐ5•R”ZÐ5Ð#4Ð5Ð5ÐPT€KÝ˜+­Ð7Ñ8Ô8€NØ(-Ð?ˆc�hŠh�|Ñ$Ô$Ð$°<€GåÔØØØ%ÐKˆtˆt¨KÐ,J½:¼?Ø%Ðbˆtˆt¸{Ð,a­J¬O¨OÕPZÔPaØØØðñ ô €Gð ð ØˆåØ	ˆ
�Z Ð-Ð/?ÐQ`ðñ ô ð ð ð r   c                 óø   — t          | ¦  «         |ri t          j        ¥|¥nd}|rd                     | ¦  «        n| }t	          j        ||rt          j        nd|||¬¦  «        }|�|                     ¦   «         ndS )aL  
    Execute the given command (a sequence of command/argument strings), capturing and returning its
    output (stdout). If capture stderr is True, then capture and return stderr in addition to
    stdout. If shell is True, execute the command within a shell. If an extra environment dict is
    given, then use it to augment the current environment, and pass the result into the command. If
    a working directory is given, use that as the present working directory when running the command.

    Raise subprocesses.CalledProcessError if an error occurs while running the command.
    Nr   )r   rX   rY   rZ   )rT   r\   r]   r   r8   Úcheck_outputra   r.   )rQ   Úcapture_stderrrX   rb   rc   re   r   Úoutputs           r   Ú"execute_command_and_capture_outputrl   ×   s—   € õ �ÑÔÐØ9JÐTÐ5•R”ZÐ5Ð#4Ð5Ð5ÐPT€KØ(-Ð?ˆc�hŠh�|Ñ$Ô$Ð$°<€GåÔ$ØØ$2Ð<�zÔ Ð ¸ØØØðñ ô €Fð %Ð0ˆ6�=Š=‰?Œ?ˆ?°dÐ:r   c	           	      ó~  — t          | ||¦  «         |ri t          j        ¥|¥nd}	t          |t          u ¦  «        }
|rd                     | ¦  «        n| }	 t          j        |||
rdn|pt          j        |
rdn|rt          j        nt          j	        ||	|¬¦  «        }nb# t          j
        t          f$ rI |D ]D}|                     ¦   «         €.|j                             d¦  «         |                     ¦   «          ŒE‚ w xY wt!          t#          |¦  «        |fz   ||f||¬¦  «        }|€|                     |¦  «        S dS )a»  
    Execute the given command (a sequence of command/argument strings) and log its output at the
    given log level. Simultaneously, continue to poll one or more active processes so that they
    run as well. This is useful, for instance, for processes that are streaming output to a named
    pipe that the given command is consuming from.

    If an open output file object is given, then write stdout to the file and only log stderr. But
    if output log level is None, instead suppress logging and return the captured output for (only)
    the given command. If an open input file object is given, then read stdin from the file. If
    shell is True, execute the command within a shell. If an extra environment dict is given, then
    use it to augment the current environment, and pass the result into the command. If a working
    directory is given, use that as the present working directory when running the command. If a
    Borg local path is given, then for any matching command or process (regardless of arguments),
    treat exit code 1 as a warning instead of an error.

    Raise subprocesses.CalledProcessError if an error occurs while running the command or in the
    upstream process.
    Nr   rV   r   r[   )rT   r\   r]   r   r^   r   r8   r_   r`   ra   r9   ÚOSErrorr*   r   r6   r7   rJ   Útupler)   )rQ   r;   r<   rS   rR   rX   rb   rc   r   re   rf   r   Úcommand_processr   r@   s                  r   Úexecute_command_with_processesrq   ò   s†  € õ: �˜j¨+Ñ6Ô6Ð6Ø9JÐTÐ5•R”ZÐ5Ð#4Ð5Ð5ÐPT€KÝ˜+­Ð7Ñ8Ô8€NØ(-Ð?ˆc�hŠh�|Ñ$Ô$Ð$°<€GðÝ$Ô*ØØØ)ÐO�4�4°Ð0N½z¼àðI�4�4à%0ÐG•*”/�/µjÔ6GØØØ!ð

ñ 

ô 

ˆˆøõ Ô)­7Ð3ð ð ð ð !ð 	ð 	ˆGØ�|Š|‰~Œ~Ð%Ø”×#Ò# AÑ&Ô&Ð&Ø—’‘”�øØðøøøõ #ÝˆiÑÔ˜OÐ-Ñ-Ø	�[Ð!ØØ'ð	ñ ô Ðð ÐØ×#Ò# OÑ4Ô4Ð4ð  Ðs   ÁAB ÂAC=)N)NN)FFNN)r$   Úloggingr\   r(   r8   Ú	getLoggerÚ__name__r2   r0   r   r   r   r   rJ   rT   Úobjectr^   ÚINFOrg   rl   rq   r   r   r   ú<module>rw      sG  ðØ Ð Ð Ð Ø €€€Ø 	€	€	€	Ø €€€Ø Ð Ð Ð à	ˆÔ	˜8Ñ	$Ô	$€ð !Ð ØÐ ð ð  ð  ð  ð"Uð Uð UðSð Sð Sðd
ð d
ð d
ðN	ð 	ð 	ð 	ð �‘”€ð
 ”\ØØØ
ØØØØð+ð +ð +ð +ð^ `dð;ð ;ð ;ð ;ð< ”\ØØØ
ØØØð?5ð ?5ð ?5ð ?5ð ?5ð ?5r   