3 šgt`lã@s^ddlmZddlmZddlmZddlmZddlZddlZ ddl Z Gdd„dej ƒZ dS)é)Úabsolute_import)Úunicode_literals)Úucd)ÚloggerNcs<eZdZdZ‡fdd„Zedd„ƒZdd„Zdd „Z‡Z 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)rÚdebug)Úmsgr r rÚ_out$szBashCompletionCache._outcCsd}x,|jjjƒD]}|jdk r|jjrd}PqWtjj|jƒ sF|rüy~t j |jƒ�h}|j dƒ|j ƒ}|j dƒ|j dƒ|j dƒ|jjjƒjƒ}dd „|Dƒ}|jd |ƒ|jƒWdQRXWn6t 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|ƒg‘qS)Úsrc)ÚarchÚstr)Ú.0Úxr r rú @sz,BashCompletionCache.sack..z*insert or ignore into available values (?)z Can't write completion cache: %s)r ZreposZ iter_enabledZmetadataÚfreshÚosÚpathÚexistsr Úsqlite3ÚconnectrÚcursorÚexecuteÚsackÚqueryZ availableÚ executemanyÚcommitÚOperationalErrorr)r rZrepoÚconnÚcurZ avail_pkgsZavail_pkgs_insertÚer r rr (s,  zBashCompletionCache.sackcCsÊ|js dSy„tj|jƒ�n}|jdƒ|jƒ}|jdƒ|jdƒ|jdƒtjj |j ƒj ƒj ƒ}dd„|Dƒ}|j d|ƒ|jƒWdQRXWn6tjk 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|ƒg‘qS)r)rr)rrr r rrVsz3BashCompletionCache.transaction..z*insert or ignore into installed values (?)z Can't write completion cache: %s)Ú transactionrrr rrrÚdnfr 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 rÚs