%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyo

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZddl	m
Z
ddlZddl
ZddlZddlZddl	ZddlmZddlmZyddlZeZWnek
r�eZnXyddlZeZWnek
reZnXddlmZmZeje �Z!dZ"d	�Z#d
d�Z$d�Z%d
�Z&d�Z'd�Z(d�Z)d�Z*ej+j,j-j.d�ej+j,j-j.d�ej+j,j-j.d�d����Z/d�Z0ed�Z1d�Z2dS(u
Support for rpm
i(tabsolute_importtprint_functiontunicode_literalsN(tLooseVersion(tzip(tsix(tCommandExecutionErrortSaltInvocationErrorulowpkgcC@s�tjjjd�stdfSy$tdj�}tdj�}Wntk
r]tdfSXd
}|dks|||kr�tStdfS(u2
    Confine this module to rpm based systems
    urpmuGThe rpm execution module failed to load: rpm binary is not in the path.uosu	os_familyuQThe rpm execution module failed to load: failed to detect os or os_family grains.uamazonuxcpu	xenserveruVirtuozzoLinuxuredhatususeupThe rpm execution module failed to load: only available on redhat/suse type systems or amazon, xcp or xenserver.(uamazonuxcpu	xenserveruVirtuozzoLinux(uredhatususe(	tsalttutilstpathtwhichtFalset
__grains__tlowert	Exceptiont__virtualname__(tos_graint	os_familytenabled((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt__virtual__-s

ubasecC@s\td|�rMtd||�}|sDtdj||���n|}nTtjj|�swtdj|���n*tjj|�s�tdj|���ntj	j
jjj
dd�}tddd	d
||gddd
tdt�}i}tj	j
jj|dtd�}y+x$|jD]}t||�||<q%WWntk
rWdSX|S(u
    .. versionadded:: 2015.8.0

    Parses RPM metadata and returns a dictionary of information about the
    package (name, version, etc.).

    path
        Path to the file. Can either be an absolute path to a file on the
        minion, or a salt fileserver URL (e.g. ``salt://path/to/file.rpm``).
        If a salt fileserver URL is passed, the file will be cached to the
        minion so that it can be examined.

    saltenv : base
        Salt fileserver envrionment from which to retrieve the package. Ignored
        if ``path`` is a local file path on the minion.

    CLI Example:

    .. code-block:: bash

        salt '*' lowpkg.bin_pkg_info /root/salt-2015.5.1-2.el7.noarch.rpm
        salt '*' lowpkg.bin_pkg_info salt://salt-2015.5.1-2.el7.noarch.rpm
    uconfig.valid_fileprotou
cp.cache_fileu)Unable to retrieve {0} from saltenv '{1}'u{0} does not exist on minionu	%{REPOID}unoneucmd.run_stdouturpmu-qpu
--queryformattoutput_loglevelutracetignore_retcodetpython_shelltosarchuosarchN(t__salt__RtformattosR
texiststisabsRRR	tpkgtrpmtQUERYFORMATtreplacetTrueRt
parse_pkginfoR
t_fieldstgetattrtAttributeErrortNone(R
tsaltenvtnewpathtqueryformattoutputtrettpkginfotfield((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pytbin_pkg_infoAs:		

cG@s�i}d|rdndddg}|r:|j|�ntd|ddd	t�}xPtjjj|d
�D]6}d|kr�qon|j�}|d||d
<qoW|S(u�
    List the packages currently installed in a dict::

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

    CLI Example:

    .. code-block:: bash

        salt '*' lowpkg.list_pkgs
    urpmu-qu-qau
--queryformatu%{NAME} %{VERSION}\nucmd.runRutraceRu
uis not installedii(textendRRRR	t	itertoolstsplit(tpackagestpkgstcmdtouttlinetcomps((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt	list_pkgs�sc
O@s�idd6dd6dd6dd6d	d
6}i}|jdg�}t|ttjf�shtd��nt|tj�r�y,g|jd
�D]}|j�^q�}Wq�tk
r�gtj	|�jd
�D]}|j�^q�}q�Xn|jdg�}t|ttjf�s'td��nt|tj�r�y,g|jd
�D]}|j�^qL}Wq�tk
r�gtj	|�jd
�D]}|j�^q�}q�Xndg}|j
g|D]}d|^q��|r�|jd�|j
|�n
|jd�td|dddt
dt�}|dj�r�|ddkr�d}	|drw|	dj|d�7}	nt|	��nxtjjj|dd�D]�}
igd 6}d!|
kr�d"|
}
t
|d!<|d =n|
d#}|
d$d%!|kr||
d$d%!|d&<nd&|ks1|d&|kr�|
dd'!d(krX|d jd)�n|
d'd*!d+kr|d jd,�n|
d*d-!d.kr�|d jd/�n|
d-d0!d1kr�|d jd2�n|
d0d3!d4kr�|d jd5�n|
d3d6!d7kr|d jd8�n|
d6d9!d:krB|d jd;�n|
d9d<!d=kri|d jd>�n|
d<d?!d@kr�|d jdA�n|||<q�q�W|S(Bu�
    Runs an rpm -Va on a system, and returns the results in a dict

    Files with an attribute of config, doc, ghost, license or readme in the
    package header can be ignored using the ``ignore_types`` keyword argument

    CLI Example:

    .. code-block:: bash

        salt '*' lowpkg.verify
        salt '*' lowpkg.verify httpd
        salt '*' lowpkg.verify httpd postfix
        salt '*' lowpkg.verify httpd postfix ignore_types=['config','doc']
    uconfigucudocudughostugulicenseulureadmeuruignore_typesu7ignore_types must be a list or a comma-separated stringu,uverify_optionsu9verify_options must be a list or a comma-separated stringurpmu--u-Vu-Vaucmd.run_allRutraceRRustdouturetcodeiuFailed to verify package(s)ustderru: {0}u
umismatchumissingu i
iiutypeiuSusizeiuMumodeiu5umd5sumiuDudevice major/minor numberiuLu
readlink pathiuUuuseriuGugroupiuTumtimei	uPucapabilities(tgett
isinstancetlistRtstring_typesRR2tstripR&t	text_typeR0tappendRR"RRRRR	R1(
R3tkwargstftypesR,tignore_typestxtverify_optionsR5R6tmsgR7tfdicttfname((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pytverify�s�

,
8,
8	$


	!
#




c
O@sFtdddgt|�dddt�}i}|ddkrM|d	=|S|ds[|Stjd
�}d}}}x tjjj	|d	d�D]}|j	|�}t
|�dkr�|\}}}n|\}}d}d
ddddddddg	}	t|�}t
|�dkr/|jd�ng}
x9t|	|�D](\}}|dkrE|
j|�qEqEW|dk	r�|
jd�n|
||<q�W|s�|Si}
x�|j
�D]�\}}
t}x^|j
�D]P\}}|jd�r�q�n|r||
ks|r�||
kr�t}Pq�q�W|r�|
|
|<q�q�W|
S(ui
    List the modified files that belong to a package. Not specifying any packages
    will return a list of _all_ modified files on the system's RPM database.

    .. versionadded:: 2015.5.0

    CLI examples:

    .. code-block:: bash

        salt '*' lowpkg.modified httpd
        salt '*' lowpkg.modified httpd postfix
        salt '*' lowpkg.modified
    ucmd.run_allurpmu-VaRutraceRuretcodeiustdoutu\s+u
iusizeumodeuchecksumudeviceusymlinkuownerugrouputimeucapabilitiesiu.uconfigu_N(RR<RtretcompileR'RR	R1R2tlenR@RtitemsR"t
startswith(R3tflagsR,tdatatptrntchangestcfgtf_nametf_infotkeyststatstktvt
filtered_datatincludetparamtpval((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pytmodified�sZ	
#cG@sb|sddg}nddg}|j|�td|dddt�j�}igd6|d	6S(
u[
    List the files that belong to a package. Not specifying any packages will
    return a list of _every_ file on the system's rpm database (not generally
    recommended).

    CLI Examples:

    .. code-block:: bash

        salt '*' lowpkg.file_list httpd
        salt '*' lowpkg.file_list httpd postfix
        salt '*' lowpkg.file_list
    urpmu-qlau-qlucmd.runRutraceRuerrorsufiles(R0RRt
splitlines(R3R5R,((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt	file_listGs
c
G@s6g}i}i}d|r!dndddg}|rF|j|�ntd|ddd	t�}xdtjjj|d
�D]J}d|kr�|j|�q{n|j�}i|dd
6||d<q{WxX|D]P}g}	dd|g}tddd|gddd	t�}|j�||<q�Wi|d6|d6S(ul
    List the files that belong to a package, sorted by group. Not specifying
    any packages will return a list of _every_ file on the system's rpm
    database (not generally recommended).

    CLI Examples:

    .. code-block:: bash

        salt '*' lowpkg.file_dict httpd
        salt '*' lowpkg.file_dict httpd postfix
        salt '*' lowpkg.file_dict
    urpmu-qu-qau
--queryformatu%{NAME} %{VERSION}\nucmd.runRutraceRu
uis not installediuversioniu-qluerrorsupackages(	R0RRRR	R1R2R@R_(
R3terrorsR,R4R5R6R7R8Rtfiles((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt	file_dictbs.

	cG@s�|s
dSi}xf|D]^}dddd|g}td|ddd	t�||<d
||j�krd||<qqWt|�dkr�t|j��dS|S(
u/
    Return the name of the package that owns the file. Multiple file paths can
    be passed. 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 Examples:

    .. code-block:: bash

        salt '*' lowpkg.owner /usr/bin/apachectl
        salt '*' lowpkg.owner /usr/bin/apachectl /etc/httpd/conf/httpd.conf
    uurpmu-qfu
--queryformatu%{name}ucmd.run_stdoutRutraceRu	not ownedii(RRRRLR<tvalues(tpathsR,R
R5((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pytowner�s


urpm2cpioucpioudiffcC@sNd}td|j||�dd�}|rJ|jd�rJdj|�S|S(u�
    Return a formatted diff between current file and original in a package.
    NOTE: this function includes all files (configuration and not), but does
    not work on binary content.

    :param package: Full pack of the RPM file
    :param path: Full path to the installed file
    :return: Difference or empty string. For binary files only a notification.

    CLI example:

    .. code-block:: bash

        salt '*' lowpkg.diff /path/to/apache2.rpm /etc/apache2/httpd.conf
    ukrpm2cpio {0} | cpio -i --quiet --to-stdout .{1} | diff -u --label 'A {1}' --from-file=- --label 'B {1}' {1}u	cmd.shellRutraceuBinary fileu7File '{0}' is binary and its content has been modified.(RRRN(tpackage_pathR
R5tres((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pytdiff�s	cO@sD|jdt�}tdddgdt�j�}d|krId}nd}|rmd	jd
j|��ppd}idd
6dd6dd6dd6dd6dd6dd6dd6dd6dd6d d!6d"d#6d$d%6d&|d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86}|jd9dV�r@|d9jd:�pCdV}t�}|rx:|D]2}	|	|kr\|	d6kr\|j	||	�q\q\W|s�t
d;��nd
|kr�|j	d
�|j	|d
�nd8|kr@|j	d8�|j	|d8�q@n<x9tj|�D](\}	}
|	d6kr|j	|
�qqW|rRd6|ksY|rm|j	|d6�n|j	d<�td=|d>jd?j|��d@dAdBidCdD6dEt
�}|dFdGkrd?}dH|kr�||dHp�|dI7}nt
|��n-dJ|dHkr(t
|dH��n
|dI}
t�}xItjdK|
�D]5}|j�}|slqNn|jtj�}|dLj�jdM�r�|dL }nt�}dV}t}t�}xl|D]d}|r�|j	|�q�ng|jdNdO�D]}|j�^q�}t|�dPkr+q�n|\}}|d6krOt
}q�n|d
krd|}n|dWkr�y*tjjt|��j�dQ||<Wq�tk
r�tjdR|�q�Xq�n|dXkryt|�||<Wq�tk
rtjdR|�q�Xq�n|dYkr�|r�|||<q�q�W|rCd6|ksJ|rctjj|�|d6<n|rN||d
<|j	|�qNqNWt�}x�tt|dSdT���D]�}|jd
�}|jdU�r�q�n||kr|r�|j �g||<q<|j �||<||d8=q�|r�||j	|j ��q�q�W|S(Zu�
    Return a detailed package(s) summary information.
    If no packages specified, all packages will be returned.

    :param packages:

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

        Valid attributes are:
            version, vendor, release, build_date, build_date_time_t, install_date, install_date_time_t,
            build_host, group, source_rpm, arch, epoch, size, license, signature, packager, url, summary, description.

    :param all_versions:
        Return information for all installed versions of the packages

    :return:

    CLI example:

    .. code-block:: bash

        salt '*' lowpkg.info apache2 bash
        salt '*' lowpkg.info apache2 bash attr=version
        salt '*' lowpkg.info apache2 bash attr=version,build_date_iso,size
        salt '*' lowpkg.info apache2 bash attr=version,build_date_iso,size all_versions=True
    uall_versionsucmd.run_stdouturpmu--querytagsRuLONGSIZEu%{LONGSIZE}u%{SIZE}u
rpm -q {0}u urpm -qauname: %{NAME}\nunameu?relocations: %|PREFIXES?{[%{PREFIXES} ]}:{(not relocatable)}|\nurelocationsuversion: %{VERSION}\nuversionuvendor: %{VENDOR}\nuvendorurelease: %{RELEASE}\nureleaseu%|EPOCH?{epoch: %{EPOCH}\n}|uepochu!build_date_time_t: %{BUILDTIME}\nubuild_date_time_tubuild_date: %{BUILDTIME}\nu
build_dateuHinstall_date_time_t: %|INSTALLTIME?{%{INSTALLTIME}}:{(not installed)}|\nuinstall_date_time_tuAinstall_date: %|INSTALLTIME?{%{INSTALLTIME}}:{(not installed)}|\nuinstall_dateubuild_host: %{BUILDHOST}\nu
build_hostugroup: %{GROUP}\nugroupusource_rpm: %{SOURCERPM}\nu
source_rpmusize: u\nusizeuarch: %{ARCH}\nuarchu"%|LICENSE?{license: %{LICENSE}\n}|ulicenseu�signature: %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|\nu	signatureu%%|PACKAGER?{packager: %{PACKAGER}\n}|upackageru%|URL?{url: %{URL}\n}|uurlusummary: %{SUMMARY}\nusummaryudescription:\n%{DESCRIPTION}\nudescriptionu4edition: %|EPOCH?{%{EPOCH}:}|%{VERSION}-%{RELEASE}\nueditionuattru,uNo valid attributes found.u-----\nucmd.run_allu --queryformat '{0}'uRutracetenvuUTCuTZt	clean_envuretcodeiustderrustdoutuerroru----*i����udistributionu:iiuZu%Could not convert "%s" into Unix timetkeycS@st|d�S(Nuedition(R(RD((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt<lambda>esu
gpg-pubkeyN(u
build_dateuinstall_date(ubuild_date_time_tuinstall_date_time_t(udescriptionuname(!R:RRR_RtjoinR'R2R<R@RRt	iteritemsR"RJR>RtlinesepRRNtdictRLtdatetimetutcfromtimestamptintt	isoformatt
ValueErrortlogtwarningtreversedtsortedtpoptcopy(R3RAtall_versionstrpm_tagstsize_tagR5tattr_maptattrtquerytattr_ktattr_vtcalltcommentR6t_rettpkg_infotpkg_datatpkg_nametdescr_markertdescrR7titemRltvalueR,((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pytinfo�s�	$
+	



#
	
		

+	*


	"c	@ss�fd�}||�}||�}yd}trgy
tj}Wqgtk
rctjd�qgXn|dkr�tr�ytj	j
}Wq�tk
r�tjd�q�Xn|dkr�tjj
jd�rtd�}||�}||�}tdd||gdtdtd	t�}|d
dkr.dS|d
dkrBd
S|d
dkrVdStjd|d
|d�q*tjd�n�tjjjj|�\}}}	tjjjj|�\}
}}|	s�|r�d}	}n||||	f|
||f�}
|
dkr&tdj|
���n|
SWn)tk
rV}tjd|||�nXtjjj||dt�S(u�
    .. versionadded:: 2015.8.9

    Do a cmp-style comparison on two packages. Return -1 if ver1 < ver2, 0 if
    ver1 == ver2, and 1 if ver1 > ver2. Return None if there was a problem
    making the comparison.

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

        .. versionadded:: 2015.8.10,2016.3.2

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.version_cmp '0.2-001' '0.2.0.1-002'
    c@s0�r#tj|�jdd�dStj|�S(Nu:ii����(RR?R2(RD(tignore_epoch(s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyRm�s#uwrpm module imported, but it does not have the labelCompare function. Not using rpm.labelCompare for version comparison.u.rpmUtils.miscutils.compareEVR is not availableu
rpmdev-vercmpcS@sBd�}yd|kr"||�SWntk
r=||�SX|S(NcS@s
dj|�S(Nu0:{0}(R(tver((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt_prepend�su:(t	TypeError(R�R�((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt
_ensure_epoch�s	
ucmd.run_allRtredirect_stderrRuretcodeiiiii����u�Failed to interpret results of rpmdev-vercmp output. This is probably a bug, and should be reported. Return code was %s. Output: %sustdoutuUrpmdevtools is not installed, please install it for more accurate version comparisonsuu"Comparison result '{0}' is invalidu4Failed to compare version '%s' to '%s' using RPM: %sR�N(i����ii(R'tHAS_RPMRtlabelCompareR&RwtdebugtHAS_RPMUTILStrpmUtilst	miscutilst
compareEVRRR	R
RRRR"RxRtversion_to_evrRRRtversionstversion_cmp(tver1tver2R�t	normalizetcmp_funcR�tresulttver1_etver1_vtver1_rtver2_etver2_vtver2_rt
cmp_resulttexc((R�s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyR�vsh


		
!!
c
G@s|t�}|std��nxW|D]O}ttd|��omtdddd|gdtdd	d
t�||<q%W|S(u�
    Return if the signature of a RPM file is valid.

    CLI Example:

    .. code-block:: bash

        salt '*' lowpkg.checksum /path/to/package1.rpm
        salt '*' lowpkg.checksum /path/to/package1.rpm /path/to/package2.rpm
    u$No package files has been specified.ufile.file_existsucmd.retcodeurpmu-Ku--quietRRutraceR(RqRtboolRR"R(ReR,tpackage_file((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pytchecksum�s	
(3t__doc__t
__future__RRRtloggingRRJRrtsalt.utils.versionsRtsalt.utils.decorators.pathRtsalt.utils.itertoolstsalt.utils.pathtsalt.utils.pkg.rpmtsalt.ext.six.movesRtsalt.extRRR"R�tImportErrorRtrpmUtils.miscutilsR�R�tsalt.exceptionsRRt	getLoggert__name__RwRRR/R9RIR^R`RcRfR	t
decoratorsR
RRiR�R�R�(((s;/usr/lib/python2.7/site-packages/salt/modules/rpm_lowpkg.pyt<module>sP





	B		a	I		'	 '	�u

Zerion Mini Shell 1.0