[Kimchi-devel] [PATCH 5/6] isoinfo: Move _probe_iso() to IsoImage()

Sheldon shaohef at linux.vnet.ibm.com
Mon Jan 6 04:55:17 UTC 2014


Just a minor comment below

On 01/04/2014 03:18 AM, Aline Manera wrote:
> From: Aline Manera <alinefm at br.ibm.com>
>
> That way all operations related to IsoImage() object will be in this class.
>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
>   src/kimchi/isoinfo.py    |   57 +++++++++++++++++++---------------------------
>   src/kimchi/model.py      |    5 ++--
>   src/kimchi/scan.py       |    5 ++--
>   src/kimchi/vmtemplate.py |    4 +++-
>   4 files changed, 33 insertions(+), 38 deletions(-)
>
> diff --git a/src/kimchi/isoinfo.py b/src/kimchi/isoinfo.py
> index 83e4b95..46e0cf3 100644
> --- a/src/kimchi/isoinfo.py
> +++ b/src/kimchi/isoinfo.py
> @@ -154,6 +154,26 @@ class IsoImage(object):
>
>           raise IsoFormatError('ISO %s does not exist' % self.path)
>
> +    def probe(self):
> +        if not self.bootable:
> +            raise IsoFormatError("ISO %s not bootable" % self.path)
> +
> +        matcher = Matcher(self.volume_id)
> +
> +        for d, v, regex in iso_dir:
> +            if matcher.search(regex):
> +                distro = d
> +                if hasattr(v, '__call__'):
> +                    version = v(matcher)
> +                else:
> +                    version = v
> +                return (distro, version)
> +
> +        kimchi_log.debug("probe_iso: Unable to identify ISO %s with Volume ID: %s"
> +                     % (self.path, self.volume_id))
log prefers comma.
seems you copy it from the below code. :-)
> +
> +        return ('unknown', 'unknown')
> +
>       def _unpack(self, s, data):
>           return s.unpack(data[:s.size])
>
> @@ -259,33 +279,6 @@ class Matcher(object):
>           return self.lastmatch.group(num)
>
>
> -def _probe_iso(fname, remote = None):
> -    try:
> -        iso = IsoImage(fname, remote)
> -    except Exception, e:
> -        kimchi_log.warning("probe_iso: Error processing ISO image: %s\n%s" %
> -                           (fname, e))
> -        raise IsoFormatError(e)
> -
> -    if not iso.bootable:
> -        raise IsoFormatError("ISO %s not bootable" % fname)
> -
> -    matcher = Matcher(iso.volume_id)
> -
> -    for d, v, regex in iso_dir:
> -        if matcher.search(regex):
> -            distro = d
> -            if hasattr(v, '__call__'):
> -                version = v(matcher)
> -            else:
> -                version = v
> -            return (distro, version)
> -
> -    kimchi_log.debug("probe_iso: Unable to identify ISO %s with Volume ID: %s"
> -                     % (fname, iso.volume_id))
> -    return ('unknown', 'unknown')
> -
> -
>   def probe_iso(status_helper, params):
>       loc = params['path'].encode("utf-8")
>       updater = params['updater']
> @@ -311,22 +304,20 @@ def probe_iso(status_helper, params):
>                       continue
>                   iso = os.path.join(root, name)
>                   try:
> -                    ret = _probe_iso(iso, False)
> +                    iso_img = IsoImage(iso)
> +                    ret = iso_img.probe()
>                       update_result(iso, ret)
>                   except:
>                       continue
>       else:
> -        ret = _probe_iso(loc)
> +        iso_img = IsoImage(loc)
> +        ret = iso_img.probe()
>           update_result(loc, ret)
>
>       if status_helper != None:
>           status_helper('', True)
>
>
> -def probe_one(iso):
> -    return _probe_iso(iso)
> -
> -
>   if __name__ == '__main__':
>       iso_list = []
>       def updater(iso_info):
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index f48f3d3..7115583 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -55,7 +55,6 @@ except ImportError:
>
>
>   from kimchi import config
> -from kimchi import isoinfo
>   from kimchi import netinfo
>   from kimchi import network as knetwork
>   from kimchi import vnc
> @@ -66,6 +65,7 @@ from kimchi.exception import InvalidOperation, InvalidParameter, IsoFormatError
>   from kimchi.exception import MissingParameter, NotFoundError, OperationFailed
>   from kimchi.featuretests import FeatureTests
>   from kimchi.iscsi import TargetClient
> +from kimchi.isoinfo import IsoImage
>   from kimchi.networkxml import to_network_xml
>   from kimchi.objectstore import ObjectStore
>   from kimchi.scan import Scanner
> @@ -1182,7 +1182,8 @@ class Model(object):
>                   path = os.path.join(os.path.dirname(path), os.readlink(path))
>               os_distro = os_version = 'unknown'
>               try:
> -                os_distro, os_version = isoinfo.probe_one(path)
> +                iso_img = IsoImage(path)
> +                os_distro, os_version = iso_img.probe()
>                   bootable = True
>               except IsoFormatError:
>                   bootable = False
> diff --git a/src/kimchi/scan.py b/src/kimchi/scan.py
> index 27be1da..e192f01 100644
> --- a/src/kimchi/scan.py
> +++ b/src/kimchi/scan.py
> @@ -29,7 +29,7 @@ import tempfile
>   import time
>
>
> -from kimchi.isoinfo import probe_iso, probe_one
> +from kimchi.isoinfo import IsoImage, probe_iso
>   from kimchi.utils import kimchi_log
>
>
> @@ -73,7 +73,8 @@ class Scanner(object):
>
>               duplicates = "%s/%s*" % (params['pool_path'], iso_name)
>               for f in glob.glob(duplicates):
> -                if (iso_info['distro'], iso_info['version']) == probe_one(f):
> +                iso_img = IsoImage(f)
> +                if (iso_info['distro'], iso_info['version']) == iso_img.probe():
>                       return
>
>               iso_path = iso_name + hashlib.md5(iso_info['path']).hexdigest() + '.iso'
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index 1720384..69af6ec 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -30,6 +30,7 @@ import urlparse
>   from kimchi import isoinfo
>   from kimchi import osinfo
>   from kimchi.exception import InvalidParameter, IsoFormatError
> +from kimchi.isoinfo import IsoImage
>
>
>   QEMU_NAMESPACE = "xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'"
> @@ -63,7 +64,8 @@ class VMTemplate(object):
>                   self.info.update({'iso_stream': True})
>
>               try:
> -                iso_distro, iso_version = isoinfo.probe_one(iso)
> +                iso_img = IsoImage(iso)
> +                iso_distro, iso_version = iso_img.probe()
>               except IsoFormatError, e:
>                   raise InvalidParameter(e)
>


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list