[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: comps discussion at fudcon and the future



Kevin Kofler (kevin kofler chello at) said: 
> seth vidal wrote:
> > Conditional packages were viewed, from the outset, as something that had
> > to go. One way or the other conditional pkgs were going to get beaten
> > up.
> 
> But it can't go because there's no working alternative.

Well... attached is a prototype of a yum plugin to do this sort of stuff.

However:

- KDE would need to be repackaged so their packages are kde-l10n-fr,
  kde-i18n-de, etc. Same for some other packages (scim-lang?)
- The actual list of conditional packages would still need to be
  in the external metadata that's used to define the groups, as it
  shouldn't be hardcoded in the plugin, nor dropped on the filesystem

Bill
#!/bin/env python
# -*- coding: utf-8 -*-
#
# Conditional language support packages, via a yum plugin
#
# Copyright © 2009 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

from yum.plugins import TYPE_CORE

import fnmatch
import glob
import locale
import rpm

requires_api_version = '2.5'
plugin_type = TYPE_CORE

langs = []

# This needs to be in the metadata somewhere. For a POC, this works.
conditional_pkgs = {
  'aspell' : [ 'aspell-%s', 'hunspell-%s' ],
  'eclipse-platform' : [ 'eclipse-nls-%s' ],
  'gcompris' : [ 'gcompris-sound-%s'],
  'hunspell' : [ 'hunspell-%s' ],
  'hyphen' : [ 'hyphen-%s' ],
  'kdelibs3' : [ 'kde-i18n-%s' ],
  'kdelibs' : [ 'kde-l10n-%s' ],
  'koffice-core' : [ 'koffice-langpack-%s' ],
  'LabPlot-doc' : [ 'LabPlot-doc-%s' ],
  'man-pages' : [ 'man-pages-%s' ],
  'moodle' : [ 'moodle-%s' ],
  'openoffice.org-core' : [ 'openoffice.org-langpack-%s' ],
  'tesseract' : [ 'tesseract-langpack-%s' ],
  'xorg-x11-server-Xorg' : [ 'scim-lang-%s' ]
}

def config_hook(conduit):
    global conditional_pkgs
    
    # Here is where we would read conditional pkgs from some sort of
    # metadata. For now, they're defined above

def init_hook(conduit):
    global langs
    
    (lang, encoding) = locale.getdefaultlocale()
    
    rpm_langs = rpm.expandMacro("%_install_langs")
    # FIXME - what to do here? 'all' seems to be the default
    if rpm_langs == "all":
        #langs.append('*')
        #print "YOU GET TO DRINK FROM THE FIRE HOSE!"
        #return
        pass
    else:
        langlist = rpm_langs.split(':')
        for l in langlist:
            print "Adding %s to language list" % (l,)
            langs.append(l)
    print "Adding %s to language list" % (lang,)
    langs.append(lang)

def add_deps_to_ts(conduit, po):
    conds = conditional_pkgs[po.name]
    sack = conduit.getRepos().getPackageSack()
    tsInfo = conduit.getTsInfo()
    for lang in langs:
        pkgs = sack.returnPackages(patterns = map(lambda x: x % (lang,), conds))
        if not pkgs and lang != '*':
            shortlang = lang.split('_')[0]
            pkgs = sack.returnPackages(patterns = map(lambda x: x % (shortlang,), conds))
        for po in pkgs:
            print "Adding %s to transaction" % (po.name)
            tsInfo.addInstall(po)

def remove_deps_from_ts(conduit, po):
    conds = conditional_pkgs[po.name]
    pkgs = conduit.getRpmDB().returnPackages()
    tsInfo = conduit.getTsInfo()
    for pkg in pkgs:
        for c in conds:
            for lang in langs:
              if fnmatch.fnmatch(pkg.name, c % (lang,)):
                  print "Removing %s from system" % (pkg.name)
                  tsInfo.addErase(pkg)
              shortlang = lang.split('_')[0]
              if fnmatch.fnmatch(pkg.name, c % (shortlang,)):
                  print "Removing %s from system" % (pkg.name)
                  tsInfo.addErase(pkg)

def postresolve_hook(conduit):
    for member in conduit.getTsInfo().getMembers():
        po = member.po
        if conditional_pkgs.has_key(po.name):
            print "AOOOGA AOOOGA %s" % ( po.name )
            if member.ts_state in ('i', 'u'):
                add_deps_to_ts(conduit, po)
            elif member.ts_state in ('e'):
                remove_deps_from_ts(conduit, po)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]