Add functions that relate dm nodes and dm names
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 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 |
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 |
Add functions that relate dm nodes and dm names
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 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@redhat.com https://www.redhat.com/mailman/listinfo/anaconda-devel-list |
Add functions that relate dm nodes and dm names
----- "Joel Granados" <jgranado@redhat.com> wrote:
> ----- "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. The following functions expresses what I mean. In the last 4 functions the additional effort that has to be done to create the function seems overkill to me (its two additional lines more with the one point of return approach). I still think its more readable, in these cases, to have the various return statements. IMO, for functions that are counted in the tens of lines, it is more readable to use various return statements. FUNCTIONS: def getDmTarget(uuid = None, major = None, minor = None, name = None): retval = None for map in dm.maps(): if (map.name and map.name == name) or (map.uuid is not None and map.uuid == uuid) or (map.dev.minor is not None and map.dev.minor == long(minor)and map.dev.major is not None and map.dev.major == long(major)):. retval = map.table.type break return retval def getNameFromDmNode(dm_node): retval = None 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: retval = map.name break return retval def getDmNodeFromName(name): retval = None for map in dm.maps(): if map.name == name: retval = "dm-%s" % map.dev.minor break return retval > 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 -- 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 |
| All times are GMT. The time now is 09:14 AM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.