%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/win_update.pyc

�
���^c@@s!dZddlmZmZmZddlZddlZddlZddl	Zddl
ZddlmZddl
mZddlmZy"ddlZddlZeZWnek
r�eZnXeje�ZdZd�Zd	efd
��YZdefd��YZd
�Z dS(u/
Classes for working with Windows Update Agent
i(tabsolute_importtprint_functiontunicode_literalsN(tsix(trange(tCommandExecutionErroru
win_updatecC@s0tjjj�stdfSts,tdfStS(Nu$win_update: Not available on Windowsuwin_update: Missing pywin32(tsalttutilstplatformt
is_windowstFalsetHAS_PYWIN32t__virtualname__(((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyt__virtual__s


tUpdatescB@saeZdZidd6dd6Zidd6dd6dd6Zd	�Zd
�Zd�Zd�ZRS(
uU
    Wrapper around the 'Microsoft.Update.UpdateColl' instance
    Adds the list and summary functions. For use by the WindowUpdateAgent class.

    Usage:
    .. code-block:: python

        # Create an instance
        updates = Updates()

        # Bind to the collection object
        found = updates.updates

        # This exposes Collections properties and methods
        # https://msdn.microsoft.com/en-us/library/windows/desktop/aa386107(v=vs.85).aspx
        found.Count
        found.Add

        # To use custom functions, use the original instance
        # Return the number of updates inside the collection
        updates.count()

        # Return a list of updates in the collection and details in a dictionary
        updates.list()

        # Return a summary of the contents of the updates collection
        updates.summary()
    uSoftwareiuDriveriuNever Requires RebootiuAlways Requires RebootuCan Require RebootcC@s2tjjj��tjjd�|_WdQXdS(ud
        Initialize the updates collection. Can be accessed via
        ``Updates.updates``
        uMicrosoft.Update.UpdateCollN(RRtwinapitComtwin32comtclienttDispatchtupdates(tself((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyt__init__LscC@s
|jjS(uN
        Return how many records are in the Microsoft Update Collection

        Returns:
            int: The number of updates in the collection

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            updates = salt.utils.win_update.Updates()
            updates.count()
        (RtCount(R((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pytcountTscC@sW|j�dkrdStjd�i}x'|jD]}i|jjd6tj|j�d6|j	|j
d6|jd6t|j
�d6t|j�d	6t|j�d
6t|j�d6t|j�d6tj|j�d
6t|jj�d6|j|jjd6g|jD]}d|^qd6g|jD]}|j^q,d6||jj<q3W|S(uK
        Create a dictionary with the details for the updates in the collection.

        Returns:
            dict: Details about each update

        .. code-block:: cfg

            List of Updates:
            {'<GUID>': {'Title': <title>,
                        'KB': <KB>,
                        'GUID': <the globally unique identifier for the update>
                        'Description': <description>,
                        'Downloaded': <has the update been downloaded>,
                        'Installed': <has the update been installed>,
                        'Mandatory': <is the update mandatory>,
                        'UserInput': <is user input required>,
                        'EULAAccepted': <has the EULA been accepted>,
                        'Severity': <update severity>,
                        'NeedsReboot': <is the update installed and awaiting reboot>,
                        'RebootBehavior': <will the update require a reboot>,
                        'Categories': [ '<category 1>',
                                        '<category 2>',
                                        ...]
                        }
            }

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            updates = salt.utils.win_update.Updates()
            updates.list()
        iuNothing to returnu*Building a detailed report of the results.uguiduTitleuTypeuDescriptionu
Downloadedu	Installedu	MandatoryuEULAAccepteduNeedsRebootuSeverityu	UserInputuRebootBehavioruKBuKBsu
Categories(RtlogtdebugRtIdentitytUpdateIDRt	text_typetTitletupdate_typestTypetDescriptiontbooltIsDownloadedtIsInstalledtIsMandatorytEulaAcceptedtRebootRequiredtMsrcSeveritytInstallationBehaviortCanRequestUserInputtreboot_behaviortRebootBehaviortKBArticleIDst
CategoriestName(Rtresultstupdatetitem((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pytlistes,%


!1cC@s�|j�dkrdSidd6dd6dd6dd6id6id6}xq|jD]f}|dcd	7<tjjj|j�r�tjjj|j�r�|dcd	7<ntjjj|j�r�tjjj|j�r�|dcd	7<ntjjj|j�r|dcd	7<nxO|jD]D}|j	|dkrW|d|j	cd	7<q$d	|d|j	<q$W|j
rP|j
|dkr�|d|j
cd	7<q�d	|d|j
<qPqPW|S(
uq
        Create a dictionary with a summary of the updates in the collection.

        Returns:
            dict: Summary of the contents of the collection

        .. code-block:: cfg

            Summary of Updates:
            {'Total': <total number of updates returned>,
             'Available': <updates that are not downloaded or installed>,
             'Downloaded': <updates that are downloaded but not installed>,
             'Installed': <updates installed (usually 0 unless installed=True)>,
             'Categories': { <category 1>: <total for that category>,
                             <category 2>: <total for category 2>,
                             ... }
            }
        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            updates = salt.utils.win_update.Updates()
            updates.summary()
        iuNothing to returnuTotalu	Availableu
Downloadedu	Installedu
CategoriesuSeverityi(RRRRtdatatis_trueR#R$R.R/R((RR0R1tcategory((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pytsummary�s6

	(	t__name__t
__module__t__doc__RR+RRR3R7(((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyR's



			DtWindowsUpdateAgentc	B@s,eZdZidd6dd6dd6dd6d	d
6dd6d
d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26Zd3�Zd4�Zd5�Zeeeeeed<d<d6�Z
d7�Zd8�Zd9�Z
d:�Zd;�ZRS(=u:
    Class for working with the Windows update agent

    u'WinHTTP Send/Receive failed: 0x8024402Ci,@$�uDownload failed: 0x80240034i4$�u#Invalid search criteria: 0x80240032i2$�uCancelled by policy: 0x8024002Fi/$�uMissing source: 0x8024002Di-$�uMissing source: 0x8024002Ci,$�u!Uninstall not allowed: 0x80240028i($�uPrevented by policy: 0x80240025i%$�uNo Updates: 0x80240024i$$�u"Service being shutdown: 0x8024001Ei$�u#Self Update in Progress: 0x8024001Bi$�u&Exclusive Install Conflict: 0x80240019i$�uInstall not allowed: 0x80240016i$�uDuplicate item: 0x80240013i$�uOperation cancelled: 0x8024000Bi$�u!Operation in progress: 0x80240009i	$�uAccess Denied: 0x8024044iD$�u$Unsupported search scope: 0x80240045iE$�uAccess is denied: 0x80070005i�uSetup in progress: 0x8024004AI�������u!Install still pending: 0x00242015I $����uAlready downloaded: 0x00240008I$����uAlready uninstalled: 0x00240007I$����uAlready installed: 0x00240006I$����uReboot required: 0x00240005I$����cC@sQtjjj��/tjjd�|_tjjd�|_WdQX|j	�dS(u"
        Initialize the session and load all updates into the ``_updates``
        collection. This collection is used by the other class functions instead
        of querying Windows update (expensive).

        Need to look at the possibility of loading this into ``__context__``
        uMicrosoft.Update.SessionuMicrosoft.Update.UpdateCollN(
RRRRRRRt_sessiont_updatestrefresh(R((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyRs	cC@s7t�}|j}x|jD]}|j|�qW|S(u*
        Get the contents of ``_updates`` (all updates) and puts them in an
        Updates class to expose the list and summary functions.

        Returns:
            Updates: An instance of the Updates class with all updates for the
            system.

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()
            updates = wua.updates()

            # To get a list
            updates.list()

            # To get a summary
            updates.summary()
        (RRR=tAdd(RRtfoundR1((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyR*s
		c
C@s�d}|jj�}d|j_yB|j|�}|jjdkrbtjd|�dj|�SWn�t	j
k
r�}|j\}}}}y|j|d}	Wn t
k
r�dj|�}	nXtjd|	|�t|	��nX|j|_d	S(
u�
        Refresh the contents of the ``_updates`` collection. This gets all
        updates in the Windows Update system and loads them into the collection.
        This is the part that is slow.

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()
            wua.refresh()
        u Type='Software' or Type='Driver'uSalt: Load UpdatesiuNo Updates found for:
		%suNo Updates found: {0}iuUnknown Failure: {0}uSearch Failed: %s
		%sN(R<tCreateUpdateSearchertClientApplicationIDtSearchRRRRtformatt
pywintypest	com_errortargst
fail_codestKeyErrorterrorRR=(
Rt
search_stringtsearcherR0RJthrtmsgtexctargtfailure_code((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyR>Gs"
c	
C@sst�}	|	j}
xZ|jD]O}tjjj|j�rF|rFqntjjj|j�rj|rjqntjjj|j	�r�|r�qntjjj|j
j�r�|r�qn|r�|jdkr�qn|r�|jdkr�qn|dk	r:t}x)|jD]}
|
j|kr	t}q	q	W|s:qq:n|dk	r^|j|kr^qq^n|
j|�qW|	S(uQ
        Gets a list of all updates available on the system that match the passed
        criteria.

        Args:

            skip_hidden (bool): Skip hidden updates. Default is True

            skip_installed (bool): Skip installed updates. Default is True

            skip_mandatory (bool): Skip mandatory updates. Default is False

            skip_reboot (bool): Skip updates that can or do require reboot.
            Default is False

            software (bool): Include software updates. Default is True

            drivers (bool): Include driver updates. Default is True

            categories (list): Include updates that have these categories.
            Default is none (all categories).

                Categories include the following:

                * Critical Updates
                * Definition Updates
                * Drivers (make sure you set drivers=True)
                * Feature Packs
                * Security Updates
                * Update Rollups
                * Updates
                * Update Rollups
                * Windows 7
                * Windows 8.1
                * Windows 8.1 drivers
                * Windows 8.1 and later drivers
                * Windows Defender

            severities (list): Include updates that have these severities.
            Default is none (all severities).

                Severities include the following:

                * Critical
                * Important

        .. note:: All updates are either software or driver updates. If both
        ``software`` and ``drivers`` is False, nothing will be returned.

        Returns:

            Updates: An instance of Updates with the results of the search.

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # Gets all updates and shows a summary
            updates = wua.available
            updates.summary()

            # Get a list of Critical updates
            updates = wua.available(categories=['Critical Updates'])
            updates.list()
        iiN(RRR=RRR4R5tIsHiddenR$R%R)R,R tNoneR
R.R/tTrueR(R?(Rtskip_hiddentskip_installedtskip_mandatorytskip_reboottsoftwaretdriverst
categoriest
severitiesRR@R1tmatchR6((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyt	availableps8N		
		cC@s5t�}|j}t|tj�r0|g}nt|tj�rWtj|�g}nx�|jD]�}x�|D]�}||jj	kr�|j
|�qnn|g|jD]}d|^q�kr�|j
|�qnn|g|jD]}|^q�kr|j
|�qnn||jkrn|j
|�qnqnqnWqaW|S(u+
        Search for either a single update or a specific list of updates. GUIDs
        are searched first, then KB numbers, and finally Titles.

        Args:

            search_string (str, list): The search string to use to find the
            update. This can be the GUID or KB of the update (preferred). It can
            also be the full Title of the update or any part of the Title. A
            partial Title search is less specific and can return multiple
            results.

        Returns:
            Updates: An instance of Updates with the results of the search

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # search for a single update and show its details
            updates = wua.search('KB3194343')
            updates.list()

            # search for a list of updates and show their details
            updates = wua.search(['KB3195432', '12345678-abcd-1234-abcd-1234567890ab'])
            updates.list()
        uKB(
RRt
isinstanceRtstring_typest
integer_typesRR=RRR?R-R(RRKRR@R1tfindR2((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pytsearch�s*		

&
"

cC@s$|j�dkr*itd6dd6}|S|jj�}d|j_tjjj��t	j
jd�}WdQXiid6}x�|jD]�}|j
j}i|d|<|j|d|d<t|j�|d|d	<tjjj|j�stjd
|j�|j�ntjjj|j�s�tjd|�tjd|j�|j|�q�q�W|jdkr�itd6dd6}|S||_ytjd
�|j�}Wntjk
r,}|j\}	}
}}y|j |d}
Wn t!k
rdj"|�}
nXtj#d|
�t$|
��nXidd6dd6dd6dd6dd6dd6}tjd�tj||j%�||j%|d<|j%dkr�tjd�t|d<ntjd�t|d<xNt&|j�D]=}|j'|�j
j}||j(|�j%|d|d<q�W|S( u�
        Download the updates passed in the updates collection. Load the updates
        collection using ``search`` or ``available``

        Args:

            updates (Updates): An instance of the Updates class containing a
            the updates to be downloaded.

        Returns:
            dict: A dictionary containing the results of the download

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # Download KB3195454
            updates = wua.search('KB3195454')
            results = wua.download(updates)
        iuSuccessuNothing to downloaduUpdatesuSalt: Download UpdateuMicrosoft.Update.UpdateCollNuTitleuAlreadyDownloadeduAccepting EULA: %suTo Be Downloaded: %su
	Title: %suDownloading UpdatesiuUnknown Failure: {0}uDownload Failed: %suDownload Not StarteduDownload In ProgressiuDownload SucceedediuDownload Succeeded With ErrorsiuDownload FailediuDownload AborteduDownload CompleteuMessageuDownloaded SuccessfullyuResult(ii()RR
R<tCreateUpdateDownloaderRBRRRRRRRRRRRR"R#R4R5R&RRt
AcceptEulaR?RRTRtDownloadRERFRGRHRIRDRJRt
ResultCodeRtItemtGetUpdateResult(RRtrett
downloadert
download_listR1tuidtresultRJRMRNRORPRQtresult_codeti((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pytdownload(sn





	








&cC@s?|j�dkr*itd6dd6}|S|jj�}d|j_tjjj��t	j
jd�}WdQXiid6}x�|jD]�}|j
j}i|d|<|j|d|d<t|j�|d|d	<tjjj|j�s�tjd
|�tjd|j�|j|�q�q�W|jdkrMitd6dd6}|S||_ytjd�|j�}Wntjk
r�}|j\}	}
}}y|j|d
}
Wn tk
r�dj |�}
nXtj!d|
�t"|
��nXidd6dd6dd6dd6dd6dd
6}tjd�tj||j#�||j#|d<|j#d$kr�t|d<|j$|d<tjd|j$�ntjd�t|d<idd6d d6d!d6}xst%|j�D]b}|j&|�j
j}||j'|�j#|d|d"<||j&|�j(j)|d|d#<q�W|S(%u
        Install the updates passed in the updates collection. Load the updates
        collection using the ``search`` or ``available`` functions. If the
        updates need to be downloaded, use the ``download`` function.

        Args:

            updates (Updates): An instance of the Updates class containing a
            the updates to be installed.

        Returns:
            dict: A dictionary containing the results of the installation

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # install KB3195454
            updates = wua.search('KB3195454')
            results = wua.download(updates)
            results = wua.install(updates)
        iuSuccessuNothing to installuUpdatesuSalt: Install UpdateuMicrosoft.Update.UpdateCollNuTitleuAlreadyInstalleduTo Be Installed: %su
	Title: %suInstalling UpdatesiuUnknown Failure: {0}uInstall Failed: %suInstallation Not StarteduInstallation In ProgressiuInstallation Succeedediu"Installation Succeeded With ErrorsiuInstallation FailediuInstallation AborteduInstall CompleteuMessageuNeedsRebootuNeedsReboot: %suInstall FaileduNever Rebootu
Always RebootuPoss RebootuResultuRebootBehavior(ii(*RR
R<tCreateUpdateInstallerRBRRRRRRRRRRRR"R$R4R5RRR?RRTRtInstallRERFRGRHRIRDRJRRgR'RRhRiR)R,(RRRjt	installertinstall_listR1RmRnRJRMRNRORPRQRotrebootRp((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pytinstall�sr




	










")c
C@s�|j�dkr*itd6dd6}|S|jj�}d|j_tjjj��t	j
jd�}WdQXiid6}x�|jD]�}|j
j}i|d|<|j|d|d<t|j�|d|d	<tjjj|j�r�tjd
|�tjd|j�|j|�q�q�W|jdkrNitd6dd6}|S||_ytjd�|j�}Wn�tjk
r6}|j\}	}
}}y|j|d
}
Wn tk
r�dj|�}
nX|d
dkrtjd�y�x�|D]�}x�|j D]�}dddg}|j!|�dj"�}xr|D]j}d||j#�krB|j$d�d}||d<ddddj|�ddg}|j!|�qBqBWq
Wq�WWn^t%k
r}tjd�tjddj&|��tjd|�t%d j|���nXtjd!�t'|d<d"|d#<t(�|d$<tjd%|d$�|j)�id&d6d'd6d(d)6}x�|j*D]�}|j
j}xo|D]g}|j
j|kr�|js�d*|d|d+<nd,|d|d+<||j+j,|d|d-<q�q�Wq�W|Stj-d.|
�t%|
��nXid/d6d0d6d*d)6d1d26d,d36d4d
6}tjd5�tj||j.�||j.|d#<|j.d7kr�t'|d<|j/|d$<tjd%|j/�ntjd6�t|d<id&d6d'd6d(d)6}xst0|j�D]b}|j1|�j
j}||j2|�j.|d|d+<||j1|�j+j,|d|d-<qW|S(8u)
        Uninstall the updates passed in the updates collection. Load the updates
        collection using the ``search`` or ``available`` functions.

        .. note:: Starting with Windows 10 the Windows Update Agent is unable to
        uninstall updates. An ``Uninstall Not Allowed`` error is returned. If
        this error is encountered this function will instead attempt to use
        ``dism.exe`` to perform the uninstallation. ``dism.exe`` may fail to
        to find the KB number for the package. In that case, removal will fail.

        Args:

            updates (Updates): An instance of the Updates class containing a
            the updates to be uninstalled.

        Returns:
            dict: A dictionary containing the results of the uninstallation

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # uninstall KB3195454
            updates = wua.search('KB3195454')
            results = wua.uninstall(updates)
        iuSuccessuNothing to uninstalluUpdatesuSalt: Install UpdateuMicrosoft.Update.UpdateCollNuTitleuAlreadyUninstalleduTo Be Uninstalled: %su
	Title: %suUninstalling UpdatesiuUnknown Failure: {0}i($�u/Uninstall Failed with WUA, attempting with DISMudismu/Onlineu
/Get-Packagesukbu : iuDismPackageu/Remove-Packageu/PackageName:{0}u/Quietu
/NoRestartuUninstall using DISM faileduCommand: %su u	Error: %su Uninstall using DISM failed: {0}uUninstall Completed using DISMuUninstalled using DISMuMessageuNeedsRebootuNeedsReboot: %suNever Rebootu
Always RebootuPoss RebootiuUninstallation SucceededuResultuUninstallation FaileduRebootBehavioruUninstall Failed: %suUninstallation Not StarteduUninstallation In Progressu$Uninstallation Succeeded With ErrorsiiuUninstallation AborteduUninstall CompleteuUninstall Failed(ii(3RR
R<RrRBRRRRRRRRRRRR"R$R4R5RRR?RRt	UninstallRERFRGRHRIRDR-t_runt
splitlinestlowertsplitRtjoinRTtneeds_rebootR>R=R)R,RJRgR'RRhRi(RRRjRttuninstall_listR1RmRnRJRMRNRORPRQR2tkbtcmdtpkg_listtpkgRvRoRp((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyt	uninstalls�$




	





	 








	'








"&cC@s�t|tj�r*tjjj|�}nyBtj|�t	j
|dtdt	jdt	j�}|j
�SWnNttfk
r�}tjddj|��tjd|�t|��nXdS(u�
        Internal function for running commands. Used by the uninstall function.

        Args:
            cmd (str, list): The command to run

        Returns:
            str: The stdout of the command
        tshelltstdouttstderruCommand Failed: %su u	Error: %sN(R_RR`RRRGtshlex_splitRRt
subprocesstPopenRTtPIPEtcommunicatetOSErrortIOErrorR}R(RR�tpRO((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyRy�s
	N(R8R9R:RHRRR>RTR
RSR^RcRqRwR�Ry(((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyR;�sT

			*n	B	p	o	�cC@sAtjjj��tjjd�}WdQXtjjj|j	�S(u

    Determines if the system needs to be rebooted.

    Returns:

        bool: True if the system requires a reboot, False if not

    CLI Examples:

    .. code-block:: bash

        import salt.utils.win_update

        salt.utils.win_update.needs_reboot()

    uMicrosoft.Update.SystemInfoN(
RRRRRRRR4R5R'(tobj_sys((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyR~�s(!R:t
__future__RRRtloggingR�tsalt.utils.argsRtsalt.utils.datatsalt.utils.winapitsalt.extRtsalt.ext.six.movesRtsalt.exceptionsRtwin32com.clientRRERTRtImportErrorR
t	getLoggerR8RRR
tobjectRR;R~(((s9/usr/lib/python2.7/site-packages/salt/utils/win_update.pyt<module>s.


	����

Zerion Mini Shell 1.0