
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me]              	   @   s   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 d	d
dddddgZdZdddeeedgedgdZeeeZ ejeZdd Zdd Zdd Zdd Zdd  Zeee	edd!d"d#ZdS )$z6zypper_add_repo: Add zypper repositories to the system    N)dedent)util)Cloud)Config)
MetaSchemaget_meta_doc)
PER_ALWAYSZopensusezopensuse-microoszopensuse-tumbleweedzopensuse-leapZsle_hpcz	sle-microZ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.
Z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distrosZexamplesZ	frequencyZactivate_by_schema_keysc             C   s   | j dd} | S )N _)replace)repo_id r   (/usr/lib/python3.6/cc_zypper_add_repo.py_canonicalize_idT   s    r   c             C   sN   t | tr| rdS dS t | ttfr8djdd | D S t | tsJt| S | S )N   r   z
    c             S   s   g | ]}t |qS r   )_format_repo_value).0vr   r   r   
<listcomp>^   s    z&_format_repo_value.<locals>.<listcomp>)
isinstanceboollisttuplejoinstr)valr   r   r   r   Y   s    

r   c             C   sH   t j }i || < x$|j D ]\}}t|||  |< qW |j }dj|S )N
)	configobjZ	ConfigObjitemsr   writer   )r   repo_configZto_bekr   linesr   r   r   _format_repository_configd   s    r)   c             C   s$  | sdS i }xt | D ]\}}tddgjt|}|rNtjd|dj| q|jd}t|}tj	j|d| }tj	j
|rtjd|| qn||krtjd|| qtd	d
 |j D }	xdD ]}
|
|	krd|	|
< qW ||	f||< qW x2|j D ]&\}}t||d }tj|d | qW dS )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
   Z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             s   s6   | ].\}}|r|d kr|j  j jdd|fV  qdS )r
   -r   N)lowerstripr   )r   r'   r   r   r   r   	<genexpr>   s   z_write_repos.<locals>.<genexpr>enabledautorefresh1r   r   )r/   r0   )	enumerateset
differenceLOGwarningr   getr   ospathexistsinfodictr$   r)   r   
write_file)reposrepo_base_pathZvalid_reposindexZuser_repo_configZmissing_keysr   Zcanon_repo_idZrepo_fn_pthr&   ZfieldZ	repo_dataZ	repo_blobr   r   r   _write_reposp   sH    

rB   c             C   s   | sdS d}t j|}dg}xJ| j D ]>\}}|dkrNd}|d7 }tj| q&|r&|jd||f  q&W t|dkr|d	j| }n|}t j|| dS )
z@Write to the default zypp configuration file /etc/zypp/zypp.confNz/etc/zypp/zypp.confz# Added via cloud.cfgZ	configdirz5Changing the location of the zypper configuration is z+not supported, skipping "configdir" settingz%s=%sr   r"   )	r   Z	load_filer$   r6   r7   appendlenr   r>   )zypper_configZzypp_configZzypp_conf_contentZnew_settingsZsettingvaluemsgZ
new_configr   r   r   _write_zypp_config   s"    

rH   )r   cfgcloudargsreturnc             C   sj   |j d}|stjd|  d S |j d}|s<tjd|  d S |j di }|j dd}t| t|| d S )Nr	   zBSkipping module named %s, no 'zypper' relevant configuration foundr?   z8Skipping module named %s, no 'repos' configuration foundconfigZreposdirz/etc/zypp/repos.d/)r8   r6   debugrH   rB   )r   rI   rJ   rK   Zzypper_sectionr?   rE   r@   r   r   r   handle   s    

rO   )__doc__Zloggingr9   textwrapr   r#   Z	cloudinitr   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr   r   ZMODULE_DESCRIPTIONmetaZ	getLogger__name__r6   r   r   r)   rB   rH   r    r   rO   r   r   r   r   <module>   sD   
: