3 gt`l@s^ddlmZddlmZddlmZddlmZddlZddlZ ddl Z Gdddej Z dS))absolute_import)unicode_literals)ucd)loggerNcs<eZdZdZfddZeddZddZdd ZZ S) BashCompletionCacheZgenerate_completion_cachecs"tt|j||||_d|_dS)Nz/var/cache/dnf/packages.db)superr__init__base cache_file)selfr Zcli) __class__//usr/lib/python3.6/generate_completion_cache.pyrszBashCompletionCache.__init__cCstjd|dS)NzCompletion plugin: %s)rdebug)msgr r r_out$szBashCompletionCache._outcCsd}x,|jjjD]}|jdk r|jjrd}PqWtjj|j sF|ry~t j |jh}|j d|j }|j d|j d|j d|jjjj}dd |D}|jd ||jWdQRXWn6t jk r}z|j d t|WYdd}~XnXdS) z& Generate cache of available packages FNTzGenerating completion cache...z/create table if not exists available (pkg TEXT)zAcreate unique index if not exists pkg_available ON available(pkg)zdelete from availablecSs g|]}|jdkrt|gqS)src)archstr).0xr r r @sz,BashCompletionCache.sack..z*insert or ignore into available values (?)z Can't write completion cache: %s)r ZreposZ iter_enabledZmetadatafreshospathexistsr sqlite3connectrcursorexecutesackqueryZ available executemanycommitOperationalErrorr)r rZrepoconncurZ avail_pkgsZavail_pkgs_inserter r rr (s,  zBashCompletionCache.sackcCs|js dSytj|jn}|jd|j}|jd|jd|jdtjj |j j j }dd|D}|j d||jWdQRXWn6tjk r}z|jd t|WYdd}~XnXdS) z& Generate cache of installed packages NzGenerating completion cache...z/create table if not exists installed (pkg TEXT)zAcreate unique index if not exists pkg_installed ON installed(pkg)zdelete from installedcSs g|]}|jdkrt|gqS)r)rr)rrr r rrVsz3BashCompletionCache.transaction..z*insert or ignore into installed values (?)z Can't write completion cache: %s) transactionrrr rrrdnfr Z _rpmdb_sackr r!Z installedr"r#r$r)r r%r&Z inst_pkgsZinst_pkgs_insertr'r r rr(Gs"   zBashCompletionCache.transaction) __name__ __module__ __qualname__namer staticmethodrr r( __classcell__r r )r rrs   r) Z __future__rrZdnf.i18nrZdnfpluginscorerr)Zos.pathrrZPluginrr r r rs