%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/rpmbuild_pkgbuild.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlZddlZddlZddlZddlmZddlmZeZy"ddlZddlZeZWnek
r)nXej e!�Z"dZ#d�Z$d	d
�Z%d	d�Z&dd
�Z'dd	d�Z(d�Z)dd�Z*dddd	d�Z,ddd�Z-ddedd	dd�Z.dS(u�
RPM Package builder system

.. versionadded:: 2015.8.0

This system allows for all of the components to build rpms safely in chrooted
environments. This also provides a function to generate yum repositories

This module implements the pkgbuild interface
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltInvocationError(tsix(turlparseupkgbuildcC@s�t}dddddg}x-|D]%}tjjj|�s"t}Pq"q"Wtr{|r{tjdt�dkrtt	SdSn
td	fSd
S(uR
    Confirm this module is on a RPM based system, and has required utilities
    ugpgurpmurpmbuildumocku
createrepou	os_familyuRedHatuSuseu�The rpmbuild module could not be loaded: requires python-gnupg, gpg, rpm, rpmbuild, mock and createrepo utilities to be installedN(uRedHatuSuse(
tFalsetsalttutilstpathtwhichtTruetHAS_LIBSt
__grains__tgett__virtualname__(tmissing_utilt
utils_reqdt
named_util((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt__virtual__2s

urootcC@s3tjjd�}tjj|d�}tjj|�sYtdd|d|dd�ntjj|d�}tjj|�s�tdd|d|dd�ntjj|d�}tjjj	|d	��`}|j
tjjjd
j
|���|j
d�|j
d�|j
d
�|j
d�WdQXdS(u=
    Create the .rpmmacros file in user's home directory
    u~urpmbuildufile.makedirs_permstnametusertgroupumocku
.rpmmacrosuwu
%_topdir {0}
u%signature gpg
u %_source_filedigest_algorithm 8
u %_binary_filedigest_algorithm 8
u#%_gpg_name packaging@saltstack.com
N(tosR	t
expandusertjointisdirt__salt__RRtfilestfopentwritetstringutilstto_strtformat(trunasthometrpmbuilddirtmockdirt	rpmmacrostafile((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt_create_rpmmacrosHs  


cC@shtj�}dddddg}x@|D]8}tjj||�}tdd|d|d	d
�q(W|S(u#
    Create the rpm build tree
    uBUILDuRPMSuSOURCESuSPECSuSRPMSufile.makedirs_permsRRRumock(ttempfiletmkdtempRR	RR(R"tbasedirtpathsR	tfull((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt_mk_tree`s
!ubasecC@sAtjj|�}tjj|d|�}td||d|�S(u9
    Get the spec file and place it in the SPECS dir
    uSPECSu
cp.get_urltsaltenv(RR	tbasenameRR(t	tree_basetspecttemplateR/tspec_tgttdest((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt	_get_speclscC@s�t|�}tjj|�}tjj|d|�}|jr[td||d|�}ntj||�tdd|d|dd�d	S(
uA
    Get the named sources and place them into the tree_base
    uSOURCESu
cp.get_urlR/u
file.chownR	RRumockN(	t	_urlparseRR	R0RtschemeRtshutiltcopy(R1tsourceR/R"tparsedtsbaseR5tlsrc((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt_get_srcxs	cC@se|jd�}|ddkr5dj|d�}n,|dd
kr[dj|d�}nd	}|S(uD
    Get the distribution string for use with rpmbuild and mock
    u-iuamznu--define "dist .{0}1"iu6u7u--define "dist .el{0}"u(u6u7(tsplitR!(ttgtttgtattrstdistset((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt_get_distset�scC@s�d}|dkr|St|t�s4td��nx�|D]}t|�}tjj|�}tjj||�}|j	r�t
d||d|�ntj||�|dj
|�7}q;W|S(uH
    Get include string for list of dependent rpms to build package
    uu6'deps' must be a Python list or comma-separated stringu
cp.get_urlR/u {0}N(tNonet
isinstancetlistRR7RR	R0RR8RR9R:R!(tdepsR1R/t	deps_listtdeprpmR<tdepbaseR5((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt	_get_deps�s
	cC@s�t|�t|�}t||||�}tdd|d|dd�tdd|d|dd�t|tj�r�|jd�}nx!|D]}	t||	||�q�Wdj	||�}
td|
d	|�}|d
krt
dj	||||���ntjj
|d�}g}
tjj|�sOtd
d|d|dd�nx^tj|�D]M}tjj
||�}tjj
||�}tj||�|
j|�q_W|
S(u�
    Create a source rpm from the given spec file and sources

    CLI Example:

    .. code-block:: bash

        salt '*' pkgbuild.make_src_pkg /var/www/html/
                https://raw.githubusercontent.com/saltstack/libnacl/master/pkg/rpm/python-libnacl.spec
                https://pypi.python.org/packages/source/l/libnacl/libnacl-1.3.5.tar.gz

    This example command should build the libnacl SOURCE package and place it in
    /var/www/html/ on the minion

    .. versionchanged:: 2017.7.0

    dest_dir
        The directory on the minion to place the built package(s)

    spec
        The location of the spec file (used for rpms)

    sources
        The list of package sources

    env
        A dictionary of environment variables to be set prior to execution.

    template
        Run the spec file through a templating engine
        Optional arguement, allows for no templating engine used to be
        if none is desired.

    saltenv
        The saltenv to use for files downloaded from the salt filesever

    runas
        The user to run the build process as

        .. versionadded:: 2018.3.3


    .. note::

        using SHA256 as digest and minimum level dist el6

    u
file.chownR	RRumocku,uFrpmbuild --verbose --define "_topdir {0}" -bs --define "dist .el6" {1}ucmd.retcodeR"iu�Make source package for destination directory {0}, spec {1}, sources {2}, failed with return error {3}, check logs for further detailsuSRPMSufile.makedirs_permsR(R(R.R6RRFRtstring_typesR@R?R!RRR	RRtlistdirR9R:tappend(tdest_dirR2tsourcestenvR3R/R"R1t	spec_pathtsrctcmdtretrctsrpmstrettfn_R-RA((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pytmake_src_pkg�s80

 u/var/log/salt/pkgbuildc

C@s�i}
y!tdd|d|dd�Wn+tk
rT}|jtjkrU�qUnXtjj|d�}tj�}
y"t	|
||||||�}Wn.t
k
r�}tj|
�t
jd�|
SXt|�}d}tj�}t|||�}d	}x:|D]2}tjj|�}tj�}z�y�tdd|d|dd�tdd|d|dd�d
j||�}|td|d|�O}|r�|j�r�d
j||||�}|td|d|�O}|d7}ndj|||||�}|td|d|�O}ddddj|	�|g}td|dt�}x�tj|�D]�}tjj||�}|jd�rtjj||�}y!tdd|d|dd�Wn+tk
r�}|jtjkr��q�nXtj||�|
jdg�j|�qa|jd�rktjj||�}tj||�|
jdg�j|�qatjj||�}y!tdd|d|dd�Wn+tk
r�}|jtjkr��q�nXtj||�|
jdg�j|�qaWWn&t
k
r%}t
jd||�nXWdtj|�XqW|d	kritdj||||���ntj|�tj|
�|
S( uU
    Given the package destination directory, the spec file source and package
    sources, use mock to safely build the rpm defined in the spec file

    CLI Example:

    .. code-block:: bash

        salt '*' pkgbuild.build mock epel-7-x86_64 /var/www/html
                    https://raw.githubusercontent.com/saltstack/libnacl/master/pkg/rpm/python-libnacl.spec
                    https://pypi.python.org/packages/source/l/libnacl/libnacl-1.3.5.tar.gz

    This example command should build the libnacl package for rhel 7 using user
    mock and place it in /var/www/html/ on the minion
    u
file.chownR	RRumockuSRPMSuFailed to make src packageuiu&mock --root={0} --resultdir={1} --initucmd.retcodeR"u1mock --root={0} --resultdir={1} --install {2} {3}u --no-cleanu+mock --root={0} --resultdir={1} {2} {3} {4}urpmu-qpu
--queryformatu'{0}/%{{name}}/%{{version}}-%{{release}}ucmd.run_stdouttpython_shellusrc.rpmufile.makedirs_permsRuSource Packagesu.rpmuPackagesu	Log FilesuError building from %s: %sNu�Building packages for destination directory {0}, spec {1}, sources {2}, failed with return error {3}, check logs for further details(RtOSErrorterrnotEEXISTRR	RR)R*RZt	ExceptionR9trmtreetlogterrorRDRLtdirnameR!tisspaceRRNtendswithR:t
setdefaultROR(R"RARPR2RQRHRRR3R/tlog_dirRXtexctsrpm_dirtsrpm_build_dirRWRCtnocleantdeps_dirRIRVtsrpmtdbasetresults_dirRUtcmdlisttlog_desttfilenameR-tsdesttbdisttlog_file((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pytbuilds�!




		!
!
!

u/etc/salt/gpgkeysg.@cC@stjdtj�}d}d%}	d%}
d}|d%k	r�dj|tddd%��}dj|tddd%��}
|d%ks�|
d%kr�td��ny>tdd	|d
|d|�tdd	|d
|
d|�Wn&tk
rtdj|���nXtd
d	|d|�}x:|D]2}||ddkr%|d}
|d}	Pq%q%W|	d%kr�tdj||���n|r�tdd�}n|
r�dj|
d�}ndj|�}td|d|dt�}|dkr	tdj||���nd}x�tj	|�D]�}|j
d�rtjj||�}||}d}dj|�}dj||�}t
jtjjj|d%�}z>y�d*\}}tjjj|dtd|d td!t�}x�|jre|j�\}}|r|j|�r|j|�n
|d"7}||krUtd#j|t||����ntj|�q�W|j}|dkr�td$j||���nWn;tjjjk
r�}tj�}t j!|||�nXWd%|j"d&td't�XqqWnd(j|�}td)|d|�S(+u�
    Make a package repository and optionally sign packages present

    Given the repodir, create a ``yum`` repository out of the rpms therein
    and optionally sign it and packages present, the name is directory to
    turn into a repo. This state is best used with onchanges linked to
    your package building states.

    repodir
        The directory to find packages that will be in the repository.

    keyid
        .. versionchanged:: 2016.3.0

        Optional Key ID to use in signing packages and repository.
        Utilizes Public and Private keys associated with keyid which have
        been loaded into the minion's Pillar data.

        For example, contents from a Pillar data file with named Public
        and Private keys as follows:

        .. code-block:: yaml

            gpg_pkg_priv_key: |
              -----BEGIN PGP PRIVATE KEY BLOCK-----
              Version: GnuPG v1

              lQO+BFciIfQBCADAPCtzx7I5Rl32escCMZsPzaEKWe7bIX1em4KCKkBoX47IG54b
              w82PCE8Y1jF/9Uk2m3RKVWp3YcLlc7Ap3gj6VO4ysvVz28UbnhPxsIkOlf2cq8qc
              .
              .
              Ebe+8JCQTwqSXPRTzXmy/b5WXDeM79CkLWvuGpXFor76D+ECMRPv/rawukEcNptn
              R5OmgHqvydEnO4pWbn8JzQO9YX/Us0SMHBVzLC8eIi5ZIopzalvX
              =JvW8
              -----END PGP PRIVATE KEY BLOCK-----

            gpg_pkg_priv_keyname: gpg_pkg_key.pem

            gpg_pkg_pub_key: |
              -----BEGIN PGP PUBLIC KEY BLOCK-----
              Version: GnuPG v1

              mQENBFciIfQBCADAPCtzx7I5Rl32escCMZsPzaEKWe7bIX1em4KCKkBoX47IG54b
              w82PCE8Y1jF/9Uk2m3RKVWp3YcLlc7Ap3gj6VO4ysvVz28UbnhPxsIkOlf2cq8qc
              .
              .
              bYP7t5iwJmQzRMyFInYRt77wkJBPCpJc9FPNebL9vlZcN4zv0KQta+4alcWivvoP
              4QIxE+/+trC6QRw2m2dHk6aAeq/J0Sc7ilZufwnNA71hf9SzRIwcFXMsLx4iLlki
              inNqW9c=
              =s1CX
              -----END PGP PUBLIC KEY BLOCK-----

            gpg_pkg_pub_keyname: gpg_pkg_key.pub

    env
        .. versionchanged:: 2016.3.0

        A dictionary of environment variables to be utilized in creating the
        repository.

        .. note::

            This parameter is not used for making ``yum`` repositories.

    use_passphrase : False
        .. versionadded:: 2016.3.0

        Use a passphrase with the signing key presented in ``keyid``.
        Passphrase is received from Pillar data which could be passed on the
        command line with ``pillar`` parameter. For example:

        .. code-block:: bash

            pillar='{ "gpg_passphrase" : "my_passphrase" }'

    gnupghome : /etc/salt/gpgkeys
        .. versionadded:: 2016.3.0

        Location where GPG related files are stored, used with ``keyid``.

    runas : root
        .. versionadded:: 2016.3.0

        User to create the repository as, and optionally sign packages.

        .. note::

            Ensure the user has correct permissions to any files and
            directories which are to be utilized.

    timeout : 15.0
        .. versionadded:: 2016.3.4

        Timeout in seconds to wait for the prompt for inputting the passphrase.

    CLI Example:

    .. code-block:: bash

        salt '*' pkgbuild.make_repo /var/www/html/

    uEnter pass phrase: uu{0}/{1}u
pillar.getugpg_pkg_pub_keynameugpg_pkg_priv_keynameuJPillar data should contain Public and Private keys associated with 'keyid'ugpg.import_keyRRrt	gnupghomeu[Public and Private key files associated with Pillar data and 'keyid' {0} could not be foundu
gpg.list_keysukeyidiuuidsu8The key ID '{0}' was not found in GnuPG keyring at '{1}'ugpg_passphraseu4--define='%_signature gpg' --define='%_gpg_name {0}'iurpm --import {0}ucmd.retcodeR"tuse_vtu_Failed to import public key from file {0} with return error {1}, check logs for further detailsg�?u.rpmuFailed to sign file {0}urpm {0} --addsign {1}tshellt
preexec_fnt
stream_stdoutt
stream_stderriu>Attemping to sign file {0} failed, timed out after {1} secondsu,Signing file {0} failed with proc.status {1}Nt	terminatetkillucreaterepo --update {0}ucmd.run_all(NN(#tretcompiletMRER!RRRRRNReR	Rt	functoolstpartialRRRtchugid_and_umasktvttTerminalthas_unread_datatrecvtsearchtsendlinetintttimetsleept
exitstatustTerminalExceptiont	tracebackt
format_excRaRbtclose(trepodirtkeyidRRtuse_passphraseRwR"ttimeouttSIGN_PROMPT_REtdefine_gpg_nametlocal_keyidt
local_uidstphrasetpkg_pub_key_filetpkg_priv_key_filet
local_keystgpg_keyRURVtintervaltfileusedtabs_filetnumber_retriesttimes_loopedt	error_msgRztstdouttstderrtproctproc_exitstatusterrttrace((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt	make_repoys�m!




	
	!(/t__doc__t
__future__RRRR]tloggingRR9R)R�RR�R�tsalt.exceptionsRtsalt.utils.filesRtsalt.utils.pathtsalt.utils.usert
salt.utils.vttsalt.extRtsalt.ext.six.moves.urllib.parseRR7RRtgnupgtsalt.modules.gpgRtImportErrort	getLoggert__name__RaRRR(R.R6R?RDRLRERZRvR�(((sB/usr/lib/python2.7/site-packages/salt/modules/rpmbuild_pkgbuild.pyt<module>sT

		\m

Zerion Mini Shell 1.0