3 ft`O@svddlmZddlmZddlmZddlmZmZddlmZm Z ddl Z ddl Z ddl Z ddl Z ddlZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZejdZe j j!d kre j j!ndZ"e"j#Z$d d Z%d^d d Z&d_ddZ'ddZ(ddZ)ddZ*ddZ+ddZ,ddZ-ddZ.dd Z/d!d"Z0d#d$Z1d%d&Z2d'd(Z3d)d*Z4d+d,Z5d-d.Z6d/d0Z7d1d2Z8d3d4Z9d5d6Z:d7d8Z;d9d:ZZ>d?d@Z?dAdBZ@dCdDZAd`dFdGZBdHdIejCfdJdKZDdLdMZEdNdOZFdPdQZGdRdSZHGdTdUdUeIZJGdVdWdWeKZLGdXdYdYeMZNdZd[ZOd\d]ZPdS)a)print_function)absolute_import)unicode_literals)PY3 basestring)_ucdNdnfZyumcCst|dgt|dgt|dgt}x|D]}||kr>q0|j|tjjj|d}|jdrr|jj|q0|r|d kr|jj|q0|j d r|j j|d d q0|j j|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.rpmhttpftpfilehttps@rN)rrrr) setattrsetaddr pycompZurlparseendswithr append startswithr r ) namespacevaluesZtmp_setvalueZschemesr/usr/lib/python3.6/util.py _parse_specs7s        rcCs|dkrtjj}tjj|||}tjj|jr6|jSt |j g}|j d||j g}yt jjjt jj|dWnBtk r}z&|jrtt|tjt|WYdd}~XnX|jS)NrT)r callbackZNullDownloadProgressrepoZRemoteRPMPayloadospathexistsZ local_pathsumZ download_sizestartZ_librepo_targetlibdnfZ PackageTargetZdownloadPackagesZVectorPPackageTarget RuntimeErrorstrictIOErrorstrloggererror)urlconfZprogressZploadZest_remote_sizeZtargetserrr_urlopen_progressWs      r1w+bcKstrd|kr|jddtj|f|}y<|r@|jj||jn tjj j |rR|j nd||jWn.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 bencodingzutf-8Nr)r setdefaulttempfileZNamedTemporaryFileZ_repoZ downloadUrlfilenor'r!Z DownloaderZ downloadURLZ_configr(r*r+seek)r.r/r!modekwargsZfor0rrr_urlopenhs  $ r;cCs |j|r|dt| }|S)N)rlen)srrrrrtrim|s r?cCs tjdkS)Nr)r"geteuidrrrr am_i_rootsrAcCs.x(tj|D]}tjj||}t|q WdS)zBRemove all files and dirs under `path` Also see rm_rf() N)r"listdirr#joinrm_rf)r#entryZcontained_pathrrr clear_dirsrFcCsXytj|ddWn@tk rR}z$|jtjks>tjj| rB|WYdd}~XnXdS)Ni)r9)r"makedirsOSErrorerrnoZEEXISTr#isdir)Zdnamer0rrr ensure_dirs rKcCsJg}|}xsz!first_not_none..)rWrXrY)rTrZrrrfirst_not_nones r_cCstjt|S)N)timefile_timestamp)fnrrrfile_agesrccCs tj|jS)N)r"statst_mtime)rbrrrrasrac Cs4ytjtjdStk r.dtjSXdS)NrzUID: %s)pwdgetpwuidr"r@KeyErrorrrrrget_effective_loginsricCs(x"|D]}|j|}|dkr|SqW|S)z!Like dict.get() for nested dicts.N)get)ZdctkeysZ not_foundkrrrget_ins   rmcsfdd}tj||ggfS)Ncs|t| j||S)N)boolr)Zaccr])rbrrsplittersz!group_by_filter..splitter) functoolsreduce)rbrTror)rbrgroup_by_filters rrccs&x |D]}||r|V|VqWdS)z/Insert an item into an iterable by a condition.Nr)r]rT conditionZ original_itemrrr insert_ifs rtc Cs*y t|Wntk r dSXdSdS)z&Test whether an iterator is exhausted.TFN)rXrY)iteratorrrr is_exhausteds  rvcCs*t|r|g}t|to(tdd|DS)Ncss|]}t|td@VqdS)z*[?N)r)r\prrrr^sz"is_glob_pattern..)is_string_type isinstancerSany)patternrrris_glob_patternsr|cCstrt|tSt|tSdS)N)rryr+r)objrrrrxs rxcsfdd}|S)zDecorator to get lazy attribute initialization. Composes with @property. Force reinitialization by deleting the . csfdd}|S)Nc s8y t|Stk r2|}t|||SXdS)N)getattrAttributeErrorr)r}val)attrnamerbrr cached_getters   z6lazyattr..get_decorated..cached_getterr)rbr)r)rbr get_decoratedszlazyattr..get_decoratedr)rrr)rrlazyattrs rcGstt|f|S)zLike functools.map(), but return a list instead of an iterator. This means all side effects of fn take place even without iterating the result. )rSmap)rbseqrrrmapall srcCs8tjdtj|}tjjs4tjd}|r4|j|}|S)z6Convert time into locale aware datetime string object.z%cr) r`ZstrftimeZ localtimer rrlocaleZ getlocaledecode)Z timestamptZcurrent_locale_settingrrrnormalize_times   rcCszy\d}ddtj|D}t|dkrZ|d}tdj||}|j}t|dkSQRXdSttfk rtdSXdS)zDecide 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|]}|jdr|qS)ZAC)r)r\Znoderrr &szon_ac_power..rz {}/{}/onlinerN) r"rBr<openformatreadintr* ValueError)Z ps_folderZac_nodesZac_nodeZ ac_statusdatarrr on_ac_powers rcCsy ddl}Wntk r dSXy0|j}|jdd}|j|d}|jdd}Wn|jk rhdSX|dkrvdS|dkrd S|dkrd Std |dS)zDecide 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.PropertiesZMeteredrTFz&Unknown value for metered property: %r)rr)rr)dbus ImportErrorZ SystemBusZ get_objectZ InterfaceZGetZ DBusExceptionr)rZbusproxyZifaceZmeteredrrron_metered_connection1s&  rcCs&tj|\}}tjj||t||fS)zUse a predicate to partition entries into false entries and true entries. Credit: Python library itertools' documentation. ) itertoolsteer r filterfalsefilter)ZpredrTZt1Zt2rrr partitionNsrc Cs(ytj|Wntk r"YnXdS)N)shutilZrmtreerH)r#rrrrDWsrDc#sFtfdd}t||}||Vx||}|s8P|Vq*WdS)zSplit 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. csttjfdd|S)Ncs|kS)Nr)r0) separatorrrgsz4split_by..next_subsequence..)tupler takewhile)rZ)rrrnext_subsequencefsz"split_by..next_subsequenceN)objectrt)rTrsrZmarkedZ subsequencer)rrsplit_by]s   rcCs|j|r|t|dSdS)N)rr<)r=prefixrrr strip_prefixus rFc Cs8|stj|tjrtj|dSt|dWdQRXdS)z{Create an empty file if it doesn't exist or bump it's timestamps. If no_create is True only bumps the timestamps. Na)r"accessF_OKutimer)r#Z no_createrrrtouch{s  rwritecCsyh|dkr|j|nP|dkr(|jn>|dkrD|j||jn"|dkrZt||dn td|Wn>tk r}z"tjdjt|j t |WYdd}~XnXdS)NrflushZ write_flushprint)rzUnsupported type: z{}: {}) rrrrr*r,criticalrtype__name__r )tpmsgoutr0rrr_terminal_messengers    rcCsnd}t|dk}xXt|ddD]H\}}|rD|dtdd|7}n|dtdd7}|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 rr)r&z ZProblemz %d: z: z - )r< enumeraterrC)Zresolve_problemsrZcount_problemsiZrsrrr_format_resolve_problemss rcCsX|jd}|jdk r4|jdkr4||jd7}||jd|jd|jS)N-0:.)NEVRA)ZteZnevrarrr _te_nevras rcCstjdxH|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,debugKeystaterrFailedr+actionZ from_reporeasonZ get_reason)rpm_transactionswdb_transactionrpm_eltsiZ tsi_staterrrr_log_rpm_trans_with_swdbs    rc CsVtjjtjjtjjtjjtjjh}dd|D}d}d}x|D]}t|}|j}|dksft |d rx:|D]2} | j tjj krql| j |krqlt | |krl| }PqlW|dkst |d rtjtdj|d}q>|jrtjj|_ d}q>tjj|_ q>Wx6|D].}|j tjj krtjtdjt |d}qW|rBtjtd|rRt||dS) NcSsg|]}|qSrr)r\rrrrrsz-_sync_rpm_trans_with_swdb..FZpkgz%TransactionItem not found for key: {}Tz)TransactionSWDBItem not found for key: {}z#Errors occurred during transaction.)r' transactionZ TransactionItemAction_DOWNGRADEDZTransactionItemAction_OBSOLETEDTransactionItemAction_REMOVEZTransactionItemAction_UPGRADEDZ!TransactionItemAction_REINSTALLEDrrhasattrrZTransactionItemState_UNKNOWNrr+r,rrrrTransactionItemState_ERRORZTransactionItemState_DONErr) rrZrevert_actionsZ cached_tsiZ el_not_foundr-rZte_nevrarZ tsi_candidaterrr_sync_rpm_trans_with_swdbsH       rc@s$eZdZddZddZddZdS)tmpdircCsdtjj}tj|d|_dS)Nz%s-)r)r constZPREFIXr6Zmkdtempr#)selfrrrr__init__s ztmpdir.__init__cCs|jS)N)r#)rrrr __enter__sztmpdir.__enter__cCst|jdS)N)rDr#)rexc_type exc_value tracebackrrr__exit__sztmpdir.__exit__N)r __module__ __qualname__rrrrrrrrsrcs(eZdZdZfddZddZZS)BunchzDictionary with attribute accessing syntax. In DNF, prefer using this over dnf.yum.misc.GenericHolder. Credit: Alex Martelli, Doug Hudgeon cstt|j||||_dS)N)superrr__dict__)rargskwds) __class__rrrszBunch.__init__cCst|S)N)id)rrrr__hash__szBunch.__hash__)rrr__doc__rr __classcell__rr)rrrs rcs,eZdZfddZddZddZZS) MultiCallListcstt|j|j|dS)N)rrrextend)rrT)rrrrszMultiCallList.__init__csfdd}|S)Ncsfdd}tt|S)Ncst|}|S)N)r~)vmethod)rr:whatrr call_what s z8MultiCallList.__getattr__..fn..call_what)rSr)rr:r)rr)rr:rrb sz%MultiCallList.__getattr__..fnr)rrrbr)rrr __getattr__ szMultiCallList.__getattr__csfdd}tt||S)Ncst|dS)N)r)r])rrrrsettersz)MultiCallList.__setattr__..setter)rSr)rrrrr)rrr __setattr__szMultiCallList.__setattr__)rrrrrrrrr)rrrs rc Csntgggggggggggd }xF|D]<}|jtjjkrJ|jj|q(|jtjjkrf|j j|q(|jtjj kr|j tjj kr|j j|nD|j tjjkr|jj|n(|j tjjkr|jj|n |jj|q(|jtjjkr|jj|q(|jtjjkrL|j tjjkr |jj|n*|j tjjkr>|jj|n |jj|q(|jtjjkr(|jj|q(W|S)N) downgradederased erased_clean erased_dep installedinstalled_group installed_depinstalled_weak reinstalledupgradedfailed)rrr'rrrrrZTransactionItemAction_DOWNGRADErZTransactionItemAction_INSTALLrZTransactionItemReason_GROUPrZ TransactionItemReason_DEPENDENCYrZ%TransactionItemReason_WEAK_DEPENDENCYrrZTransactionItemAction_REINSTALLrrZTransactionItemReason_CLEANrrrZTransactionItemAction_UPGRADEr)rr3rrrr _make_listssH rc sfdd}tjj|}jd|d\}}|j|}g}xtd|jftd|jftd|j|j |j |j ftd|j ftd |ftd |j |j|jftd |jfgD]&\} } |j|| t| tj|d qW|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)zCompares two transaction items or packages by nevra. Used as a fallback when tsi does not contain package object. r)nameepochversionreleasearch) rhawkeyZNEVRArrrrZevr_cmpZsack)Zitem1Zitem2retZnevra1Znevra2)baserr_tsi_or_pkg_nevra_cmpPsz7_post_transaction_output.._tsi_or_pkg_nevra_cmpF)Zreport_problemsrZUpgradedZ DowngradedZ InstalledZ ReinstalledZSkippedZRemovedr)key)r utilrZ_skipped_packagesunionrrrrrrrrrrrrrsortedrp cmp_to_key) rrZaction_callbackr Z list_bunchZskipped_conflictsZskipped_brokenZskippedrrZtsisr)rr_post_transaction_outputFs(       r)N)NNr2)F)QZ __future__rrrrrrZdnf.i18nrr argparser Z dnf.callbackZ dnf.constZ dnf.pycomprIrprrrZloggingr"rfrsysr6r`Z libdnf.repor'Zlibdnf.transactionZ getLoggerr,ArgumentParserprogZ MAIN_PROGupperZMAIN_PROG_UPPERrr1r;r?rArFrKrQrVr[r_rcrarirmrrrtrvr|rxrrrrrrrDrrrstdoutrrrrrrrdictrrSrrrrrrrs              ( -