
    >Tf                         d dl Z d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZmZ d
dlmZ  G d de          ZdS )    N)nullcontext)transaction)gettext)clear_events)Script)event_tracking)	JobRunner)AbortScriptAbortTransaction   )	is_reportc                   :    e Zd ZdZ G d d          Zd ZddZdS )		ScriptJobz
    Script execution job.

    A wrapper for calling Script.run(). This performs error handling and provides a hook for committing changes. It
    exists outside the Script class to ensure it cannot be overridden by a script author.
    c                       e Zd ZdZdS )ScriptJob.Meta N)__name__
__module____qualname__name     0/var/www/html/netbox-4.1.3/netbox/extras/jobs.pyMetar      s         r   r   c                    t          j        d|j                   }|                    d| d           	 	 t	          j                    5  |                    ||          |_        |st                      	 ddd           n# 1 swxY w Y   nP# t          $ rC |	                    t          d                     |j        r|                    d            Y nw xY wnf# t          $ rX}t          |          t          u rt          d          t!          |          z   }t#          t          |                    r|                    |           n|                    |           |                    d|            nmt)          j                    }|                    t          d	          d
t          |          j         d| d| dz              |                    d|            t          |          t          ur#|	                    t          d                     |rt/          j        |            d}~ww xY w|                                | j        _        dS # |                                | j        _        w xY w)a  
        Core script execution task. We capture this within a method to allow for conditionally wrapping it with the
        event_tracking context manager (which is bypassed if commit == False).

        Args:
            request: The WSGI request associated with this execution (if any)
            data: A dictionary of data to be passed to the script upon execution
            commit: Passed through to Script.run()
        znetbox.scripts.zRunning script (commit=)Nz2Database changes have been reverted automatically.)messagezScript failedzScript aborted with error: zAn exception occurred: `z: z`
```
z
```z*Exception raised during script execution: z1Database changes have been reverted due to error.)logging	getLogger	full_nameinfor   atomicrunoutputr   log_info_failedwarning	Exceptiontyper
   strr   log_failureerror	traceback
format_excr   r   sendget_job_datajobdata)	selfscriptrequestr4   commitloggeremsg
stacktraces	            r   
run_scriptzScriptJob.run_script   s    "#GV5E#G#GHH7f777888'	2	 ')) 1 1$*JJtV$<$<FM! 1.00011 1 1 1 1 1 1 1 1 1 1 1 1 1 1 $   *^(_(_```= NN#3444   	 	 	Aww+%%566Q?T&\\** ,&&s&3333&&s+++>1>>???? '133
""788;otAww?O;o;oST;o;o^h;o;o;oo #    M!MMNNNAww...*](^(^___  +!'***-	6 #//11DHMMMF//11DHM1111sm   B ,B8B BB BB C" A
CC" CC"  I( "I-EI  II( ( JNTc                 |   t           j                            | j        j                                                  }|r&|j        }|                                D ]
\  }}|||<   ||_        |rt          |          nt                      5  |                     ||||           ddd           dS # 1 swxY w Y   dS )a:  
        Run the script.

        Args:
            job: The Job associated with this execution
            data: A dictionary of data to be passed to the script upon execution
            request: The WSGI request associated with this execution (if any)
            commit: Passed through to Script.run()
        )pkN)ScriptModelobjectsgetr3   	object_idpython_classFILESitemsr7   r   r   r=   )	r5   r4   r7   r8   kwargsr6   files
field_namefileobjs	            r   r$   zScriptJob.runS   s    $((DH,>(??LLNN  	+ME',{{}} + +#
G#*Z   ! )/A^G$$$KMM 	; 	;OOFGT6:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   B11B58B5)NT)r   r   r   __doc__r   r=   r$   r   r   r   r   r      sj                
42 42 42l; ; ; ; ; ;r   r   )r   r/   
contextlibr   	django.dbr   django.utils.translationr   r'   core.signalsr   extras.modelsr   r@   netbox.context_managersr   netbox.jobsr	   utilities.exceptionsr
   r   utilsr   r   r   r   r   <module>rU      s         " " " " " " ! ! ! ! ! ! 1 1 1 1 1 1 % % % % % % / / / / / / 2 2 2 2 2 2 ! ! ! ! ! ! > > > > > > > >      [; [; [; [; [;	 [; [; [; [; [;r   