
    fb              
          U d Z ddlZddlZddlm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mZ ddlmZ g d	Zd
Zdddee ed      gedgdZeed<    ee      Z  ej*                  e      Zd Zd Zd Zd Zd Zdedede	deddf
dZy)z6zypper_add_repo: Add zypper repositories to the system    N)dedent)util)Cloud)Config)
MetaSchemaget_meta_doc)
PER_ALWAYS)opensusezopensuse-microoszopensuse-tumbleweedzopensuse-leapsle_hpcz	sle-microslesa  Zypper behavior can be configured using the ``config`` key, which will modify
``/etc/zypp/zypp.conf``. The configuration writer will only append the
provided configuration options to the configuration file. Any duplicate
options will be resolved by the way the zypp.conf INI file is parsed.

.. note::
    Setting ``configdir`` is not supported and will be skipped.

The ``repos`` key may be used to add repositories to the system. Beyond the
required ``id`` and ``baseurl`` attributions, no validation is performed
on the ``repos`` entries. It is assumed the user is familiar with the
zypper repository file format. This configuration is also applicable for
systems with transactional-updates.
cc_zypper_add_repozZypper Add Repoz5Configure zypper behavior and add zypper repositoriesa          zypper:
          repos:
            - id: opensuse-oss
              name: os-oss
              baseurl: http://dl.opensuse.org/dist/leap/v/repo/oss/
              enabled: 1
              autorefresh: 1
            - id: opensuse-oss-update
              name: os-oss-up
              baseurl: http://dl.opensuse.org/dist/leap/v/update
              # any setting per
              # https://en.opensuse.org/openSUSE:Standards_RepoInfo
              # enable and autorefresh are on by default
          config:
            reposdir: /etc/zypp/repos.dir
            servicesdir: /etc/zypp/services.d
            download.use_deltarpm: true
            # any setting in /etc/zypp/zypp.conf
    zypper)idnametitledescriptiondistrosexamples	frequencyactivate_by_schema_keysmetac                 *    | j                  dd      } | S )N _)replace)repo_ids    E/usr/lib/python3/dist-packages/cloudinit/config/cc_zypper_add_repo.py_canonicalize_idr   T   s    ooc3'GN    c                     t        | t              r| rdS dS t        | t        t        f      r(dj	                  | D cg c]  }t        |       c}      S t        | t              st        |       S | S c c}w )N   r   z
    )
isinstanceboollisttuplejoin_format_repo_valuestr)valvs     r   r'   r'   Y   se    #tqQ#e}%}}SA03ABBc33xJ Bs   A2c                     t        j                         }i || <   |j                         D ]  \  }}t        |      ||    |<    |j	                         }dj                  |      S )N
)	configobj	ConfigObjitemsr'   writer&   )r   repo_configto_bekr*   liness         r   _format_repository_configr5   d   sf    !EE'N##% 2A /q1gq2 KKME99Ur   c                    | syi }t        |       D ]  \  }}t        ddg      j                  t        |            }|r't        j	                  d|dj                  |             U|j                  d      }t        |      }t        j                  j                  |d|z        }t        j                  j                  |      rt        j                  d||       ||v rt        j                  d||       t        d	 |j                         D              }	d
D ]  }
|
|	vsd|	|
<    ||	f||<   ! |j                         D ]-  \  }}t        ||d         }t        j                   |d   |       / y)zWrite the user-provided repo definition files
    @param repos: A list of repo dictionary objects provided by the user's
        cloud config.
    @param repo_base_path: The directory path to which repo definitions are
        written.
    Nr   baseurlz;Repo config at index %d is missing required config keys: %s,z%s.repoz)Skipping repo %s, file %s already exists!z*Skipping repo %s, file %s already pending!c              3      K   | ]>  \  }}|r7|d k7  r2|j                         j                         j                  dd      |f @ yw)r   -r   N)lowerstripr   ).0r3   r*   s      r   	<genexpr>z_write_repos.<locals>.<genexpr>   sD      
1Q$Y WWY__&&sC0!4
s   AA)enabledautorefresh1r   )	enumerateset
differenceLOGwarningr&   getr   ospathexistsinfodictr/   r5   r   
write_file)reposrepo_base_pathvalid_reposindexuser_repo_configmissing_keysr   canon_repo_idrepo_fn_pthr1   field	repo_data	repo_blobs                r   _write_reposrZ   p   s    K#,U#3 (:D),-88=M9NOKKM&
 "&&t,(1ggll>93NO77>>+&HH;
 #HH<
   
(..0
 
 0 	)EK'%(E"	) !,[9GQ(:T !, 1 1 3 1)-gy}E		!i01r   c                 Z   | syd}t        j                  |      }dg}| j                         D ]@  \  }}|dk(  rd}|dz  }t        j	                  |       (|s+|j                  |d|       B t        |      dkD  r|d	j                  |      z   }n|}t        j                  ||       y)
z@Write to the default zypp configuration file /etc/zypp/zypp.confNz/etc/zypp/zypp.confz# Added via cloud.cfg	configdirz5Changing the location of the zypper configuration is z+not supported, skipping "configdir" setting=r!   r,   )	r   load_text_filer/   rF   rG   appendlenr&   rN   )zypper_configzypp_configzypp_conf_contentnew_settingssettingvaluemsg
new_configs           r   _write_zypp_configri      s    'K++K8+,L'--/ <k!IC@@CKK7E :;< <1&<)@@
&
OOK,r   r   cfgcloudargsreturnc                 "   |j                  d      }|st        j                  d|        y |j                  d      }|st        j                  d|        y |j                  di       }|j                  dd      }t        |       t	        ||       y )Nr   zBSkipping module named %s, no 'zypper' relevant configuration foundrO   z8Skipping module named %s, no 'repos' configuration foundconfigreposdirz/etc/zypp/repos.d/)rH   rF   debugri   rZ   )r   rj   rk   rl   zypper_sectionrO   ra   rP   s           r   handlers      s    WWX&N		8	

 	w'E		F	
 	"&&x4M"&&z3GHN}%'r   ) __doc__loggingrI   textwrapr   r-   	cloudinitr   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r   cloudinit.settingsr	   r   MODULE_DESCRIPTIONr   __annotations__	getLogger__name__rF   r   r'   r5   rZ   ri   r(   r$   rs    r   r   <module>r      s    =  	    ! # < )   D%	
0  (z? j  D t
g!
	71t-,( (6 (% (t ( (r   