
    W'Fg                     V    S SK r S SKrS SKrS SKrSSKJr  S rS	S jrS rS r	S	S jr
g)
    N   )logc                    [         R                  " S5        [        R                  " / SQ[        R                  [        R                  US9n[        R                  " / SQUR
                  [        R                  [        R                  US9n[        U S5      n[        R                  " S/UR
                  U[        R                  S9nUR                  5         UR                  5         UR                  5         UR                  5         UR                  R                  5       nUR                  R                  5       nUR                  R                  5       nU(       a  [         R                  " S	U5        U(       a  [         R                  " S
U5        U(       a  [         R                  " SU5        UR                  S:w  d   UR                  S:w  d  UR                  S:w  a  [        S5      eg )NzAppending to the initrd.)find.z-print0)stdoutstderrcwd)cpioz--createz--nullz--quietz--format=newcz--owner=0:0)stdinr   r	   r
   abgzip)r   r   r	   zfind stderr=%szcpio stderr=%szgzip stderr=%sr   z"Failed to inject files into initrd)r   debug
subprocessPopenPIPEr   openwaitcloser	   read
returncodeRuntimeError)	initrdtempdir	find_proc	cpio_procf	gzip_procfinderrcpioerrgziperrs	            ;/usr/share/virt-manager/virtinst/install/installerinject.py_run_initrd_commandsr#      sm   II()  !9(2(2%,.I    "B'0'7'7(2(2%,.I 	VTA  &1A1A()*//CINNNNNNGGI##%G##%G##%G		"G,		"G,		"G,!!!?@@ 	"    c                 b   / SQnU H   n[         R                  " U5      (       d  M     O   WSU SSSS/nU(       a  UR                  SS/5        UR                  U5        [        R
                  " S	U5        [        R                  " U[        R                  S
9n[        R
                  " SU5        g )N)	xorrisofsgenisoimagemkisofsz-oz-Jz-input-charsetutf8z-rational-rockz-VcidatazRunning iso build command: %s)r	   zcmd output: %s)	shutilwhichextendappendr   r   r   check_outputSTDOUT)isor   	cloudinitprogramsprogramcmdoutputs          r"   _run_iso_commandsr7   4   s     7H<<    V	C
 

D(#$JJwII-s3$$S1B1BCFII'r$   c                    U (       d  g [         R                  " US9n [        R                  " US5        U  H  n[	        U5      [
        L a  Uu  pgO[        R                  R                  U5      n[        R                  " SXgU5        [        R                  " U[        R                  R                  XW5      5        M     U" X%40 UD6[        R                  " U5        $ ! [        R                  " U5        f = f)N)diri  z%Injecting src=%s dst=%s into media=%s)tempfilemkdtemposchmodtypetuplepathbasenamer   r   r+   copyjoinrmtree)
injections
scratchdirmediacbkwargsr   filenamedsts           r"   _perform_generic_injectionsrL   L   s    :.G
% "HH~& (#gg&&x0II=5*KK"'',,w"<= # %+F+ggs   B*C C7c                 &    [        XU [        5        g)z>
Insert files into the root directory of the initial ram disk
N)rL   r#   )r   rE   rF   s      r"   perform_initrd_injectionsrN   c   s      
 "r$   c                     U(       a  SnOSn[         R                  " SUUSS9nUR                  n [        XU[        US9  U$ ! [
         a    [        R                  " U5        e f = f)z;
Insert files into the root directory of a generated cdrom
z-cloudinit.isoz-unattended.isoz	virtinst-F)prefixsuffixr9   delete)r2   )r:   NamedTemporaryFilenamerL   r7   	Exceptionr<   unlink)rE   rF   r2   
iso_suffixfileobjr1   s         r"   perform_cdrom_injectionsrY   k   sr     %
&
)):u&G ,,C#JC	4 J	  
		#s   A "A%)F)r<   r+   r   r:   loggerr   r#   r7   rL   rN   rY    r$   r"   <module>r\      s1    
    "AJ(0."r$   