NS;@s"ddlmZddlZejddeddlZddlZGdddeZGdddeZ Gd d d e Z Gd d d ej Z ed krddlmZdZedeZe eejjZededjddejDndS))print_functionNignorezapt API not stable yetc@s(eZdZddZddZdS)LanguagePackageStatuscCs1||_||_d|_d|_d|_dS)NF) languageCodepkgname_template available installeddoChange)selfrZ pkg_templater }|j|}||k|_|jrA||j|_qAqAWdS)Nzlanguage-pack-%sZ languagePack) rlanguagelanguagePkgListrvaluesrrZ is_installedr)r cacherrZlangpkg_statuspkgnamer r r r s     zLanguageInformation.__init__cCs|j r|j rdSdS)zK returns True if only parts of the language support packages are installed TF) notInstalled fullInstalled)r r r r inconsistent)sz LanguageInformation.inconsistentcCsWxP|jjD]?}|js%qn|jr8|j pH|j oH|jsdSqWdS)zM return True if all of the available language support packages are installed FT)rrrrr )r pkgr r r r.s  &z!LanguageInformation.fullInstalledcCsWxP|jjD]?}|js%qn|j r9|j pH|joH|jsdSqWdS)zN return True if none of the available language support packages are installed FT)rrrrr )r rr r r r5s  &z LanguageInformation.notInstalledcCs+x$|jjD]}|jrdSqWdS)zM returns true if anything in the state of the language packs/support changes TF)rrr )r rr r r changes<s zLanguageInformation.changescCsd|j|jfS)Nz%s (%s))rr)r r r r rBszLanguageInformation.__str__) rrrr propertyrrrrrr r r r rs rc@seZdZdS)ExceptionPkgCacheBrokenN)rrrr r r r rFs rc@s^eZdZddZeddZddZddZd d Zd d Z d S)LanguageSelectorPkgCachecCsPtjj|||jjdkr1tn||_tj||_ dS)Nr) aptCacher _depcacheZ broken_countr _localeinfolanguage_support_pkgsZLanguageSupport lang_support)r Z localeinfoprogressr r r r Ks   z!LanguageSelectorPkgCache.__init__cCsx|jjD]}xx|jD]m}|jdjdrAqn|jdjdr_qn|jdkrtqn|jr|jrdSqWq WdS)z, verify that a network package lists exists zcdrom:zhttp://security.ubuntu.comzDebian Package IndexTF)Z_listlistZ index_filesZ archive_uri startswithZlabelexistsZ has_packages)r Z metaindexZ indexfiler r r havePackageListsRs z)LanguageSelectorPkgCache.havePackageListscCs|jjdS)z clear the selections N)r#Zinit)r r r r clearaszLanguageSelectorPkgCache.clearcCsng}g}xU|jD]G}|js1|jrD|j|jn|jr|j|jqqW||fS)N)Z get_changesZmarked_installZmarked_upgradeappendnameZ marked_delete)r Zto_instZto_rmrr r r getChangesListes z'LanguageSelectorPkgCache.getChangesListc Csx|jjD]\}}|jr|jj|jd|j}yv|jrxf|D]<}|jds|jd|jrV||j qVqVWnx|D]}||j qWWqt k rt YqXqqWdS)z$ commit changed status of list itemsrzlanguage-pack--N) ritemsr r&Z by_localerrr*endswithZ mark_deleteZ mark_install SystemErrorr)r likeyitemZpkgsrr r r tryChangeDetailsos     z)LanguageSelectorPkgCache.tryChangeDetailscCs}g}xp|jjjD]\\}}|dkr7qnt|||}dd|jjDr|j|qqW|S)z5 returns a list with language packs/support packages ZzhcSsg|]}|jr|qSr )r).0sr r r s zCLanguageSelectorPkgCache.getLanguageInformation..)r$Z_langr2rrrr.)r rescodeZlangr5r r r getLanguageInformations z/LanguageSelectorPkgCache.getLanguageInformationN) rrrr rr,r-r0r8r>r r r r r Is    r __main__) LocaleInfoz/usr/share/language-selectorZ languagelistzavailable language informationz, cCsg|]}d|qS)z%sr )r9xr r r r;s r;)Z __future__rwarningsfilterwarnings FutureWarningr!r%objectrr Exceptionrr"r rr@Zdatadirr5r'Z OpProgressZlcprintjoinr>r r r r s   /H