%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/opkg.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
ZddlZddlZddlZddlZddlZddlmZmZmZddlmZddlmZdZdZid	d
6dd6d
d6dd6dd6dd6Zeje �Z!dZ"dZ#d�Z$d�Z%d�Z&d�Z'd�Z(e(Z)d�Z*e+d�Z,de+dde+d�Z.ddd�Z/ddd �Z0e1d!�Z2dddd"�Z3dddd#�Z4d$�Z5d%�Z6e+d&�Z7e1d'�Z8d(�Z9d)�Z:d*�Z;d+�Z<e+d,�Z=d-�Z>d.�Z?d/�Z@e1d0�ZAd1�ZBd2�ZCd3�ZDd4�ZEd5�ZFd6�ZGdS(7u�
Support for Opkg

.. important::
    If you feel that Salt should be using this module to manage packages on a
    minion, and it is using a different module (or gives an error similar to
    *'pkg.install' is not available*), see :ref:`here
    <module-provider-override>`.

.. versionadded: 2016.3.0

.. note::

    For version comparison support on opkg < 0.3.4, the ``opkg-utils`` package
    must be installed.

i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionErrortMinionErrortSaltInvocationError(tsix(tshlex_quoteu3^#?\s*(src|src/gz)\s+([^\s<>]+|"[^<>]+")\s+[^\s<>]+u	/etc/opkguarchuArchitectureuurluHomepageuinstall_date_time_tuInstalled-Timeupackageru
MaintainerunameuPackageugroupuSectionupkgu /var/lib/salt/restartcheck_statecC@s�tddjt��tddjt��d}tjj|�r}tddj|t��tddj|t��ndS(u�
    NILRT systems determine whether to reboot after various package operations
    including but not limited to kernel module installs/removals by checking
    specific file md5sums & timestamps. These files are touched/modified by
    the post-install/post-remove functions of their respective packages.

    The opkg module uses this function to store/update those file timestamps
    and checksums to be used later by the restartcheck module.

    u	cmd.shelluJstat -c %Y /lib/modules/$(uname -r)/modules.dep >{0}/modules.dep.timestampuCmd5sum /lib/modules/$(uname -r)/modules.dep >{0}/modules.dep.md5sumu%/usr/local/natinst/share/nisysapi.iniu*stat -c %Y {0} >{1}/nisysapi.ini.timestampu#md5sum {0} >{1}/nisysapi.ini.md5sumN(t__salt__tformattNILRT_RESTARTCHECK_STATE_PATHtostpathtexists(t
nisysapi_path((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt_update_nilrt_restart_state>s






cC@sFtddt�}t|t�rBd|krB|j|d�n|S(uM
    Return restartcheck result and append errors (if any) to ``errors``
    urestartcheck.restartchecktverboseucomment(RtFalset
isinstancetdicttappend(terrorst	rs_result((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt_get_restartcheck_resultWscC@s�d|krdSxm|D]e}d|kr>t�td�qtjjd|�}tjj|�rtd|dg�qqWdS(uu
    Check restartcheck output to see if system/service restarts were requested
    and take appropriate action.
    u(No packages seem to need to be restartedNuSystem restart requiredu$system.set_reboot_required_witnessedu/etc/init.ducmd.runurestart(RRRRtjoinR
(Rtrstrtservice((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt_process_restartcheck_resultas
cC@s�tjd�dkr�ytjt�WnDtk
rl}|jtjkrmtdj	t|j|j
�fSnXtjjtjj
td��o�tjjtjj
td��s�t�ntStjjt�r�tStdfS(u8
    Confirm this module is on a nilrt based system
    u	os_familyu	NILinuxRTuError creating {0} (-{1}): {2}umodules.dep.timestampumodules.dep.md5sumu4Module opkg only works on OpenEmbedded based systems(t
__grains__tgetRtmakedirsR
tOSErrorterrnotEEXISTRR	tstrerrorRR
RRt__virtualname__tisdirtOPKG_CONFDIR(texc((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt__virtual__rs 	!!
c
O@stjjj|jdt��}t|�dkr7dSi}x|D]}d||<qDW|rht�nddg}td|ddd	t	�}xitjj
j|d
�D]O}y5|jd�\}}}	||kr�|	||<nWq�tk
r�q�Xq�Wt|�dkr||dS|S(
u
    Return the latest version of the named package available for upgrade or
    installation. If more than one package name is specified, a dict of
    name/version pairs is returned.

    If the latest version of a given package is already installed, an empty
    string will be returned for that package.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.latest_version <package name>
        salt '*' pkg.latest_version <package name>
        salt '*' pkg.latest_version <package1> <package2> <package3> ...
    urefreshiuuopkgulist-upgradableucmd.run_stdouttoutput_loglevelutracetpython_shellu
u - i(
tsalttutilstdatatis_truetpoptTruetlent
refresh_dbRRt	itertoolstsplitt
ValueError(
tnamestkwargstrefreshtrettnametcmdtouttlinet_oldversiont
newversion((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytlatest_version�s,!


	
cO@std||�S(uY
    Returns a string representing the package version or an empty string if not
    installed. If more than one package name is specified, a dict of
    name/version pairs is returned.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.version <package name>
        salt '*' pkg.version <package1> <package2> <package3> ...
    upkg_resource.version(R(R5R6((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytversion�s
c

K@s�tjjjt�i}g}ddg}td|dddtdtdt�}|d	}d
}x�tjjj	|d�D]�}d|kr�|j
�j	�d
d }	t||	<n|d|kr�|j
�j	�d
d }	t||	<nId|kr1|j
�j	�dj	d�d}	t||	<|j|	�n|}q|W|rh|rhtdj
dj|����n|ddkr�|r�t|��n|S(u�
    Updates the opkg database to latest packages based upon repositories

    Returns a dict, with the keys being package databases and the values being
    the result of the update attempt. Values can be one of the following:

    - ``True``: Database updated successfully
    - ``False``: Problem updating database

    failhard
        If False, return results of failed lines as ``False`` for the package
        database that encountered the error.
        If True, raise an error with a list of the package databases that
        encountered errors.

        .. versionadded:: 2018.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.refresh_db
    uopkguupdateucmd.run_allR(utraceR)tignore_retcodetredirect_stderrustdoutuu
u	Inflatingii����uUpdated sourceuFailed to downloadiu,iuError getting repos: {0}u, uretcode(R*R+tpkgt
clear_rtagt__opts__RRR/R2R3tstripRRR	R(
tfailhardR6R8terror_reposR:tcallR;t	prev_lineR<tkey((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyR1�s:
	


#

cK@sbtjjj|�}y#td||||�\}}Wntk
rY}	t|	��nXt�}
ddg}g}g}
g}|d%ks�t	|�dkr�iS|dkr�|r�|j
d�n|jdt�s�|j
d�n|j
|�n�|d	kr�|jd
t�s%|j
d�nx~tj|�D]j\}}|r�|d%kr�|jd�r�t	|�d
kr�|d}n|}|d%kr�|r�||
kr�|
j
|�q�|j
|�q5dj||�}|
j|d�}|r/|r/tjjjd|ddd|dt�r/|
j
|�q5|s`tjjjd|ddd|dt�rp|j
|�q5|jdt�s�|j
|�q5|j
|�q5Wng}|r�tj|�}|j
|�|j
|�n|rtj|�}|j
d�|j
|�|j
|�n|
r\tj|�}|j
d�|j
|
�|j
|�n|sfiS|rvt�ng}xl|D]d}td|dddt�}|ddkr�|dr�|j
|d�q�|j
|d�q�q�Wtjdd%�t�}tjjj|
|�}|dkr�|r�x�|D]}}dd|g}td|dddt�}|ddkr5t|dg�}|r�|
j
t|j��d�q�q5q5Wnxc|
D][}||ks�||
kr�|jii|
j|d�d6|j|d�d 6|6�q�q�Wt|�}|rTtd!d"i|d#6|d$6��nt |�|S(&u	
    Install the passed package, add refresh=True to update the opkg database.

    name
        The name of the package to be installed. Note that this parameter is
        ignored if either "pkgs" or "sources" is passed. Additionally, please
        note that this option can only be used to install packages from a
        software repository. To install a package file manually, use the
        "sources" option.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install <package name>

    refresh
        Whether or not to refresh the package database before installing.

    version
        Install a specific version of the package, e.g. 1.2.3~0ubuntu0. Ignored
        if "pkgs" or "sources" is passed.

        .. versionadded:: 2017.7.0

    reinstall : False
        Specifying reinstall=True will use ``opkg install --force-reinstall``
        rather than simply ``opkg install`` for requested packages that are
        already installed.

        If a version is specified with the requested package, then ``opkg
        install --force-reinstall`` will only be used if the installed version
        matches the requested version.

        .. versionadded:: 2017.7.0


    Multiple Package Installation Options:

    pkgs
        A list of packages to install from a software repository. Must be
        passed as a python list.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install pkgs='["foo", "bar"]'
            salt '*' pkg.install pkgs='["foo", {"bar": "1.2.3-0ubuntu0"}]'

    sources
        A list of IPK packages to install. Must be passed as a list of dicts,
        with the keys being package names, and the values being the source URI
        or local path to the package.  Dependencies are automatically resolved
        and marked as auto-installed.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install sources='[{"foo": "salt://foo.deb"},{"bar": "salt://bar.deb"}]'

    install_recommends
        Whether to install the packages marked as recommended. Default is True.

    only_upgrade
        Only upgrade the packages (disallow downgrades), if they are already
        installed. Default is False.

        .. versionadded:: 2017.7.0

    Returns a dict containing the new package names and versions::

        {'<package>': {'old': '<old-version>',
                       'new': '<new-version>'}}
    upkg_resource.parse_targetsuopkguinstalliufileu--force-reinstalluonly_upgradeu--force-downgradeu
repositoryuinstall_recommendsu--no-install-recommendsuversioniu{0}={1}utver1toperu==tver2tcmp_funcu>=ucmd.run_allR(utraceR)uretcodeustderrustdoutu
pkg.list_pkgsuinfouoldunewu)Problem encountered installing package(s)tinfouerrorsuchangesN(!R*R+R,R-RRRt	list_pkgstNoneR0RRRtextendR/Rt	iteritemsR	tversionstcomparetversion_cmptcopytdeepcopyR1t__context__R.t
compare_dictst_process_info_installed_outputtlisttkeystupdateRR(R9R7tpkgstsourcest	reinstallR6t	refreshdbt
pkg_paramstpkg_typeR&toldt
cmd_prefixt
to_installtto_reinstalltto_downgradetpkgnamet
pkgversiontversion_numtpkgstrtcvertcmdsR:RR;tnewR8tpkgfiletpkginfo_dictR((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytinstalls�R	!
		






	
	
	*
"
cK@s�ytd||�d}Wntk
r<}t|��nXt�}g|D]}||krM|^qM}|suiSddg}|jdt�r�|jd�n|jdt�r�|jd�n|j|�td	|d
ddt�}	|	d
dkr(|	dr|	dg}
q.|	dg}
ng}
tj	dd�t�}tjj
j||�}t|
�}
|
r�tddi|
d6|d6��nt|
�|S(ul
    Remove packages using ``opkg remove``.

    name
        The name of the package to be deleted.


    Multiple Package Options:

    pkgs
        A list of packages to delete. Must be passed as a python list. The
        ``name`` parameter will be ignored if this option is passed.

    remove_dependencies
        Remove package and all dependencies

        .. versionadded:: 2019.2.0

    auto_remove_deps
        Remove packages that were installed automatically to satisfy dependencies

        .. versionadded:: 2019.2.0

    Returns a dict containing the changes.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.remove <package name>
        salt '*' pkg.remove <package1>,<package2>,<package3>
        salt '*' pkg.remove pkgs='["foo", "bar"]'
        salt '*' pkg.remove pkgs='["foo", "bar"]' remove_dependencies=True auto_remove_deps=True
    upkg_resource.parse_targetsiuopkguremoveuremove_dependenciesu%--force-removal-of-dependent-packagesuauto_remove_depsu--autoremoveucmd.run_allR(utraceR)uretcodeustderrustdoutu
pkg.list_pkgsu'Problem encountered removing package(s)RPuerrorsuchangesN(RRRRQRRRRSRZR.RRR*R+R,R[RR(R9R`R6RdR&RftxttargetsR:R;RRqR8R((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytremove�sB#	%
	
	
cK@std|d|�S(ug
    Package purges are not supported by opkg, this function is identical to
    :mod:`pkg.remove <salt.modules.opkg.remove>`.

    name
        The name of the package to be deleted.


    Multiple Package Options:

    pkgs
        A list of packages to delete. Must be passed as a python list. The
        ``name`` parameter will be ignored if this option is passed.


    Returns a dict containing the changes.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.purge <package name>
        salt '*' pkg.purge <package1>,<package2>,<package3>
        salt '*' pkg.purge pkgs='["foo", "bar"]'
    R9R`(Rw(R9R`R6((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytpurgeCsc	K@siid6td6dd6}g}tjjj|�r@t�nt�}ddg}td|dd	d
t�}t	j
dd�t�}tjjj||�}|dd
kr�|j
|�nt|�}|r�tddi|d6|d6��nt|�|S(u/
    Upgrades all packages via ``opkg upgrade``

    Returns a dictionary containing the changes:

    .. code-block:: python

        {'<package>':  {'old': '<old-version>',
                        'new': '<new-version>'}}


    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade
    uchangesuresultuucommentuopkguupgradeucmd.run_allR(utraceR)u
pkg.list_pkgsuretcodeiu&Problem encountered upgrading packagesRPuerrorsN(R/R*R+R,R-R1RQRRRZR.RRR[RRRR(	R7R6R8RRfR:tresultRqR((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytupgrade`s.


	
		
c

K@s�|r$|r$|r$td��n|r?|r?td��ng}|r[|j|�n@|r�x7|D]}|jtt|���qhWn
|j|�i}xF|D]>}t|t�r�tt|��}ni|d6id6td6dd6||<t|�}|s$dj	|�||d<q�|d	kr�d
t
krtt
d
rt||jdd�dj	|�||d<q�t
|d	�}	||jd
|	|dt�dj	|�||d<q�||jdt�dj	|�||d<q�W|S(u�
    Set package in 'hold' state, meaning it will not be upgraded.

    name
        The name of the package, e.g., 'tmux'

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.hold <package name>

    pkgs
        A list of packages to hold. Must be passed as a python list.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.hold pkgs='["foo", "bar"]'
    u0One of name, pkgs, or sources must be specified.u-Only one of pkgs or sources can be specified.unameuchangesuresultuucommentuPackage {0} not currently held.uholdutestRyuPackage {0} is set to be held.tchangesuPackage {0} is now being held.u&Package {0} is already set to be held.N(RRSRtnexttiterRRRt
_get_stateR	RER_RRt
_set_stateR/(
R9R`RaR6RvtsourceR8ttargettstateRy((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pythold�sL
 


c

K@s�|r$|r$|r$td��n|r?|r?td��ng}|r[|j|�n@|r�x7|D]}|jtt|���qhWn
|j|�i}xB|D]:}t|t�r�tt|��}ni|d6id6td6dd6||<t|�}|s$dj	|�||d<q�|d	kr�d
t
krpt
d
rp||jdd�dj	|�|d<q�t
|d
�}	||jd|	|dt�dj	|�||d<q�||jdt�dj	|�||d<q�W|S(u�
    Set package current in 'hold' state to install state,
    meaning it will be upgraded.

    name
        The name of the package, e.g., 'tmux'

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.unhold <package name>

    pkgs
        A list of packages to hold. Must be passed as a python list.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.unhold pkgs='["foo", "bar"]'
    u0One of name, pkgs, or sources must be specified.u-Only one of pkgs or sources can be specified.unameuchangesuresultuucommentu"Package {0} does not have a state.uholdutestRyu"Package {0} is set not to be held.uokR{u$Package {0} is no longer being held.u*Package {0} is already set not to be held.N(RRSRR|R}RRRR~R	RER_RRRR/(
R9R`RaR6RvR�R8R�R�Ry((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytunhold�sL
 


cC@s�ddg}|j|�td|dt�}d}xJtjjj|d�D]0}|jd�rN|j�\}}}}qNqNW|S(uP
    View package state from the opkg database

    Return the state of pkg
    uopkgustatusucmd.runR)uu
uStatus(RRRR*R+R2R3t
startswith(RCR:R;t
state_flagR<t_statust_state_wantt
_state_status((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyR~%s
cC@s�i}d}||kr0tdj|���nt|�}dd	g}|j|�|j|�td
|dt�}i|d6|d
6||<|S(u�
    Change package state on the opkg database

    The state can be any of:

     - hold
     - noprune
     - user
     - ok
     - installed
     - unpacked

    This command is commonly used to mark a specific package to be held from
    being upgraded, that is, to be kept at a certain version.

    Returns a dict containing the package name, and the new and old
    versions.
    uholdunopruneuuseruoku	installeduunpackeduInvalid state: {0}uopkguflagucmd.runR)uoldunew(uholdunopruneuuseruoku	installeduunpacked(RR	R~RRR(RCR�R8tvalid_statestoldstateR:t_out((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyR6s


c	K@sltjjj|�}tgdD]$}tjjj|j|��^q�rPiSdtkr�|rjtdStjtd�}t	d|�|Snddg}i}t	d|dd	d
t
�}xmtjjj|d�D]S}|s�|dd
kr�q�n|jdd�d \}}t	d|||�q�Wt	d|�tj|�td<|sht	d|�n|S(u�
    List the packages currently installed in a dict::

        {'<package_name>': '<version>'}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_pkgs
        salt '*' pkg.list_pkgs versions_as_list=True
    uremovedu
purge_desiredu
pkg.list_pkgsupkg_resource.stringifyuopkgulist-installeducmd.runR(utraceR)u
iu u - iupkg_resource.add_pkgupkg_resource.sort_pkglist(uremovedu
purge_desired(
R*R+R,R-tanyRRZRXRYRRR2R3(	tversions_as_listR6RuR8R:R;R<tpkg_nametpkg_version((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyRQYs.
1cK@s�i}tjjj|�r%t�nddg}td|dddt�}|ddkr�d	}d
|kr�||d
7}nd|kr�||d7}nt|��n
|d}x6|j�D](}|j	d�\}}	}
|
||<q�W|S(
u~
    List all available package upgrades.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_upgrades
    uopkgulist-upgradableucmd.run_allR(utraceR)uretcodeiuustderrustdoutu - (
R*R+R,R-R1RRRt
splitlinesR3(R7R6R8R:RItcommentR;R<R9R=R>((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt
list_upgrades�s&


	
cC@s,tj|d�}|dkr(|j�S|S(u�
    Helper function for _process_info_installed_output()

    Converts an opkg attribute name to a standard attribute
    name which is used across 'pkg' modules.
    N(tATTR_MAPRRRtlower(tattrtret_attr((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt_convert_to_standard_attr�s
c	C@soi}d}i}d}x=tjjj|d�D]#}|r�|ddkr�|dkse||kr1|j�}t||�r�||cd7<n||c|7<q1q1n|j�}|s�|r�|||<nd}i}d}q1n|jdd�\}}|j�}t|�}|dkr/|}q1|dksG||kr1|||<q1q1W|rk|||<n|S(uz
    Helper function for info_installed()

    Processes stdout output from a single invocation of
    'opkg status'.
    u
iu u:iunameN(	RRR*R+R2R3RFR0tlstripR�(	R;tfilter_attrsR8R9tattrsR�R<RKtvalue((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyR\�s<
	
c	O@s�|jdd�}|dkr'd}n6t|tj�rQt|jd��}nt|�}i}|rx4|D]�}dd|g}td|dddt�}|d	d
kr�d}|dr�||d7}n||d
7}t	|��n|j
t|d
|��qpWn�ddg}td|dddt�}|d	d
kr�d}|dri||d7}n||d
7}t	|��n|j
t|d
|��|S(u%
    Return the information of the named package(s), installed on the system.

    .. versionadded:: 2017.7.0

    :param names:
        Names of the packages to get information about. If none are specified,
        will return information for all installed packages.

    :param attr:
        Comma-separated package attributes. If no 'attr' is specified, all available attributes returned.

        Valid attributes are:
            arch, conffiles, conflicts, depends, description, filename, group,
            install_date_time_t, md5sum, packager, provides, recommends,
            replaces, size, source, suggests, url, version

    CLI example:

    .. code-block:: bash

        salt '*' pkg.info_installed
        salt '*' pkg.info_installed attr=version,packager
        salt '*' pkg.info_installed <package1>
        salt '*' pkg.info_installed <package1> <package2> <package3> ...
        salt '*' pkg.info_installed <package1> attr=version,packager
        salt '*' pkg.info_installed <package1> <package2> <package3> ... attr=version,packager
    uattru,uopkgustatusucmd.run_allR(utraceR)uretcodeiuustderrustdoutN(R.RRRRtstring_typestsetR3RRRR_R\(	R5R6R�R�R8R9R:RIR�((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytinfo_installed�s@	

	
!
	
cK@st|�dkS(u�
    Check whether or not an upgrade is available for a given package

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade_available <package name>
    u(R?(R9R6((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytupgrade_available/s
c	@s]�fd�}||�}||�}tdddgdddt�}|jd�d	j�}tjjj|�tjjjd
�kr�ddg}n2tjjj	d�r�dg}nt
jd
�dSx�dddfD]x\}}	|}
|
j
t|��|
j
|�|
j
t|��td|
dddtdt�}|dkr�|	Sq�WdS(u�
    Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if
    pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem
    making the comparison.

    ignore_epoch : False
        Set to ``True`` to ignore the epoch when comparing versions

        .. versionadded:: 2016.3.4

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.version_cmp '0.2.4-0' '0.2.4.1-0'
    c@s0�r#tj|�jdd�dStj|�S(Nu:ii����(Rt	text_typeR3(Ru(tignore_epoch(s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt<lambda>Msucmd.run_stdoutuopkgu	--versionR(utraceR)u iu0.3.4ucompare-versionsuopkg-compare-versionsu�Unable to find a compare-versions utility installed. Either upgrade opkg to version > 0.3.4 (preferred) or install the older opkg-compare-versions script.u<<i����u=iu>>iucmd.retcodeRAN(u<<i����(u=i(u>>i(RRR3RFR*R+RUtLooseVersionRtwhichtlogtwarningRRRt
_cmd_quoteR/(tpkg1tpkg2R�R6t	normalizetoutputtopkg_versiontcmd_compareRMR8R:tretcode((R�s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyRW<s4	


	c
K@s{i}tjt�}x_tjt�D]N}|jd�r%tjj	j
tjjt|���}x|D]�}tjj
j|�}|j|�rhi}|jd�r�t|d<|d}n
t|d<tjjj|j��}|ddkrt|d<n
t|d<|d|d<|d	|d
<tjjt|�|d<|d
|krf|g||d
<qfqhqhWWdQXq%q%W|S(
u}
    Lists all repos on ``/etc/opkg/*.conf``

    CLI Example:

    .. code-block:: bash

       salt '*' pkg.list_repos
    u.confu#uenablediiusrcu
compressedunameiuuriufileN(tretcompiletREPO_REGEXPRtlistdirR%tendswithR*R+tfilestfopenRRtstringutilst
to_unicodetsearchR�RR/targstshlex_splitRF(R6trepostregextfilenamet	conf_fileR<trepotcols((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt
list_reposms.
'





(cK@sUt�}|rQx?tj|�D]+}x"|D]}|d|kr,|Sq,WqWniS(u�
    Display a repo from the ``/etc/opkg/*.conf``

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.get_repo repo
    uname(R�Rt
itervalues(R�R6R�R�tsub((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytget_repo�s
	
cC@stjjj|���}g}tjt�}x�|D]�}tjjj|�}|j	|�r4|j
d�rz|d}ntjjj|j
��}||dkr�|jtjjj|��q�q4q4WWdQXtjjj|d��}|j|�WdQXdS(u%
    Remove a repo from filepath
    u#iNuw(R*R+R�R�R�R�R�R�R�R�R�R�R�RFRtto_strt
writelines(R�tfilepathtfhandleR�R�R<R�((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt_del_repo_from_file�s

,cC@s�|sdnd}||r!dnd7}d|krI|d|d7}n||d7}||d7}tjjt|d	�}tjjj|d
��#}|jtjj	j
|��WdQXdS(u
    Add a new repo entry
    u# uusrc/gz usrc u u"u" u
u.confuaN(RRRR%R*R+R�R�twriteR�R�(R�turit
compressedtenabledtrepostrtconffileR�((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt
_add_new_repo�sc	C@s�tjjj|���}g}xt|D]l}tjjjtjjj|�j��}||krq|j	|�q%|j	tjjj
|d��q%WWdQXtjjj|d��}|j|�WdQXdS(u7
    Replace a repo entry in filepath with repostr
    u
Nuw(R*R+R�R�R�R�R�R�RFRR�R�(R�R�R�R�R�R<R�((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt_mod_repo_in_file�s
*cK@s�tjjj|jdt��}t�}|r{t�}xN|D]F}||d}|d|kr@d||d<t||d�q@q@W|r{d}xC|D];}||d}|d|kr�||dcd7<q�q�Wx�t	j
|�D]t\}}	d}
|	dkrJtjj
|�rJd}
ytj|�WqJtk
rFqJXn||
j||�7}q�W|rtt�n|Snd	j|�S(
u�
    Delete a repo from ``/etc/opkg/*.conf``

    If the file does not contain any other repo configuration, the file itself
    will be deleted.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.del_repo repo
    urefreshiunameufileuiu&Repo '{0}' has been removed from {1}.
u1File {1} containing repo '{0}' has been removed.
u-Repo {0} doesn't exist in the opkg repo lists(R*R+R,R-RR/R�RR�RRTRRtisfileRwRR	R1(R�R6R7R�tdeleted_fromt
repositoryR�R8t	repo_filetcounttmsg((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytdel_repo�s8
!		



cK@s0t�}t}d}d|kr.|d}nxi|D]a}||d}|d|krat}d}d|kr�|dr�|d7}nd|kr�||dr�dnd	7}n||dr�d
nd	7}d|kr�|dn|}d|kr
|d
j|�7}n|dj|�7}|djd|kr<|dn|d�7}t|||d�q5|r5|d|kr5tdj||d���q5q5W|sd|kr�tdj|���nd|kr�|dnt}	d|kr�|dnt}
t||d|	|
�nd|kr,t�ndS(u�
    Modify one or more values for a repo.  If the repo does not exist, it will
    be created, so long as uri is defined.

    The following options are available to modify a repo definition:

    repo
        alias by which opkg refers to the repo.
    uri
        the URI to the repo.
    compressed
        defines (True or False) if the index file is compressed
    enabled
        enable or disable (True or False) repository
        but do not remove if disabled.
    refresh
        enable or disable (True or False) auto-refresh of the repositories

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.mod_repo repo uri=http://new/uri
        salt '*' pkg.mod_repo repo enabled=False
    uuuriiunameuenabledu# u
compressedusrc/gz usrcusrc/gzualiasu u "{0}"u {0}ufileu)Repository '{0}' already exists as '{1}'.u;Repository '{0}' not found and no URI passed to create one.urefreshN(R�RR/R	R�RR�R1(R�R6R�tfoundR�R�R�R�t
repo_aliasR�R�((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytmod_reposB	


- cO@sVt|�}g}x+t|dj��D]}|j|�q)Wi|dd6|d6S(uV
    List the files that belong to a package. Not specifying any packages will
    return a list of _every_ file on the system's package database (not
    generally recommended).

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.file_list httpd
        salt '*' pkg.file_list httpd postfix
        salt '*' pkg.file_list
    upackagesuerrorsufiles(t	file_dictR]tvaluesRS(tpackagesR6R�R�tpackage((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt	file_listPs
c
O@sg}i}ddg}|s6tt�j��}nx�|D]�}g}|}|j|�td|dddt�}x^|dj�D]L}	|	jd�r�|j|	�q�|	jd	�r�|j|	d
�Pq�q�q�W|r=|||<q=q=Wi|d6|d6S(
uj
    List the files that belong to a package, grouped by package. Not
    specifying any packages will return a list of _every_ file on the system's
    package database (not generally recommended).

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.file_list httpd
        salt '*' pkg.file_list httpd postfix
        salt '*' pkg.file_list
    uopkgufilesucmd.run_allR(utraceR)ustdoutu/u * iuerrorsupackages(R]RQR^RRRR�R�(
R�R6RR8t	cmd_filesR�R�R:R;R<((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyR�es,


	cO@s�|s
dSi}ddg}xn|D]f}|}|j|�td|dddt�}|r|jd�d	j�||<q#d||<q#Wt|�d
kr�ttj|��S|S(u9
    Return the name of the package that owns the file. Multiple file paths can
    be passed. Like :mod:`pkg.version <salt.modules.opkg.version`, if a single
    path is passed, a string will be returned, and if multiple paths are passed,
    a dictionary of file/package name pairs will be returned.

    If the file is not owned by a package, or is not present on the minion,
    then an empty string will be returned for that path.

    CLI Example:

        salt '*' pkg.owner /usr/bin/apachectl
        salt '*' pkg.owner /usr/bin/apachectl /usr/bin/basename
    uuopkgusearchucmd.run_stdoutR(utraceR)u - ii(	RRRR3RFR0R|RR�(tpathsR6R8t
cmd_searchRR:R�((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pytowner�s 


	 (Ht__doc__t
__future__RRRRXRR�tloggingR tsalt.utils.argsR*tsalt.utils.datatsalt.utils.filestsalt.utils.itertoolstsalt.utils.pathtsalt.utils.pkgtsalt.utils.stringutilstsalt.utils.versionstsalt.exceptionsRRRtsalt.extRtsalt.ext.six.movesRR�R�R%R�t	getLoggert__name__R�R#R
RRRR'R?tavailable_versionR@RR1RRRtRwRxR/RzR�R�R~RRQR�R�R\R�R�RWR�R�R�R�R�R�R�R�R�R�(((s5/usr/lib/python2.7/site-packages/salt/modules/opkg.pyt<module>s�
		
			1	B�Q6GH		#/$		,	I	
1	&				.	E		*

Zerion Mini Shell 1.0