[SCM] muon packaging branch, gsoc-floris-2014, updated. 961b945e81b41bc407847424bf310de1fe450f9c

Floris-Andrei Stoica-Marcu smfloris-guest at moszumanska.debian.org
Tue Jul 15 02:10:22 UTC 2014


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/muon.git;a=commitdiff;h=961b945

The following commit has been merged in the gsoc-floris-2014 branch:
commit 961b945e81b41bc407847424bf310de1fe450f9c
Author: Floris-Andrei Stoica-Marcu <floris.sm at gmail.com>
Date:   Tue Jul 15 05:09:45 2014 +0300

    Added check-language-support scripts
---
 debian/check-language-support.install        |   8 +
 debian/control                               |   9 +-
 debian/rules                                 |   2 +-
 debian/scripts/check-language-support        |  73 +++++++
 debian/scripts/data/check-language-support.1 |  26 +++
 debian/scripts/data/pkg_depends              | 201 +++++++++++++++++++
 debian/scripts/langtools/language-options    |  65 +++++++
 debian/scripts/langtools/main-countries      |  27 +++
 debian/scripts/language_support_pkgs.py      | 279 +++++++++++++++++++++++++++
 9 files changed, 688 insertions(+), 2 deletions(-)

diff --git a/debian/check-language-support.install b/debian/check-language-support.install
new file mode 100644
index 0000000..b6519d0
--- /dev/null
+++ b/debian/check-language-support.install
@@ -0,0 +1,8 @@
+#!/usr/bin/make -f
+
+debian/scripts/check-language-support /usr/share/kde4/apps/muon/scripts
+debian/scripts/language_support_pkgs.py /usr/share/kde4/apps/muon/scripts
+debian/scripts/data/check-language-support.1 /usr/share/kde4/apps/muon/scripts/data
+debian/scripts/data/pkg_depends /usr/sharekde4/apps/muon/scripts/data
+debian/scripts/langtools/language-options /usr/share/kde4/apps/muon/scripts/langtools
+debian/scripts/langtools/main-countries /usr/share/kde4/apps/muon/scripts/langtools
diff --git a/debian/control b/debian/control
index 4476b8d..dd20e9d 100644
--- a/debian/control
+++ b/debian/control
@@ -5,8 +5,9 @@ Maintainer: Debian KDE Extras Team <pkg-kde-extras at lists.alioth.debian.org>
 Uploaders: Sune Vuorela <sune at debian.org>, Floris-Andrei Stoica-Marcu <floris.sm at gmail.com>
 Build-Depends: debhelper (>= 9.0.0~), pkg-kde-tools (>= 0.5.0), cmake,
  pkg-config, kdelibs5-dev, libqapt-dev (>= 2.2.0), libdebconf-kde-dev,
- libqjson-dev, libqoauth-dev, libqzeitgeist-dev
+ libqjson-dev, libqoauth-dev, libqzeitgeist-dev, python3
 Standards-Version: 3.9.2
+X-Python3-Version: >= 3.2
 Homepage: https://projects.kde.org/projects/extragear/sysadmin/muon/
 
 Package: muon
@@ -103,3 +104,9 @@ Description: Muon debugging symbols
  experienced a Muon crash without this package
  installed, please install it, try to reproduce the problem and fill a bug
  report with a new backtrace attached.
+ 
+Package: check-language-support
+Architecture: all
+Depends: ${misc:Depends}, ${python3:Depends}
+Description: The check-language-support script
+ It finds missing locale packages.
diff --git a/debian/rules b/debian/rules
index 6fd4323..e004c04 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,7 +1,7 @@
 #!/usr/bin/make -f
 
 %:
-	dh $@ --parallel --dbg-package=muon-dbg --with kde
+	dh $@ --parallel --dbg-package=muon-dbg --with kde --with python3
 	
 override_dh_makeshlibs:
 	dh_makeshlibs -Xusr/lib/kde4/ -V 'libmuonprivate2 (=2.2.65)'
diff --git a/debian/scripts/check-language-support b/debian/scripts/check-language-support
new file mode 100644
index 0000000..e9e6592
--- /dev/null
+++ b/debian/scripts/check-language-support
@@ -0,0 +1,73 @@
+#!/usr/bin/python3
+
+from __future__ import print_function
+
+import sys
+import re
+import os.path
+import locale
+from optparse import OptionParser
+from gettext import gettext as _
+
+import language_support_pkgs
+
+if __name__ == "__main__":
+    try:
+        locale.setlocale(locale.LC_ALL, '')
+    except locale.Error:
+        # We might well be running from the installer before locales have
+        # been properly configured.
+        pass
+
+    parser = OptionParser()
+    parser.add_option("-l", "--language",
+            help=_("target language code"))
+    parser.add_option("-d", "--datadir",
+            default="/usr/share/kde4/apps/muon/scripts",
+            help=_("alternative datadir"))
+    parser.add_option("-p", "--package", default=None, help=_("check for the given package(s) only -- separate packagenames by comma"))
+    parser.add_option("-a", "--all", action='store_true', default=False,
+                      help=_("output all available language support packages for all languages"))
+    parser.add_option("--show-installed",
+            action='store_true', default=False,
+            help=_("show installed packages as well as missing ones"))
+    (options, args) = parser.parse_args()
+
+    # sanity check for language code
+    if (options.language and 
+            not re.match('^([a-z]{2,3}(_[A-Z]{2})?(@[a-z]+)?|(zh-han[st]))$', options.language)):
+        print("Error: Unsupported language code format.
\
+               Supported formats: 'll' or 'lll'
\
+               'll_CC' or 'lll_CC'
\
+               'll at variant' or 'lll at variant'
\
+               'll_CC at variant' or 'lll_CC at variant'
\
+               Also supported are 'zh-hans' and 'zh-hant'.",
+               file=sys.stderr)
+        sys.exit(1)
+
+    if options.datadir:
+        pkg_depends = os.path.join(options.datadir, 'data', 'pkg_depends')
+    else:
+        pkg_depends = None
+
+    ls = language_support_pkgs.LanguageSupport(None, pkg_depends)
+
+    missing = set()
+
+    if options.all:
+        ls._countries_for_lang('de') # initialize cache
+        for lang, countries in ls.lang_country_map.items():
+            for country in countries:
+                missing.update(ls.by_locale('%s_%s' % (lang, country), options.show_installed))
+    elif options.package:
+        for package in options.package.split(','):
+            if options.language:
+                missing.update(ls.by_package_and_locale(package, options.language, options.show_installed))
+            else:
+                missing.update(ls.by_package(package, options.show_installed))
+    elif options.language:
+         missing = set(ls.by_locale(options.language, options.show_installed))
+    else:
+         missing = ls.missing(options.show_installed)
+
+    print(' '.join(sorted(missing))) 
diff --git a/debian/scripts/data/check-language-support.1 b/debian/scripts/data/check-language-support.1
new file mode 100644
index 0000000..1e2053a
--- /dev/null
+++ b/debian/scripts/data/check-language-support.1
@@ -0,0 +1,26 @@
+.TH check-language-support 1 "September 23, 2009"  "version 0.1"
+.SH NAME
+
Bcheck-language-support
P \- returns the list of missing packages in order to provide a complete language environment
+.SH SYNOPSIS
+.B check-language-support
+[
Ioptions
R]
+.SH OPTIONS
+.TP
+
B\-h
R, 
B\-\-help
R
+show this help message and exit
+.TP
+
B\-l
R LANGUAGE, 
B\-\-language
R=
ILANGUAGE
R
+target language code - if omitted, check for all languages on the system
+.TP
+
B\-d
R DATADIR, 
B\-\-datadir
R=
IDATADIR
R
+use an alternative data directory instead of the default
+.B /usr/share/language\-selector
+.TP
+
B\-a
R, 
B\-\-all
R
+check all available languages
+.TP
+
B\-\-show\-installed
R
+show installed packages as well as missing ones
+.SH AUTHOR
+This manpage has been written by Arne Goetje <arne at ubuntu.com>
+ 
diff --git a/debian/scripts/data/pkg_depends b/debian/scripts/data/pkg_depends
new file mode 100644
index 0000000..9b95fb0
--- /dev/null
+++ b/debian/scripts/data/pkg_depends
@@ -0,0 +1,201 @@
+# File format:
+# Column 1: category (tr: translations, fn: fonts, in: input method, wa: writing assistence)
+# Column 2: languange code for which the package should only be installed. If empty, install for all languages.
+# The language code will be appended in the specified format
+# Column 3: dependency package(s). Only install the package in column 4 when this dependency package is already installed.
+# Column 4: Package to pull. Can contain language codes at the end if column 2 is empty.
+#
+# Format: %LCODE%
+tr:::language-pack-
+tr::gvfs:language-pack-gnome-
+# Format: %LCODE% or %LCODE%-%CCODE%
+tr::libreoffice-common:libreoffice-l10n-
+tr::libreoffice-common:libreoffice-help-
+tr::firefox:firefox-locale-
+tr::thunderbird:thunderbird-locale-
+tr::lightning-extension:lightning-extension-locale-
+tr::sunbird:sunbird-locale-
+tr::sword-text-gerlut1545:sword-language-pack-
+tr::gimp:gimp-help-
+tr::evolution:evolution-documentation-
+tr::chromium-browser:chromium-browser-l10n
+tr::sylpheed:sylpheed-i18n
+tr::amarok:amarok-help-
+# Format: %LCODE% or %LCODE%%CCODE% or %LCODE%-%VARIANT%
+tr::kdelibs5-data:kde-l10n-
+tr::calligra-libs:calligra-l10n-
+tr::gcompris:gcompris-sound-
+
+# Finnish support for voikko
+wa:fi:firefox:xul-ext-mozvoikko
+wa:fi:thunderbird:xul-ext-mozvoikko
+wa:fi:seahorse:xul-ext-mozvoikko
+wa:fi:epiphany:xul-ext-mozvoikko
+wa:fi:libreoffice-core:libreoffice-voikko
+wa:fi:ispell:tmispell-voikko
+wa:fi::libenchant-voikko
+wa:fi::voikko-fi
+
+# LibreOffice support
+wa::libreoffice-common:hyphen-
+wa::libreoffice-common:mythes-
+wa::libreoffice-common:hunspell-
+# languages which don't provide a hunspell dictionary yet
+wa:af:libreoffice-common:myspell-af
+wa:bg:libreoffice-common:myspell-bg
+wa:ca:libreoffice-common:myspell-ca
+wa:cs:libreoffice-common:myspell-cs
+wa:el:libreoffice-common:myspell-el-gr
+wa:en:libreoffice-common:myspell-en-au
+wa:en:libreoffice-common:myspell-en-gb
+wa:en:libreoffice-common:myspell-en-za
+wa:eo:libreoffice-common:myspell-eo
+wa:es:libreoffice-common:myspell-es
+wa:et:libreoffice-common:myspell-et
+wa:fa:libreoffice-common:myspell-fa
+wa:fo:libreoffice-common:myspell-fo
+wa:ga:libreoffice-common:myspell-ga
+wa:gd:libreoffice-common:myspell-gd
+wa:gv:libreoffice-common:myspell-gv
+wa:he:libreoffice-common:myspell-he
+wa:hr:libreoffice-common:myspell-hr
+wa:hy:libreoffice-common:myspell-hy
+wa:it:libreoffice-common:myspell-it
+wa:ku:libreoffice-common:myspell-ku
+wa:lt:libreoffice-common:myspell-lt
+wa:lv:libreoffice-common:myspell-lv
+wa:nb:libreoffice-common:myspell-nb
+wa:nl:libreoffice-common:myspell-nl
+wa:nn:libreoffice-common:myspell-nn
+wa:nr:libreoffice-common:myspell-nr
+wa:ns:libreoffice-common:myspell-ns
+wa:pl:libreoffice-common:myspell-pl
+wa:pt:libreoffice-common:myspell-pt
+wa:sk:libreoffice-common:myspell-sk
+wa:sl:libreoffice-common:myspell-sl
+wa:ss:libreoffice-common:myspell-ss
+wa:st:libreoffice-common:myspell-st
+wa:sv:libreoffice-common:myspell-sv-se
+wa:sw:libreoffice-common:myspell-sw
+wa:th:libreoffice-common:myspell-th
+wa:tn:libreoffice-common:myspell-tn
+wa:ts:libreoffice-common:myspell-ts
+wa:uk:libreoffice-common:myspell-uk
+wa:ve:libreoffice-common:myspell-ve
+wa:xh:libreoffice-common:myspell-xh
+wa:zu:libreoffice-common:myspell-zu
+
+wa:cs:libreoffice-common:openoffice.org-hyphenation
+wa:da:libreoffice-common:openoffice.org-hyphenation
+wa:el:libreoffice-common:openoffice.org-hyphenation
+wa:en:libreoffice-common:openoffice.org-hyphenation
+wa:es:libreoffice-common:openoffice.org-hyphenation
+wa:fi:libreoffice-common:openoffice.org-hyphenation
+wa:ga:libreoffice-common:openoffice.org-hyphenation
+wa:id:libreoffice-common:openoffice.org-hyphenation
+wa:is:libreoffice-common:openoffice.org-hyphenation
+wa:nl:libreoffice-common:openoffice.org-hyphenation
+wa:pt:libreoffice-common:openoffice.org-hyphenation
+wa:ru:libreoffice-common:openoffice.org-hyphenation
+wa:sk:libreoffice-common:openoffice.org-hyphenation
+wa:sv:libreoffice-common:openoffice.org-hyphenation
+wa:uk:libreoffice-common:openoffice.org-hyphenation
+
+# Aspell support for Sylpheed and Abiword
+wa::sylpheed:hunspell-
+wa::abiword:aspell-
+wa::gedit:hunspell-
+
+# poppler-data is useful for CJK
+wa::poppler-utils:poppler-data
+
+# word lists
+wa:bg::wbulgarian
+wa:ca::wcatalan
+wa:da::wdanish
+wa:de::wngerman
+wa:de::wogerman
+wa:de::wswiss
+wa:en::wamerican
+wa:en::wbritish
+wa:es::wspanish
+wa:fo::wfaroese
+wa:fr::wfrench
+wa:ga::wirish
+wa:ga::wmanx
+wa:gl::wgalician-minimos
+wa:it::witalian
+wa:nb::wnorwegian
+wa:nl::wdutch
+wa:nn::wnorwegian
+wa:pl::wpolish
+wa:pt::wportuguese
+wa:pt::wbrazilian
+wa:sv::wswedish
+wa:uk::wukrainian
+
+# fonts
+fn:am::fonts-sil-abyssinica
+fn:ar::fonts-arabeyes
+fn:ar::fonts-kacst
+fn:as::ttf-bengali-fonts
+fn:bn::ttf-bengali-fonts
+fn:bo::fonts-tibetan-machine
+fn:dz::fonts-tibetan-machine
+fn:el::fonts-mgopen
+fn:fa::fonts-farsiweb
+fn:fa::fonts-sil-scheherazade
+fn:gu::ttf-gujarati-fonts
+fn:he::fonts-sil-ezra
+fn:hi::ttf-devanagari-fonts
+fn:ii::fonts-sil-nuosusil
+fn:ja::fonts-takao-mincho
+fn:ja::fonts-takao-gothic
+fn:km::fonts-khmeros
+fn:kn::ttf-kannada-fonts
+fn:ko::fonts-nanum
+fn:ko::fonts-nanum-coding
+fn:ko::fonts-unfonts-core
+fn:lo::fonts-lao
+fn:ml::ttf-malayalam-fonts
+fn:mn::fonts-manchufont
+fn:mnc::fonts-manchufont
+fn:mr::ttf-devanagari-fonts
+fn:my::fonts-sil-padauk
+fn:ne::ttf-devanagari-fonts
+fn:or::ttf-oriya-fonts
+fn:pa::ttf-punjabi-fonts
+fn:si::fonts-lklug-sinhala
+fn:ta::ttf-tamil-fonts
+fn:te::ttf-telugu-fonts
+fn:th::fonts-thai-tlwg
+fn:ug::fonts-ukij-uyghur
+fn:ur::fonts-nafees
+fn:ur::fonts-sil-scheherazade
+fn:yi::fonts-sil-ezra
+fn:zh-hans::fonts-droid
+fn:zh-hans::fonts-arphic-uming
+fn:zh-hans::fonts-arphic-ukai
+fn:zh-hant::fonts-droid
+fn:zh-hant::fonts-arphic-uming
+fn:zh-hant::fonts-arphic-ukai
+
+# GhostScript CJK resources
+fn:ja:gs-cjk-resource:poppler-data
+fn:ja:gs-cjk-resource:fonts-ipafont-mincho
+fn:ko:gs-cjk-resource:poppler-data
+fn:zh-hans:gs-cjk-resource:poppler-data
+fn:zh-hant:gs-cjk-resource:poppler-data
+
+# input methods
+im:ja:ibus:ibus-anthy
+im:ko:ibus:ibus-hangul
+im:th:ibus:gtk-im-libthai
+im:vi:ibus:ibus-unikey
+im:zh-hans:ibus:ibus-sunpinyin
+im:zh-hans:ibus:ibus-table-wubi
+im:zh-hant:ibus:ibus-chewing
+im:zh-hant:ibus:ibus-table-cangjie3
+im:zh-hant:ibus:ibus-table-cangjie5
+im:zh-hant:ibus:ibus-table-quick-classic
+im:te:ibus:ibus-m17n 
diff --git a/debian/scripts/langtools/language-options b/debian/scripts/langtools/language-options
new file mode 100644
index 0000000..a213944
--- /dev/null
+++ b/debian/scripts/langtools/language-options
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+my $langtoolsdir = './';
+
+# get the locales available on the system
+my @avail_locales = map { chomp; s/\.utf8//; $_ } qx( locale -a | grep -F .utf8 );
+
+# add items without country code to facilitate lookups
+my %extended_localelist;
+for my $loc (@avail_locales) {
+    ( my $lang = $loc ) =~ s/_[A-Z]+//;
+    @extended_localelist{$loc, $lang} = (1, 1);
+}
+
+# get the union of /usr/share/locale-langpack and /usr/share/locale
+my %translation_dirs;
+for my $dir ('/usr/share/locale') {
+    if ( opendir my ($dh), $dir ) {
+        $translation_dirs{$_} = 1 for readdir $dh;
+    }
+}
+
+# get the intersection of available translation_dirs and the extended locale list
+my %intersection;
+for ( keys %extended_localelist ) {
+    $intersection{$_} = 1 if $translation_dirs{$_};
+}
+
+# adjustments
+if ( open my $fh, '<', "$langtoolsdir/main-countries" ) {
+    # If country code items in a language exist:
+    # - Remove the item without country code, since gettext won't find a
+    #   translation under e.g. 'de_DE' if the first item in LANGUAGE is 'de'
+    #   (see https://launchpad.net/bugs/700213). 'en' is kept, though, since
+    #   it's always the last item in LANGUAGE per design.
+    # - Make sure that the main dialect of the language is represented among
+    #   the country code items (see https://launchpad.net/bugs/710148).
+    my %main;
+    while ( <$fh> ) {
+        next if /^\s*(?:#|$)/;
+        my ($k, $v) = split;
+        $main{$k} = $v;
+    }
+    my %count;
+    for ( keys %intersection ) {
+        next if /^en[^a-z]/;
+        ( my $not_country = $_ ) =~ s/_[A-Z]+//;
+        $count{$not_country} ++;
+    }
+    for my $langcode ( keys %count ) {
+        if ( $count{$langcode} > 1 ) {
+            delete $intersection{$langcode};
+            $intersection{ $main{$langcode} } = 1 if $main{$langcode};
+        }
+    }
+} else {
+    # not access to the language-to-main-dialect map
+    # => stick with a minimum of list manipulation
+    delete $intersection{'zh'};
+}
+
+# print the resulting list of language options
+print join("
", sort keys %intersection) || 'en'; 
diff --git a/debian/scripts/langtools/main-countries b/debian/scripts/langtools/main-countries
new file mode 100644
index 0000000..a17d052
--- /dev/null
+++ b/debian/scripts/langtools/main-countries
@@ -0,0 +1,27 @@
+# If multiple country codes are present among the available locales for
+# a language, we may want to map the language code to the language's
+# main or origin country. The list below aims to serve that purpose.
+#
+aa     aa_ET
+ar     ar_EG
+bn     bn_BD
+ca     ca_ES
+de     de_DE
+el     el_GR
+en     en_US
+es     es_ES
+eu     eu_ES
+fr     fr_FR
+fy     fy_NL
+it     it_IT
+li     li_NL
+nl     nl_NL
+om     om_ET
+pa     pa_PK
+pt     pt_PT
+ru     ru_RU
+so     so_SO
+sr     sr_RS
+sv     sv_SE
+ti     ti_ER
+tr     tr_TR 
diff --git a/debian/scripts/language_support_pkgs.py b/debian/scripts/language_support_pkgs.py
new file mode 100644
index 0000000..e3b8df2
--- /dev/null
+++ b/debian/scripts/language_support_pkgs.py
@@ -0,0 +1,279 @@
+#!/usr/bin/python3
+
+import apt
+import subprocess
+
+DEFAULT_DEPENDS_FILE='/usr/share/kde4/apps/muon/scripts/data/pkg_depends'
+
+class LanguageSupport:
+    lang_country_map = None
+
+    def __init__(self, apt_cache=None, depends_file=None):
+        if apt_cache is None:
+            self.apt_cache = apt.Cache()
+        else:
+            self.apt_cache = apt_cache
+
+        self.pkg_depends = self._parse_pkg_depends(depends_file or
+                DEFAULT_DEPENDS_FILE)
+
+    def by_package_and_locale(self, package, locale, installed=False):
+        '''Get language support packages for a package and locale.
+
+        Note that this does not include support packages which are not specific
+        to a particular trigger package, e. g. general language packs. To get
+        those, call this with package==''.
+
+        By default, only return packages which are not installed. If installed
+        is True, return all packages instead.
+        '''
+        packages = []
+        depmap = self.pkg_depends.get(package, {})
+
+        # check explicit entries for that locale
+        for pkglist in depmap.get(self._langcode_from_locale(locale), {}).values():
+            for p in pkglist:
+                if p in self.apt_cache:
+                    packages.append(p)
+
+        # check patterns for empty locale string (i. e. applies to any locale)
+        for pattern_list in depmap.get('', {}).values():
+            for pattern in pattern_list:
+                for pkg_candidate in self._expand_pkg_pattern(pattern, locale):
+                    if pkg_candidate in self.apt_cache:
+                        packages.append(pkg_candidate)
+
+        if not installed:
+            # filter out installed packages
+            packages = [p for p in packages if not self.apt_cache[p].installed]
+        return packages
+
+    def by_locale(self, locale, installed=False):
+        '''Get language support packages for a locale.
+
+        Return all packages which need to be installed in order to provide
+        language support for the given locale for all already installed
+        packages. This should be called after adding a new locale to the
+        system.
+
+        By default, only return packages which are not installed. If installed
+        is True, return all packages instead.
+        '''
+        packages = []
+
+        for trigger in self.pkg_depends:
+            try:
+                if trigger == '' or self.apt_cache[trigger].installed:
+                    packages += self.by_package_and_locale(trigger, locale, installed)
+            except KeyError:
+                continue
+
+        return packages
+
+    def by_package(self, package, installed=False):
+        '''Get language support packages for a package.
+
+        This will install language support for that package for all available
+        system languages. This is a wrapper around available_languages() and
+        by_package_and_locale().
+
+        Note that this does not include support packages which are not specific
+        to a particular trigger package, e. g. general language packs. To get
+        those, call this with package==''.
+
+        By default, only return packages which are not installed. If installed
+        is True, return all packages instead.
+        '''
+        packages = set()
+        for lang in self.available_languages():
+            packages.update(self.by_package_and_locale(package, lang, installed))
+        return packages
+
+    def missing(self, installed=False):
+        '''Get language support packages for current system.
+
+        Return all packages which need to be installed in order to provide
+        language support all system locales for all already installed
+        packages. This should be called after installing the system without
+        language support packages (perhaps because there was no network
+        available to download them).
+
+        This is a wrapper around available_languages() and by_locale().
+
+        By default, only return packages which are not installed. If installed
+        is True, return all packages instead.
+        '''
+        packages = set()
+        for lang in self.available_languages():
+                packages.update(self.by_locale(lang, installed))
+        return self._hunspell_frami_special(packages)
+
+    def _hunspell_frami_special(self, packages):
+        ''' Ignore missing hunspell-de-xx if hunspell-de-xx-frami is installed.
+
+        https://launchpad.net/bugs/1103547
+        '''
+        framis = []
+        for country in ['de', 'at', 'ch']:
+            frami = 'hunspell-de-' + country + '-frami'
+            try:
+                if self.apt_cache[frami].installed:
+                    framis.append(frami)
+            except KeyError:
+                pass
+        if len(framis) == 0:
+            return packages
+        packages_new = set()
+        for pack in packages:
+            if pack + '-frami' not in framis:
+                packages_new.add(pack)
+        return packages_new
+
+    def available_languages(self):
+        '''List available languages in the system.
+
+        The list items can be passed as the "locale" argument of by_locale(),
+        by_package_and_locale(), etc.
+        '''
+        languages = set()
+
+        lang_string = subprocess.check_output(
+            ['/usr/share/kde4/apps/muon/scripts/langtools/language-options'],
+            universal_newlines=True)
+
+        for lang in lang_string.split():
+            languages.add(lang)
+            if not lang.startswith('zh_'):
+                languages.add(lang.split('_')[0])
+
+        return languages
+
+    def _parse_pkg_depends(self, filename):
+        '''Parse pkg_depends file.
+
+        Return trigger_package -> langcode -> category -> [dependency,...] map.
+        '''
+        map = {}
+        with open(filename) as f:
+            for line in f:
+                line = line.strip()
+                if not line or line.startswith('#'):
+                    continue
+
+                (cat, lc, trigger, dep) = line.split(':')
+                map.setdefault(trigger, {}).setdefault(lc, {}).setdefault(cat,
+                        []).append(dep)
+
+        return map
+
+    @classmethod
+    def _langcode_from_locale(klass, locale):
+        '''Turn a locale name into a language code as in pkg_depends.'''
+
+        # special-case Chinese locales, as they are split between -hans and
+        # -hant
+        if locale.startswith('zh_CN') or locale.startswith('zh_SG'):
+            return 'zh-hans'
+        # Hong Kong and Taiwan use traditional
+        if locale.startswith('zh_'):
+            return 'zh-hant'
+
+        return locale.split('_', 1)[0]
+
+    @classmethod
+    def _expand_pkg_pattern(klass, pattern, locale):
+        '''Return all possible suffixes for given pattern and locale'''
+
+        # people might call this with the pseudo-locales "zh-han[st]", support
+        # these as well; we can only guess the country here.
+        if locale == 'zh-hans':
+            locale = 'zh_CN'
+        elif locale == 'zh-hant':
+            locale = 'zh_TW'
+
+        locale = locale.split('.', 1)[0].lower()
+        variant = None
+        country = None
+        try:
+            (lang, country) = locale.split('_', 1)
+            if '@' in country:
+                (country, variant) = country.split('@', 1)
+        except ValueError:
+            lang = locale
+
+        pkgs = [pattern,
+                '%s%s' % (pattern, lang)]
+
+        if country:
+            pkgs.append('%s%s%s' % (pattern, lang, country))
+            pkgs.append('%s%s-%s' % (pattern, lang, country))
+        else:
+            for country in klass._countries_for_lang(lang):
+                pkgs.append('%s%s%s' % (pattern, lang, country))
+                pkgs.append('%s%s-%s' % (pattern, lang, country))
+
+        if variant:
+            pkgs.append('%s%s-%s' % (pattern, lang, variant))
+
+        if country and variant:
+            pkgs.append('%s%s-%s-%s' % (pattern, lang, country, variant))
+
+        # special-case Chinese
+        if lang == 'zh':
+            if country in ['cn', 'sg']:
+                pkgs.append(pattern + 'zh-hans')
+            else:
+                pkgs.append(pattern + 'zh-hant')
+
+        return pkgs
+
+    @classmethod
+    def _countries_for_lang(klass, lang):
+        '''Return a list of countries for given language'''
+
+        if klass.lang_country_map is None:
+            klass.lang_country_map = {}
+            # fill cache
+            with open('/usr/share/i18n/SUPPORTED') as f:
+                for line in f:
+                    line = line.split('#', 1)[0].split(' ')[0]
+                    if not line:
+                        continue
+                    line = line.split('.', 1)[0].split('@')[0]
+                    try:
+                        (l, c) = line.split('_')
+                    except ValueError:
+                        continue
+                    c = c.lower()
+                    klass.lang_country_map.setdefault(l, set()).add(c)
+
+        return klass.lang_country_map.get(lang, [])
+
+def apt_cache_add_language_packs(resolver, cache, depends_file=None):
+    '''Add language support for packages marked for installation.
+    
+    For all packages which are marked for installation in the given apt.Cache()
+    object, mark the corresponding language packs and support packages for
+    installation as well.
+
+    This function can be used as an aptdaemon modify_cache_after plugin.
+    '''
+    ls = LanguageSupport(cache, depends_file)
+    support_pkgs = set()
+    for pkg in cache.get_changes():
+        if pkg.marked_install:
+            support_pkgs.update(ls.by_package(pkg.name))
+
+    for pkg in support_pkgs:
+        cache[pkg].mark_install(from_user=False)
+
+def packagekit_what_provides_locale(cache, type, search, depends_file=None):
+    '''PackageKit WhatProvides plugin for locale().'''
+
+    if not search.startswith('locale('):
+        raise NotImplementedError('cannot handle query type ' + search)
+
+    locale = search.split('(', 1)[1][:-1]
+    ls = LanguageSupport(cache, depends_file)
+    pkgs = ls.by_locale(locale, installed=True)
+    return [cache[p] for p in pkgs] 

-- 
muon packaging



More information about the pkg-kde-commits mailing list