[Kimchi-devel] [PATCH] Make Kimchi show arch linux version and add support for pacman

Aline Manera alinefm at linux.vnet.ibm.com
Tue Jun 30 14:30:11 UTC 2015



On 20/06/2015 10:12, stephan.conrad at gmail.com wrote:
> From: Stephan Conrad <stephan.conrad at gmail.com>
>
> Signed-off-by: Stephan Conrad <stephan.conrad at gmail.com>
> ---
>   src/kimchi/model/host.py |  2 +-
>   src/kimchi/swupdate.py   | 76 ++++++++++++++++++++++++++++++++++++++++++++++--
>   2 files changed, 75 insertions(+), 3 deletions(-)
>
> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
> index b2fa379..477e126 100644
> --- a/src/kimchi/model/host.py
> +++ b/src/kimchi/model/host.py
> @@ -91,7 +91,7 @@ class HostModel(object):
>           res['memory'] = 0L
>
>           # Include IBM PowerKVM name to supported distro names
> -        _sup_distros = platform._supported_dists + ('ibm_powerkvm',)
> +        _sup_distros = platform._supported_dists + ('ibm_powerkvm','arch',)
>           # 'fedora' '17' 'Beefy Miracle'
>           distro, version, codename = platform.linux_distribution(
>               supported_dists=_sup_distros)
> diff --git a/src/kimchi/swupdate.py b/src/kimchi/swupdate.py
> index 70db2ef..752c480 100644
> --- a/src/kimchi/swupdate.py
> +++ b/src/kimchi/swupdate.py
> @@ -26,6 +26,9 @@ from kimchi.exception import NotFoundError, OperationFailed
>   from kimchi.utils import kimchi_log, run_command
>   from kimchi.yumparser import get_yum_packages_list_update
>
> +import re
> +import os
> +
>
>   class SoftwareUpdate(object):
>       __metaclass__ = Singleton
> @@ -63,8 +66,14 @@ class SoftwareUpdate(object):
>                       kimchi_log.info("Loading ZypperUpdate features.")
>                       self._pkg_mnger = ZypperUpdate()
>                   else:
> -                    raise Exception("There is no compatible package manager "
> -                                    "for this system.")

> +                    pacman_help = ["pacman", "--help"]
> +                    (stdout, stderr, returncode) = run_command(pacman_help)
> +                    if returncode == 0:
> +                        kimchi_log.info("Loading PacmanUpdate features.")
> +                        self._pkg_mnger = PacmanUpdate()
> +                    else:
> +                        raise Exception("There is no compatible package manager "
> +                                        "for this system.")

This code is very similar to the zypper block.
I suggest to create a dict with the help command and the class instance 
and build it automatically. We could also do the same for the python 
binding managers.

For example:

self._pkg_mnger = None

mod_managers = {'apt': AptUpdate, 'yum': YumUpdate}
for mod, inst in mod_managers.items():
     try:
         __import__(mod)
         self._pkg_mnger = inst()
         return
     except:
         ....

help_managers = {'pacman': {'help': 'pacman --help', 'manager': 
PacmanUpdate}, 'yum': {....}}

for manager, data in help_managers.items():
     (stdout, stderr, returncode) = run_command(data.split())
     if returncode == 0:
         kimchi_lod.info('Loading %s features' % manager)
         self._pkg_mnger = data[manager]()
         return

raise Exception("There is no compatible package manager for this system.")

>
>       def _scanUpdates(self):
>           """
> @@ -260,3 +269,66 @@ class ZypperUpdate(object):
>           self._refreshUpdateList()
>           kimchiLock.release()
>           return self._pkgs
> +
> +class PacmanUpdate(object):
> +    """
> +    Class to represent and operate with Pacman software update system.
> +    It's loaded only on those systems listed at PACMAN_DISTROS and loads
> +    necessary modules in runtime.
> +    """
> +
> +    def __init__(self):
> +        self._pkgs = {}
> +        self.update_cmd = ["pacman", "-Su", "--noconfirm", "--noprogressbar"]
> +
> +    def _refreshUpdateList(self):
> +        """
> +        Update the list of packages to be updated in the system.
> +        """
> +        self._pkgs = []
> +        cmd_update = ["pacman", "-Sy"]
> +        cmd_list = ["pacman", "-Qu"]
> +        (stdout, stderr, rc) = run_command(cmd_update)
> +        if rc > 0:
> +            raise OperationFailed('KCHPKGUPD0003E', {'err': stderr})
> +
> +        (stdout, stderr, rc) = run_command(cmd_list)
> +        if rc > 0:
> +            if not (rc == 1 and len(stdout)==0):
> +                raise OperationFailed('KCHPKGUPD0003E', {'err': stderr})
> +
> +        os.environ['LANG'] = 'C'
> +
> +        for line in stdout.split('\n'):
> +            if line.find('->') >= 0:
> +                info = line.split(" ")
> +                (sout, serr, ret) = run_command(["pacman", "-Si", info[0]])
> +                if len(sout) > 0:
> +                    for l in sout.split('\n'):
> +                        i = re.split('\s+', l.strip())
> +                        if len(i) >= 2:
> +                            if i[0] == "Repository":
> +                                repo = i[2]
> +                            elif i[0] == "Architecture":
> +                                arch = i[2]
> +                if arch == "any":
> +                    arch = "noarch"
> +                package = {
> +                    'package_name': info[0],
> +                    'version': info[3],
> +                    'arch': arch,
> +                    'repository': repo
> +                    }
> +                self._pkgs.append(package)
> +
> +    def getPackagesList(self):
> +        """
> +        Return a list of package's dictionaries. Each dictionary contains the
> +        information about a package, in the format
> +        package = {'package_name': <string>, 'version': <string>,
> +                   'arch': <string>, 'repository': <string>}
> +        """
> +        self._refreshUpdateList()
> +        return self._pkgs
> +
> +




More information about the Kimchi-devel mailing list