[/\c@@sddlmZddlmZddlmZddlmZmZddlmZm Z ddl m Z ddl Z ddl Z ddlZ ddlZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZejd Zd Zdd Z!dd Z"ddd dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4d Z5d!Z6d"Z7d#Z8d$Z9d%Z:d&Z;d'Z<e=d(Z>d)d*ej?d+Z@d,ZAd-ZBd.eCfd/YZDd0eEfd1YZFd2eGfd3YZHdS(4i(tprint_function(tabsolute_import(tunicode_literalsi(tPY3t basestring(t_tucd(treduceNudnfcC@st|dgt|dgt|dgx|D]}tjjj|d}|jdrx|jj|q7|r|d kr|jj|q7|jd r|jj|d q7|j j|q7Wd S(u 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 u filenamesu grp_specsu pkg_specsiu.rpmuhttpuftpufileuhttpsu@iN(uhttpuftpufileuhttps( tsetattrtdnftpycompturlparsetendswitht filenamestappendt startswitht grp_specst pkg_specs(t namespacetvaluestvaluetschemes((s,/usr/lib/python2.7/site-packages/dnf/util.pyt _parse_specs2s  cC@stj}tjj|_|rt|jtkr?|jnt|j |j|_ |j |_ tj j |j|jt|_|j|_|_n|S(N(tlibrepotHandleR tconstt USER_AGENTt useragentttypetthrottletintt bandwidthtmaxspeedtproxytrepot_user_pass_strtproxy_usernametproxy_passwordtTruet proxyuserpwdt sslverifyt sslverifypeert sslverifyhost(tconfthandle((s,/usr/lib/python2.7/site-packages/dnf/util.pyt_non_repo_handleNs  cC@s|dkrtjj}ntjj|||}tjj|j rR|j St |j g}|j d||j g}y&tjjjtjj|tWnDtk r}|jrtt|ntjt|nX|j S(Ni(tNoneR tcallbacktNullDownloadProgressR"tRemoteRPMPayloadtostpathtexistst local_pathtsumt download_sizetstartt_librepo_targettlibdnft PackageTargettdownloadPackagestVectorPPackageTargetR&t RuntimeErrortstricttIOErrortstrtloggerterror(turlR+tprogresstploadtest_remote_sizettargetste((s,/usr/lib/python2.7/site-packages/dnf/util.pyt_urlopen_progress\s & uw+bcK@str%d|kr%|jddntj||}yT|r\|jj||jn.tjj j |rw|j nd||jWn%t k r}tt|nX|jd|S(u| Open the specified absolute url, return a file object which respects proxy setting even for non-repo downloads ubuencodinguutf-8iN(Rt setdefaultttempfiletNamedTemporaryFilet_repot downloadUrltfilenoR:R"t Downloadert downloadURLt_configR.R>R@RAtseek(RDR+R"tmodetkwargstfoRI((s,/usr/lib/python2.7/site-packages/dnf/util.pyt_urlopenss2 cC@s'|j|r#|t| }n|S(N(R tlen(tstr((s,/usr/lib/python2.7/site-packages/dnf/util.pytrtrimscC@stjdkS(Ni(R2tgeteuid(((s,/usr/lib/python2.7/site-packages/dnf/util.pyt am_i_rootscC@s=x6tj|D]%}tjj||}t|qWdS(uBRemove all files and dirs under `path` Also see rm_rf() N(R2tlistdirR3tjointrm_rf(R3tentrytcontained_path((s,/usr/lib/python2.7/site-packages/dnf/util.pyt clear_dirscC@s_ytj|ddWnAtk rZ}|jtjksNtjj| r[|q[nXdS(NRUi(R2tmakedirstOSErrorterrnotEEXISTR3tisdir(tdnameRI((s,/usr/lib/python2.7/site-packages/dnf/util.pyt ensure_dirs %cC@s@yt|}Wn#tk r5tt|}nX|dkS(Ni(RYt TypeErrortlist(titerabletl((s,/usr/lib/python2.7/site-packages/dnf/util.pytemptys  cC@s3t|}yt|SWntk r.dSXdS(uFReturns the first item from an iterable or None if it has no elements.N(titertnextt StopIterationR.(Rntit((s,/usr/lib/python2.7/site-packages/dnf/util.pytfirsts   cC@s=t|}ytd|DSWntk r8dSXdS(Ncs@s!|]}|dk r|VqdS(N(R.(t.0titem((s,/usr/lib/python2.7/site-packages/dnf/util.pys s(RqRrRsR.(RnRt((s,/usr/lib/python2.7/site-packages/dnf/util.pytfirst_not_nones   cC@stjt|S(N(ttimetfile_timestamp(tfn((s,/usr/lib/python2.7/site-packages/dnf/util.pytfile_agescC@stj|jS(N(R2tstattst_mtime(R{((s,/usr/lib/python2.7/site-packages/dnf/util.pyRzscC@s>ytjtjdSWntk r9dtjSXdS(NiuUID: %s(tpwdtgetpwuidR2R]tKeyError(((s,/usr/lib/python2.7/site-packages/dnf/util.pytget_effective_logins cC@s4x-|D]%}|j|}|dkr|SqW|S(u!Like dict.get() for nested dicts.N(tgetR.(tdcttkeyst not_foundtk((s,/usr/lib/python2.7/site-packages/dnf/util.pytget_ins   c@s%fd}t||ggfS(Nc@s"|t| j||S(N(tboolR(taccRw(R{(s,/usr/lib/python2.7/site-packages/dnf/util.pytsplitters(R(R{RnR((R{s,/usr/lib/python2.7/site-packages/dnf/util.pytgroup_by_filterscc@s.x'|D]}||r!|Vn|VqWdS(u/Insert an item into an iterable by a condition.N((RwRnt conditiont original_item((s,/usr/lib/python2.7/site-packages/dnf/util.pyt insert_ifs  cC@s+yt|Wntk r"tSXtSdS(u&Test whether an iterator is exhausted.N(RrRsR&tFalse(titerator((s,/usr/lib/python2.7/site-packages/dnf/util.pyt is_exhausteds  cC@s;t|r|g}nt|to:td|DS(Ncs@s%|]}t|td@VqdS(u*[?N(tset(Rvtp((s,/usr/lib/python2.7/site-packages/dnf/util.pys s(tis_string_typet isinstanceRmtany(tpattern((s,/usr/lib/python2.7/site-packages/dnf/util.pytis_glob_patterns  cC@s$trt|tSt|tSdS(N(RRRAR(tobj((s,/usr/lib/python2.7/site-packages/dnf/util.pyRs c@sfd}|S(uDecorator to get lazy attribute initialization. Composes with @property. Force reinitialization by deleting the . c@sfd}|S(Nc@sFyt|SWn.tk rA|}t|||SXdS(N(tgetattrtAttributeErrorR(Rtval(tattrnameR{(s,/usr/lib/python2.7/site-packages/dnf/util.pyt cached_getters   ((R{R(R(R{s,/usr/lib/python2.7/site-packages/dnf/util.pyt get_decorateds((RR((Rs,/usr/lib/python2.7/site-packages/dnf/util.pytlazyattrs cG@stt||S(uLike functools.map(), but return a list instead of an iterator. This means all side effects of fn take place even without iterating the result. (Rmtmap(R{tseq((s,/usr/lib/python2.7/site-packages/dnf/util.pytmapallscC@sVtjdtj|}tjjsRtjd}|rR|j|}qRn|S(u6Convert time into locale aware datetime string object.u%ci( Rytstrftimet localtimeR R Rtlocalet getlocaletdecode(t timestamptttcurrent_locale_setting((s,/usr/lib/python2.7/site-packages/dnf/util.pytnormalize_time s  cC@s1ytjd}| SWntk r,dSXdS(uDecide whether we are on line power. Returns True if we are on line power, False if not, None if it can not be decided. u/usr/bin/on_ac_powerN(t subprocesstcallRfR.(tret((s,/usr/lib/python2.7/site-packages/dnf/util.pyt on_ac_powers   cC@syddl}Wntk r$dSXyF|j}|jdd}|j|d}|jdd}Wn|jk rdSX|dkrdS|d krtS|d krt St d |dS(uDecide whether we are on metered connection. Returns: True: if on metered connection False: if not None: if it can not be decided iNuorg.freedesktop.NetworkManageru/org/freedesktop/NetworkManageruorg.freedesktop.DBus.PropertiesuMeterediiiiu&Unknown value for metered property: %r(ii(ii( tdbust ImportErrorR.t SystemBust get_objectt InterfacetGett DBusExceptionR&Rt ValueError(RtbusR!tifacetmetered((s,/usr/lib/python2.7/site-packages/dnf/util.pyton_metered_connection!s&       cC@s7tj|\}}tjj||t||fS(uUse a predicate to partition entries into false entries and true entries. Credit: Python library itertools' documentation. (t itertoolstteeR R t filterfalsetfilter(tpredRntt1tt2((s,/usr/lib/python2.7/site-packages/dnf/util.pyt partition>scC@s)ytj|Wntk r$nXdS(N(tshutiltrmtreeRf(R3((s,/usr/lib/python2.7/site-packages/dnf/util.pyRaGs c#@satfd}t||}||Vx%tr\||}|sTPn|Vq8WdS(uSplit 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. c@sttjfd|S(Nc@s |kS(N((RI(t separator(s,/usr/lib/python2.7/site-packages/dnf/util.pytWs(ttupleRt takewhile(Rt(R(s,/usr/lib/python2.7/site-packages/dnf/util.pytnext_subsequenceVsN(tobjectRR&(RnRRtmarkedt subsequence((Rs,/usr/lib/python2.7/site-packages/dnf/util.pytsplit_byMs    cC@s!|j|r|t|SdS(N(RRYR.(RZtprefix((s,/usr/lib/python2.7/site-packages/dnf/util.pyt strip_prefixescC@sE|stj|tjr+tj|dSt|dWdQXdS(u{Create an empty file if it doesn't exist or bump it's timestamps. If no_create is True only bumps the timestamps. uaN(R2taccesstF_OKtutimeR.topen(R3t no_create((s,/usr/lib/python2.7/site-packages/dnf/util.pyttouchksuwriteucC@sy|dkr|j|nn|dkr8|jnU|dkr^|j||jn/|dkr}t|d|ntd|Wn;tk r}tjdjt|j t |nXdS(Nuwriteuflushu write_flushuprinttfileuUnsupported type: u{}: {}( twritetflushtprintRR@RBtcriticaltformatRt__name__R(ttptmsgtoutRI((s,/usr/lib/python2.7/site-packages/dnf/util.pyt_terminal_messengervs       (cC@sd}t|dk}xpt|ddD]\\}}|r\|dtdd|7}n|dtdd7}|dj|7}q+W|S( u Format string about problems in resolve :param resolve_problems: list with list of strings (output of goal.problem_rules()) :return: string uiR8u uProblemu %d: u: u - (RYt enumerateRR`(tresolve_problemsRtcount_problemstitrs((s,/usr/lib/python2.7/site-packages/dnf/util.pyt_format_resolve_problemsscC@su|jd}|jdk rK|jdkrK||jd7}n||jd|jd|jS(Nu-u0u:u.(tNtER.tVtRtA(ttetnevra((s,/usr/lib/python2.7/site-packages/dnf/util.pyt _te_nevras$ttmpdircB@s#eZdZdZdZRS(cC@s)dtjj}tjd||_dS(Nu%s-R(R RtPREFIXRLtmkdtempR3(tselfR((s,/usr/lib/python2.7/site-packages/dnf/util.pyt__init__scC@s|jS(N(R3(R((s,/usr/lib/python2.7/site-packages/dnf/util.pyt __enter__scC@st|jdS(N(RaR3(Rtexc_typet exc_valuet traceback((s,/usr/lib/python2.7/site-packages/dnf/util.pyt__exit__s(Rt __module__RRR(((s,/usr/lib/python2.7/site-packages/dnf/util.pyRs  tBunchcB@s eZdZdZdZRS(uDictionary with attribute accessing syntax. In DNF, prefer using this over dnf.yum.misc.GenericHolder. Credit: Alex Martelli, Doug Hudgeon cO@s&tt|j||||_dS(N(tsuperRRt__dict__(Rtargstkwds((s,/usr/lib/python2.7/site-packages/dnf/util.pyRscC@s t|S(N(tid(R((s,/usr/lib/python2.7/site-packages/dnf/util.pyt__hash__s(RRt__doc__RR(((s,/usr/lib/python2.7/site-packages/dnf/util.pyRs t MultiCallListcB@s#eZdZdZdZRS(cC@s$tt|j|j|dS(N(RRRtextend(RRn((s,/usr/lib/python2.7/site-packages/dnf/util.pyRsc@sfd}|S(Nc@s(fd}tt|S(Nc@st|}|S(N(R(tvtmethod(RRVtwhat(s,/usr/lib/python2.7/site-packages/dnf/util.pyt call_whats(RmR(RRVR (RR (RRVs,/usr/lib/python2.7/site-packages/dnf/util.pyR{s((RR R{((RR s,/usr/lib/python2.7/site-packages/dnf/util.pyt __getattr__sc@s%fd}tt||S(Nc@st|dS(N(R(Rw(RR (s,/usr/lib/python2.7/site-packages/dnf/util.pytsetters(RmR(RR RR ((RR s,/usr/lib/python2.7/site-packages/dnf/util.pyt __setattr__s(RRRR R (((s,/usr/lib/python2.7/site-packages/dnf/util.pyRs  (It __future__RRRR RRtdnf.i18nRRt functoolsRR t dnf.callbackt dnf.constt dnf.pycompRgRRtloggingR2RRRtsysRLRyt libdnf.repoR:t getLoggerRBRR.R-RJRXR\R^RdRkRpRuRxR|RzRRRRRRRRRRRRRRaRRRRtstdoutRRRRRtdictRRmR(((s,/usr/lib/python2.7/site-packages/dnf/util.pytst