AlkantarClanX12

Your IP : 3.12.36.45


Current Path : /lib/python3.6/site-packages/dnf/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/dnf/__pycache__/util.cpython-36.pyc

3

�ft`�O�@svddlmZddlmZddlmZddlmZmZddlmZm	Z	ddl
Z
ddlZddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZejd�Ze
j �j!d	kr�e
j �j!ndZ"e"j#�Z$d
d�Z%d^dd
�Z&d_dd�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-dd�Z.dd �Z/d!d"�Z0d#d$�Z1d%d&�Z2d'd(�Z3d)d*�Z4d+d,�Z5d-d.�Z6d/d0�Z7d1d2�Z8d3d4�Z9d5d6�Z:d7d8�Z;d9d:�Z<d;d<�Z=d=d>�Z>d?d@�Z?dAdB�Z@dCdD�ZAd`dFdG�ZBdHdIejCfdJdK�ZDdLdM�ZEdNdO�ZFdPdQ�ZGdRdS�ZHGdTdU�dUeI�ZJGdVdW�dWeK�ZLGdXdY�dYeM�ZNdZd[�ZOd\d]�ZPdS)a�)�print_function)�absolute_import)�unicode_literals�)�PY3�
basestring)�_�ucdN�dnfZyumcCs�t|dg�t|dg�t|dg�t�}x�|D]�}||kr>q0|j|�tjjj|�d}|jd�rr|jj|�q0|r�|d
kr�|jj|�q0|j	d
�r�|j
j|dd��q0|jj|�q0WdS)a�
    Categorize :param values list into packages, groups and filenames

    :param namespace: argparse.Namespace, where specs will be stored
    :param values: list of specs, whether packages ('foo') or groups/modules ('@bar')
                   or filenames ('*.rmp', 'http://*', ...)

    To access packages use: specs.pkg_specs,
    to access groups use: specs.grp_specs,
    to access filenames use: specs.filenames
    �	filenames�	grp_specs�	pkg_specsrz.rpm�http�ftp�file�https�@rN)rrrr)�setattr�set�addr
�pycompZurlparse�endswithr�append�
startswithrr
)�	namespace�valuesZtmp_set�valueZschemes�r�/usr/lib/python3.6/util.py�_parse_specs7s 




rcCs�|dkrtjj�}tjj|||�}tjj|j�r6|jSt	|j
g�}|jd|�|j�g}yt
jjjt
jj|�d�WnBtk
r�}z&|jr�tt|���tjt|��WYdd}~XnX|jS)NrT)r
�callbackZNullDownloadProgress�repoZRemoteRPMPayload�os�path�existsZ
local_path�sumZ
download_size�startZ_librepo_target�libdnfZ
PackageTargetZdownloadPackagesZVectorPPackageTarget�RuntimeError�strict�IOError�str�logger�error)�url�confZprogressZploadZest_remote_sizeZtargets�errr�_urlopen_progressWs

 r1�w+bcKs�trd|kr|jdd�tj|f|�}y<|r@|jj||j��n tjj	j
|rR|jnd||j��Wn.tk
r�}zt
t|���WYdd}~XnX|jd�|S)z|
    Open the specified absolute url, return a file object
    which respects proxy setting even for non-repo downloads
    �b�encodingzutf-8Nr)r�
setdefault�tempfileZNamedTemporaryFileZ_repoZdownloadUrl�filenor'r!Z
DownloaderZdownloadURLZ_configr(r*r+�seek)r.r/r!�mode�kwargsZfor0rrr�_urlopenhs$
r;cCs |j|�r|dt|��}|S)N)r�len)�s�rrrr�rtrim|s
r?cCstj�dkS)Nr)r"�geteuidrrrr�	am_i_root�srAcCs.x(tj|�D]}tjj||�}t|�qWdS)zBRemove all files and dirs under `path`

    Also see rm_rf()

    N)r"�listdirr#�join�rm_rf)r#�entryZcontained_pathrrr�	clear_dir�srFcCsXytj|dd�Wn@tk
rR}z$|jtjks>tjj|�rB|�WYdd}~XnXdS)Ni�)r9)r"�makedirs�OSError�errnoZEEXISTr#�isdir)Zdnamer0rrr�
ensure_dir�s
rKcCsJg}|}x<tjj|�\}}|s6|s(|r4|jd|�P|jd|�q
W|S)z`
    Split path by path separators.
    Use os.path.join() to join the path back to string.
    r)r"r#�split�insert)r#�result�head�tailrrr�
split_path�s
rQcCs6yt|�}Wn tk
r,tt|��}YnX|dkS)Nr)r<�	TypeError�list)�iterable�lrrr�empty�s
rVcCs*t|�}yt|�Stk
r$dSXdS)zFReturns the first item from an iterable or None if it has no elements.N)�iter�next�
StopIteration)rT�itrrr�first�s
r[cCs4t|�}ytdd�|D��Stk
r.dSXdS)Ncss|]}|dk	r|VqdS)Nr)�.0�itemrrr�	<genexpr>�sz!first_not_none.<locals>.<genexpr>)rWrXrY)rTrZrrr�first_not_none�s
r_cCstj�t|�S)N)�time�file_timestamp)�fnrrr�file_age�srccCstj|�jS)N)r"�stat�st_mtime)rbrrrra�sracCs4ytjtj��dStk
r.dtj�SXdS)NrzUID: %s)�pwd�getpwuidr"r@�KeyErrorrrrr�get_effective_login�sricCs(x"|D]}|j|�}|dkr|SqW|S)z!Like dict.get() for nested dicts.N)�get)Zdct�keysZ	not_found�krrr�get_in�s


rmcs�fdd�}tj||ggf�S)Ncs|t�|��j|�|S)N)�boolr)Zaccr])rbrr�splitter�sz!group_by_filter.<locals>.splitter)�	functools�reduce)rbrTror)rbr�group_by_filter�srrccs&x |D]}||�r|V|VqWdS)z/Insert an item into an iterable by a condition.Nr)r]rT�	conditionZ
original_itemrrr�	insert_if�s
rtcCs*yt|�Wntk
r dSXdSdS)z&Test whether an iterator is exhausted.TFN)rXrY)�iteratorrrr�is_exhausted�s
rvcCs*t|�r|g}t|t�o(tdd�|D��S)Ncss|]}t|�td�@VqdS)z*[?N)r)r\�prrrr^�sz"is_glob_pattern.<locals>.<genexpr>)�is_string_type�
isinstancerS�any)�patternrrr�is_glob_pattern�sr|cCstrt|t�St|t�SdS)N)rryr+r)�objrrrrx�s
rxcs�fdd�}|S)z�Decorator to get lazy attribute initialization.

    Composes with @property. Force reinitialization by deleting the <attrname>.
    cs��fdd�}|S)Ncs8y
t|��Stk
r2�|�}t|�|�|SXdS)N)�getattr�AttributeErrorr)r}�val)�attrnamerbrr�
cached_getters
z6lazyattr.<locals>.get_decorated.<locals>.cached_getterr)rbr�)r�)rbr�
get_decorated�szlazyattr.<locals>.get_decoratedr)r�r�r)r�r�lazyattr�s	r�cGstt|f|���S)z�Like functools.map(), but return a list instead of an iterator.

    This means all side effects of fn take place even without iterating the
    result.

    )rS�map)rb�seqrrr�mapallsr�cCs8tjdtj|��}tjjs4tj�d}|r4|j|�}|S)z6Convert time into locale aware datetime string object.z%cr)	r`ZstrftimeZ	localtimer
rr�localeZ	getlocale�decode)Z	timestamp�tZcurrent_locale_settingrrr�normalize_times
r�cCszy\d}dd�tj|�D�}t|�dkrZ|d}tdj||���}|j�}t|�dkSQRXdSttfk
rtdSXdS)z�Decide whether we are on line power.

    Returns True if we are on line power, False if not, None if it can not be
    decided.

    z/sys/class/power_supplycSsg|]}|jd�r|�qS)ZAC)r)r\Znoderrr�
<listcomp>&szon_ac_power.<locals>.<listcomp>rz{}/{}/onlinerN)	r"rBr<�open�format�read�intr*�
ValueError)Z	ps_folderZac_nodesZac_nodeZ	ac_status�datarrr�on_ac_powersr�cCs�yddl}Wntk
r dSXy0|j�}|jdd�}|j|d�}|jdd�}Wn|jk
rhdSX|dkrvdS|dkr�d	S|dkr�dStd
|��dS)z�Decide whether we are on metered connection.

    Returns:
      True: if on metered connection
      False: if not
      None: if it can not be decided
    rNzorg.freedesktop.NetworkManagerz/org/freedesktop/NetworkManagerzorg.freedesktop.DBus.PropertiesZMeteredr�T��Fz&Unknown value for metered property: %r)rr�)r�r�)�dbus�ImportErrorZ	SystemBusZ
get_objectZ	InterfaceZGetZ
DBusExceptionr�)r�Zbus�proxyZifaceZmeteredrrr�on_metered_connection1s&r�cCs&tj|�\}}tjj||�t||�fS)z�Use a predicate to partition entries into false entries and true entries.

    Credit: Python library itertools' documentation.

    )�	itertools�teer
r�filterfalse�filter)ZpredrTZt1Zt2rrr�	partitionNsr�cCs(ytj|�Wntk
r"YnXdS)N)�shutilZrmtreerH)r#rrrrDWsrDc#sFt���fdd�}t�||�}||�Vx||�}|s8P|Vq*WdS)z�Split an iterable into tuples by a condition.

    Inserts a separator before each item which meets the condition and then
    cuts the iterable by these separators.

    csttj�fdd�|��S)Ncs|�kS)Nr)r0)�	separatorrr�<lambda>gsz4split_by.<locals>.next_subsequence.<locals>.<lambda>)�tupler��	takewhile)rZ)r�rr�next_subsequencefsz"split_by.<locals>.next_subsequenceN)�objectrt)rTrsr�ZmarkedZsubsequencer)r�r�split_by]s
r�cCs|j|�r|t|�d�SdS)N)rr<)r=�prefixrrr�strip_prefixus
r�Fc	Cs8|stj|tj�rtj|d�St|d��WdQRXdS)z{Create an empty file if it doesn't exist or bump it's timestamps.

    If no_create is True only bumps the timestamps.
    N�a)r"�access�F_OK�utimer�)r#Z	no_createrrr�touch{sr��write�cCs�yh|dkr|j|�nP|dkr(|j�n>|dkrD|j|�|j�n"|dkrZt||d�ntd|��Wn>tk
r�}z"tjdjt|�j	t
|���WYdd}~XnXdS)Nr��flushZwrite_flush�print)rzUnsupported type: z{}: {})r�r�r�r�r*r,�criticalr��type�__name__r	)�tp�msg�outr0rrr�_terminal_messenger�s


r�cCsnd}t|�dk}xXt|dd�D]H\}}|rD|dtd�d|7}n|dtd�d7}|dj|�7}qW|S)	z�
    Format string about problems in resolve

    :param resolve_problems: list with list of strings (output of goal.problem_rules())
    :return: string
    r�r)r&z
 ZProblemz %d: z: z
  - )r<�	enumeraterrC)Zresolve_problemsr�Zcount_problems�iZrsrrr�_format_resolve_problems�sr�cCsX|j�d}|j�dk	r4|j�dkr4||j�d7}||j�d|j�d|j�S)N�-�0�:�.)�N�E�V�R�A)ZteZnevrarrr�	_te_nevra�sr�cCs�tjd�xH|D]@}|j�}d}|dk	r.|j}djt|�|||j��}tj|�qWx:|D]2}djt|�|j|j|j	|j
|j��}tj|�qZWdS)NzLogging transaction elementsz@RPM element: '{}', Key(): '{}', Key state: '{}', Failed() '{}': z^SWDB element: '{}', State: '{}', Action: '{}', From repo: '{}', Reason: '{}', Get reason: '{}')r,�debug�Key�stater�r��Failedr+�actionZ	from_repo�reasonZ
get_reason)�rpm_transaction�swdb_transaction�rpm_el�tsiZ	tsi_stater�rrr�_log_rpm_trans_with_swdb�s



r�c
CsVtjjtjjtjjtjjtjjh}dd�|D�}d}d}x�|D]�}t|�}|j�}|dksft	|d�r�x:|D]2}	|	j
tjjkr�ql|	j|kr�qlt
|	�|krl|	}PqlW|dks�t	|d�r�tjtd�j|��d}q>|j�r�tjj|_
d}q>tjj|_
q>Wx6|D].}|j
tjjkr�tjtd�jt
|���d}q�W|�rBtjtd��|�rRt||�dS)	NcSsg|]}|�qSrr)r\r�rrrr��sz-_sync_rpm_trans_with_swdb.<locals>.<listcomp>FZpkgz%TransactionItem not found for key: {}Tz)TransactionSWDBItem not found for key: {}z#Errors occurred during transaction.)r'�transactionZ TransactionItemAction_DOWNGRADEDZTransactionItemAction_OBSOLETED�TransactionItemAction_REMOVEZTransactionItemAction_UPGRADEDZ!TransactionItemAction_REINSTALLEDr�r��hasattrr�ZTransactionItemState_UNKNOWNr�r+r,r�rr�r��TransactionItemState_ERRORZTransactionItemState_DONEr�r�)
r�r�Zrevert_actionsZ
cached_tsiZel_not_foundr-r�Zte_nevrar�Z
tsi_candidaterrr�_sync_rpm_trans_with_swdb�sH





r�c@s$eZdZdd�Zdd�Zdd�ZdS)�tmpdircCsdtjj}tj|d�|_dS)Nz%s-)r�)r
�constZPREFIXr6Zmkdtempr#)�selfr�rrr�__init__�sztmpdir.__init__cCs|jS)N)r#)r�rrr�	__enter__�sztmpdir.__enter__cCst|j�dS)N)rDr#)r��exc_type�	exc_value�	tracebackrrr�__exit__�sztmpdir.__exit__N)r��
__module__�__qualname__r�r�r�rrrrr��sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�Bunchz�Dictionary with attribute accessing syntax.

    In DNF, prefer using this over dnf.yum.misc.GenericHolder.

    Credit: Alex Martelli, Doug Hudgeon

    cstt|�j||�||_dS)N)�superr�r��__dict__)r��args�kwds)�	__class__rrr��szBunch.__init__cCst|�S)N)�id)r�rrr�__hash__szBunch.__hash__)r�r�r��__doc__r�r��
__classcell__rr)r�rr��sr�cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�
MultiCallListcstt|�j�|j|�dS)N)r�r�r��extend)r�rT)r�rrr�szMultiCallList.__init__cs��fdd�}|S)Ncs���fdd�}tt|���S)Ncst|��}|���S)N)r~)�v�method)r�r:�whatrr�	call_what
s
z8MultiCallList.__getattr__.<locals>.fn.<locals>.call_what)rSr�)r�r:r�)r�r�)r�r:rrbsz%MultiCallList.__getattr__.<locals>.fnr)r�r�rbr)r�r�r�__getattr__szMultiCallList.__getattr__cs��fdd�}tt||��S)Ncst|���dS)N)r)r])r�r�rr�settersz)MultiCallList.__setattr__.<locals>.setter)rSr�)r�r�r�r�r)r�r�r�__setattr__szMultiCallList.__setattr__)r�r�r�r�r�r�r�rr)r�rr�sr�c
Csntgggggggggggd��}�xF|D�]<}|jtjjkrJ|jj|�q(|jtjjkrf|j	j|�q(|jtjj
kr�|jtjjkr�|j
j|�nD|jtjjkr�|jj|�n(|jtjjkr�|jj|�n|jj|�q(|jtjjkr�|jj|�q(|jtjjk�rL|jtjjk�r |jj|�n*|jtjjk�r>|jj|�n|jj|�q(|jtjjkr(|jj|�q(W|S)N)�
downgraded�erased�erased_clean�
erased_dep�	installed�installed_group�
installed_dep�installed_weak�reinstalled�upgraded�failed)r�r�r'r�r�r�rr�ZTransactionItemAction_DOWNGRADEr�ZTransactionItemAction_INSTALLr�ZTransactionItemReason_GROUPr�Z TransactionItemReason_DEPENDENCYr�Z%TransactionItemReason_WEAK_DEPENDENCYr�r�ZTransactionItemAction_REINSTALLr�r�ZTransactionItemReason_CLEANr�r�r�ZTransactionItemAction_UPGRADEr�)r�r3r�rrr�_make_listssH
rcs��fdd�}tjj|�}�jd|d�\}}|j|�}g}x�td�|jftd�|jftd�|j|j	|j
|jftd�|jftd	�|ftd
�|j
|j|jftd�|jfgD]&\}	}
|j||	t|
tj|�d���q�W|S)
alReturns a human-readable summary of the results of the
    transaction.

    :param action_callback: function generating output for specific action. It
       takes two parameters - action as a string and list of affected packages for
       this action
    :return: a list of lines containing a human-readable summary of the
       results of the transaction
    cs�|j|jk|j|jk}|dkr$|Stj|j|j|j|j|jd�}tj|j|j|j|j|jd�}|j|�j�}|dkrz|S|j|jk|j|jkS)z�Compares two transaction items or packages by nevra.
           Used as a fallback when tsi does not contain package object.
        r)�name�epoch�version�release�arch)	r�hawkeyZNEVRArrrrZevr_cmpZsack)Zitem1Zitem2�retZnevra1Znevra2)�baserr�_tsi_or_pkg_nevra_cmpPsz7_post_transaction_output.<locals>._tsi_or_pkg_nevra_cmpF)Zreport_problemsr�ZUpgradedZ
DowngradedZ	InstalledZReinstalledZSkippedZRemovedr�)�key)r
�utilrZ_skipped_packages�unionrr�r�r�r�r�r�r�r�r�r�r�r��sortedrp�
cmp_to_key)rr�Zaction_callbackr	Z
list_bunchZskipped_conflictsZskipped_brokenZskippedr�r�Ztsisr)rr�_post_transaction_outputFs(



r)N)NNr2)F)QZ
__future__rrrrrrZdnf.i18nrr	�argparser
Zdnf.callbackZ	dnf.constZ
dnf.pycomprIrprr�r�Zloggingr"rfr��sysr6r`Zlibdnf.repor'Zlibdnf.transactionZ	getLoggerr,�ArgumentParser�progZ	MAIN_PROG�upperZMAIN_PROG_UPPERrr1r;r?rArFrKrQrVr[r_rcrarirmrrrtrvr|rxr�r�r�r�r�r�rDr�r�r��stdoutr�r�r�r�r�r�r��dictr�rSr�rrrrrr�<module>s�
 


						
(-