[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [PATCH] Add functions that relate dm nodes and dm names
- From: David Lehman <dlehman redhat com>
- To: Discussion of Development and Customization of the Red Hat Linux Installer <anaconda-devel-list redhat com>
- Subject: Re: [PATCH] Add functions that relate dm nodes and dm names
- Date: Thu, 15 Jan 2009 11:55:18 -0600
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" ]
>
> #
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]