Oups ... désolé.
Erwann
-----Message d'origine-----
De : anaconda-devel-list-bounces redhat com [mailto:anaconda-devel-list-bounces redhat com] De la part de Joel Granados
Envoyé : mardi 20 janvier 2009 14:16
À : Discussion of Development and Customization of the Red Hat Linux Installer
Objet : Re: [PATCH] Add functions that relate dm nodes and dm names
----- "David Lehman" <dlehman redhat com> wrote:
> On Thu, 2009-01-15 at 17:10 +0100, Joel Granados Moreno wrote:
> > ---
> > __init__.py | 43 +++++++++++++++++++++++++++++++++++++++++++
> > 1 files changed, 43 insertions(+), 0 deletions(-)
>
> A single return statement per function would improve readability IMO
This is discussable. I would like to see a move toward a general code convention agreement. So, for example, in this case, we can code **all** our (anaconda) functions in this way. This would increase readability even more. For now, I'll make the changes in the newly created function for pyblock.
Just thinking out loud here.
> but
> it looks good to me in general.
>
> >
> > diff --git a/__init__.py b/__init__.py
> > index 523ad74..d1db3da 100644
> > --- a/__init__.py
> > +++ b/__init__.py
> > @@ -241,6 +241,49 @@ def getDmTarget(uuid = None, major = None,
> minor = None, name = None):
> > return map.table.type
> > return None
> >
> > +def getNameFromDmNode(dm_node):
> > + """ Return the related name for the specified node.
> > +
> > + Expects a device node with or without the "/dev" prefix.
> > +
> > + Returns a String representing the name. None if the major,
> minor
> > + pair was not found in the maps list.
> > + """
> > +
> > + if not dm_node.startswith("/dev"):
> > + import os.path as _path
> > + dm_node = _path.join("/dev", dm_node)
> > + del _path
> > +
> > + import os as _os
> > + stat = _os.stat(dm_node)
> > + major = long(_os.major(stat.st_rdev))
> > + minor = long(_os.minor(stat.st_rdev))
> > + del _os
> > +
> > + for map in dm.maps():
> > + if map.dev.major == major and map.dev.minor == minor:
> > + return map.name
> > +
> > + # In case the major, minor pair is not found in maps.
> > + return None
> > +
> > +
> > +def getDmNodeFromName(name):
> > + """ Return the related node for the specified name.
> > +
> > + Expects a string representing the name.
> > +
> > + Returns dm-MINOR if the map list contains the specified name.
> > + None if name was not found.
> > + """
> > + for map in dm.maps():
> > + if map.name == name:
> > + return "dm-%s" % map.dev.minor
> > +
> > + return None
> > +
> > +
> > __all__ = [ "dm", "dmraid", "BlockDev" ]
> >
> > #
>
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list redhat com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list
--
Joel Andres Granados
Red Hat / Brno Czech Republic
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list redhat com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
Attachment:
253496.s3
Description: 253496.s3