î N¬S½ã@sddlmZddlmZddlZejddeƒddlZddlZddlZddl Z ddl m Z ddl Z ddlTddl mZGd d „d eƒZed krÿed d ƒZejejjƒƒeejƒƒndS)é)Úprint_function)Úabsolute_importNÚignorezapt API not stable yet)Ú LocaleInfo)Ú*)Úmacrosc@syeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)ÚLanguageSelectorBasez' base class for language-selector code ÚcCs+||_td|jƒ|_d|_dS)NZ languagelist)Ú_datadirrÚ _localeinfoÚ_cache)ÚselfÚdatadir©rúC/usr/lib/python3/dist-packages/LanguageSelector/LanguageSelector.pyÚ__init__s zLanguageSelectorBase.__init__cCstjj|j|ƒ|_dS)N)ÚLanguageSelectorZ LangCacheZLanguageSelectorPkgCacher r )r ÚprogressrrrÚ openCache szLanguageSelectorBase.openCachecCsv|jr6tj|jtjj|jddƒƒ}ntj|jƒ}g}x!|jƒD]}|j|ƒq[W|S)zh return a list of language packs that are not installed but should be installed ÚdataZ pkg_depends) r Úlanguage_support_pkgsZLanguageSupportr ÚosÚpathÚjoinÚmissingÚappend)r ZlsrZpackrrrÚgetMissingLangPacks#s  !z(LanguageSelectorBase.getMissingLangPackscCsDtjƒ}|jddƒ}tj|ddƒ}|j|ƒdS)z1 write various LC_* variables (e.g. de_DE.UTF-8) zcom.ubuntu.LanguageSelectorú/Údbus_interfaceN)ÚdbusÚ SystemBusÚ get_objectÚ InterfaceZSetSystemDefaultFormatsEnv)r Z sysFormatsÚbusÚobjÚifacerrrÚwriteSysFormatsSetting2s z+LanguageSelectorBase.writeSysFormatsSettingcCsDtjƒ}|jddƒ}tj|ddƒ}|j|ƒdS)z2 write the system "LANGUAGE" and "LANG" variables zcom.ubuntu.LanguageSelectorrrN)rr r!r"ZSetSystemDefaultLanguageEnv)r Z sysLanguager#r$r%rrrÚwriteSysLanguageSetting9s z,LanguageSelectorBase.writeSysLanguageSettingcCs—tjƒ}|dkr6tjdtjdƒƒdStjƒ}|jdd|ƒ}tj|ddƒ}t j |j |ƒ}|j |d ƒdS) z1 write various LC_* variables (e.g. de_DE.UTF-8) rz&No formats locale saved for user '%s'.ÚUSERNzorg.freedesktop.Accountsz /org/freedesktop/Accounts/User%irzorg.freedesktop.Accounts.UserZ SYSLOCALE) rÚgetuidÚwarningsÚwarnÚgetenvrr r!r"rZLangpackMacrosr ZSetFormatsLocale)r Z userFormatsÚuidr#r$r%ZmacrrrrÚwriteUserFormatsSetting@s     z,LanguageSelectorBase.writeUserFormatsSettingcCs‡tjƒ}|dkr6tjdtjdƒƒdStjƒ}|jdd|ƒ}tj|ddƒ}|j |j |ƒƒdS) z0 write the user "LANGUAGE" and "LANG" variables rz No language saved for user '%s'.r(Nzorg.freedesktop.Accountsz /org/freedesktop/Accounts/User%irzorg.freedesktop.Accounts.User) rr)r*r+r,rr r!r"Z SetLanguageÚvalidateLangList)r Ú userLanguager-r#r$r%rrrÚwriteUserLanguageSettingMs     z-LanguageSelectorBase.writeUserLanguageSettingcCs g}d}x^|jdƒD]M}|jdƒs=|dkrS|j|ƒd}q|s|j|ƒqqWdj|ƒ}||krœtjddƒn|S)z^ remove possible non-English elements after the first English element Fú:Zen_ZenTz;The language list was modified by the program, since there z:should not be any non-English items after an English item.)ÚsplitÚ startswithrrr*r+)r r0ZtmpZis_engZlangZvalidatedLangListrrrr/Ys     z%LanguageSelectorBase.validateLangListN) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr&r'r.r1r/rrrrrs      rÚ__main__rz..)Z __future__rrr*ÚfilterwarningsÚ FutureWarningZaptrrrZLanguageSelector.LocaleInforZLanguageSelector.LangCacherZLanguageSelector.utilsrÚobjectrr5ZlsbrrZ OpProgressÚprintZverifyPackageListsrrrrÚs        V