3 \me] @sUdZddlZddlZddlmZddlZddlmZddlm Z ddl m Z ddl m Z mZddlmZd d d d d ddgZdZdddeeedgedgdZe eeZejeZddZddZddZddZdd Zee e edd!d"d#ZdS)$z6zypper_add_repo: Add zypper repositories to the systemN)dedent)util)Cloud)Config) MetaSchema get_meta_doc) PER_ALWAYSZopensusezopensuse-microoszopensuse-tumbleweedz opensuse-leapZsle_hpcz sle-microZslesaZypper 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. Zcc_zypper_add_repozZypper 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)idnametitle descriptiondistrosZexamplesZ frequencyZactivate_by_schema_keyscCs|jdd}|S)N _)replace)repo_idr(/usr/lib/python3.6/cc_zypper_add_repo.py_canonicalize_idTs rcCsNt|tr|rdSdSt|ttfr8djdd|DSt|tsJt|S|S)Nrz cSsg|] }t|qSr)_format_repo_value).0vrrr ^sz&_format_repo_value..) isinstanceboollisttuplejoinstr)valrrrrYs   rcCsHtj}i||<x$|jD]\}}t||||<qW|j}dj|S)N ) configobjZ ConfigObjitemsrwriter)r repo_configZto_bekrlinesrrr_format_repository_configds r)c Cs$|sdSi}xt|D]\}}tddgjt|}|rNtjd|dj|q|jd}t|}tj j|d|}tj j |rtj d||qn||krtj d||qt d d |j D} xdD]} | | krd | | <qW|| f||<qWx2|j D]&\}} t|| d} tj| d| qWdS)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 Zbaseurlz;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!css6|].\}}|r|dkr|jjjdd|fVqdS)r -rN)lowerstripr)rr'rrrr sz_write_repos..enabled autorefresh1rr)r/r0) enumerateset differenceLOGwarningrgetrospathexistsinfodictr$r)r write_file) reposrepo_base_pathZ valid_reposindexZuser_repo_configZ missing_keysrZ canon_repo_idZ repo_fn_pthr&ZfieldZ repo_dataZ repo_blobrrr _write_repospsH     rBcCs|sdSd}tj|}dg}xJ|jD]>\}}|dkrNd}|d7}tj|q&|r&|jd||fq&Wt|dkr|d j|}n|}tj||dS) 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=%srr") rZ load_filer$r6r7appendlenrr>) zypper_configZ zypp_configZzypp_conf_contentZ new_settingsZsettingvaluemsgZ new_configrrr_write_zypp_configs"   rH)r cfgcloudargsreturncCsj|jd}|stjd|dS|jd}|ssD        :