Re: [PATCH] Add functions that relate dm nodes and dm names

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux