
    fS                         d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ  e j                  e      Z G d dej"                        Zy)	    N)distroshelperssubputil)PackageList)HostnameConf)CLOUDINIT_NETPLAN_FILE)PER_INSTANCEc                   t    e Zd ZdZdgZdedddiZd Zdd	Zd
e	fdZ
d Zd Zd ZddZd Zd ZddZd Zy)Distroz/etc/locale.gen	systemctlnetplanz# generated by cloud-init
T)netplan_pathnetplan_headerpostcmdsc                     t         j                  j                  | |||       t        j                  |      | _        d| _        d|d<   y )Narchsshdssh_svcname)r   r   __init__r   Runners_runnerosfamily)selfnamecfgpathss       8/usr/lib/python3/dist-packages/cloudinit/distros/arch.pyr   zDistro.__init__   s=    dC7 u-#M    Nc                 4   ||dk7  rt         j                  d|       t        j                         d|z  dg}t        j                  | j
                  dj                  |             t        j                  dgd       t        j                  d	d
|gd       y )Nz/etc/locale.confzFInvalid locale_configfile %s, only supported value is /etc/locale.confz%s UTF-8 
z
locale-genFcapture	localectlz
set-locale)LOGwarningr   make_header
write_filelocale_gen_fnjoinr   )r   localeout_fnliness       r   apply_localezDistro.apply_locale&   s    &,>">KK, &!	
 	**DIIe,<=		<.%0 			;f5uEr   pkglistc                 J    | j                          | j                  d|       y )Nr!   )pkgs)update_package_sourcespackage_command)r   r0   s     r   install_packageszDistro.install_packages9   s!    ##%Rg.r   c                 @   d }	 | j                  |      }|st        d      }|j                  |       t        j                  |t        |      dd       y # t        $ r> t        j                  | j                  dd      }|rnt
        j                  d       Y y Y w xY w)Ncreate_hostname_fileTz8create_hostname_file is False; hostname file not createdr!   wi  )omodemode)_read_hostname_confIOErrorr   get_cfg_option_bool_cfgr&   infor   set_hostnamer)   str)r   hostnamefilenameconfr7   s        r   _write_hostnamezDistro._write_hostname=   s    	 ++H5D #D(##d)3UC  
	#'#;#;		14$  $N  
	s   A ABBc                 T    | j                  | j                        }| j                  |fS N)_read_hostnamehostname_conf_fn)r   sys_hostnames     r   _read_system_hostnamezDistro._read_system_hostnameS   s)    **4+@+@A%%|44r   c                 b    t        t        j                  |            }|j                          |S rG   )r   r   load_text_fileparse)r   rC   rD   s      r   r;   zDistro._read_hostname_confW   s%    D//9:

r   c                 l    d }	 | j                  |      }|j                  }|s|S |S # t        $ r Y w xY wrG   )r;   rB   r<   )r   rC   defaultrB   rD   s        r   rH   zDistro._read_hostname\   sH    	++H5D}}H N	  		s   ' 	33c                     t         j                  d|       	 t        j                  ddd|g       y # t        j                  $ r t	        j
                  t         d|       Y y w xY w)Nz2Non-persistently setting the system hostname to %shostnamectlz--transientzset-hostnamez;Failed to non-persistently adjust the system hostname to %s)r&   debugr   ProcessExecutionErrorr   logexc)r   rB   s     r   _apply_hostnamezDistro._apply_hostnamei   sW    		@(	
	II}m^XNO)) 	KKM	s   2 .A#"A#c                 P    t        j                  || j                  |             y )N)tztz_file)r   set_etc_timezone_find_tz_file)r   rX   s     r   set_timezonezDistro.set_timezonev   s      B0B0B20FGr   c                 R   |g }g d}|r"t        |t              r|j                  |       n#|r!t        |t              r|j	                  |       |dk(  rd}|r|j                  |       t        j                  d|      }|j	                  |       t        j                  |d       y )N)pacmanz-Syz--quietz--noconfirmupgradez-uz%s-%sFr#   )
isinstancerA   appendlistextendr   expand_package_listr   )r   commandargsr2   cmdr0   s         r   r4   zDistro.package_commandy   s    <D9 JtS)JJtjt,JJtiGJJw**7D9

7 			#u%r   c                 `    | j                   j                  d| j                  dgt               y )Nzupdate-sourcesz-y)freq)r   runr4   r
   )r   s    r   r3   zDistro.update_package_sources   s*    d22TF 	 	
r   rG   )NN)__name__
__module____qualname__r*   init_cmdr	   renderer_configsr   r/   r   r5   rE   rK   r;   rH   rV   r\   r4   r3    r   r   r   r      sh    %M}H2;
$F&/ /D,5
	H&.
r   r   )logging	cloudinitr   r   r   r   cloudinit.distrosr   "cloudinit.distros.parsers.hostnamer   cloudinit.net.netplanr	   cloudinit.settingsr
   	getLoggerrk   r&   r   rp   r   r   <module>rx      s@     2 2 ) ; 8 +g!A
W^^ A
r   