usb:v0627p0001d0000dc00dsc00dp00ic03isc01ip01in00
  #   li~h
nbѿeǜw  
   355  +   	lY>C]m@EqTţ6/_I|+ ?     # Copyright (C) 2014 Red Hat, Inc.
# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; If not, see <http://www.gnu.org/licenses/>.
#
# Author: Gris Ge <fge@redhat.com>
import sys
from datetime import datetime

from lsm import (size_bytes_2_size_human, LsmError, ErrorNumber, Battery,
                 System, Pool, Disk, Volume, AccessGroup,
                 FileSystem, FsSnapshot, NfsExport, TargetPort, LocalDisk)

try:
    from collections import OrderedDict
except ImportError:
    # python 2.6 or earlier, use backport
    from ordereddict import OrderedDict


BIT_MAP_STRING_SPLITTER = ','


# Users are reporting errors with broken pipe when piping output
# to another program.  This appears to be related to this issue:
# http://bugs.python.org/issue11380
# Unable to reproduce, but hopefully this will address it.
# @param msg    The message to be written to stdout
def out(msg):
    try:
        sys.stdout.write(str(msg))
        sys.stdout.write("\n")
        sys.stdout.flush()
    except IOError:
        sys.exit(1)


def _bit_map_to_str(bit_map, conv_dict):
    rc = []
    bit_map = int(bit_map)
    for cur_enum in list(conv_dict.keys()):
        if cur_enum & bit_map:
            rc.append(conv_dict[cur_enum])
    # If there are no bits set we really don't need a string
    if bit_map != 0 and len(rc) == 0:
        return 'Unknown(%s)' % hex(bit_map)
    return BIT_MAP_STRING_SPLITTER.join(rc)


def _enum_type_to_str(int_type, conv_dict):
    int_type = int(int_type)

    if int_type in list(conv_dict.keys()):
        return conv_dict[int_type]
    return 'Unknown(%d)' % int_type


def _str_to_enum(type_str, conv_dict):
    keys = [k for k, v in list(conv_dict.items())
            if v.lower() == type_str.lower()]
    if len(keys) > 0:
        return keys[0]
    raise LsmError(ErrorNumber.INVALID_ARGUMENT,
                   "Failed to convert %s to lsm type" % type_str)


_SYSTEM_STATUS_CONV = {
    System.STATUS_UNKNOWN: 'Unknown',
    System.STATUS_OK: 'OK',
    System.STATUS_ERROR: 'Error',
    System.STATUS_DEGRADED: 'Degraded',
    System.STATUS_PREDICTIVE_FAILURE: 'Predictive failure',
    System.STATUS_OTHER: 'Other',
}


def system_status_to_str(system_status):
    return _bit_map_to_str(system_status, _SYSTEM_STATUS_CONV)


_SYSTEM_MODE_CONV = {
    System.MODE_HARDWARE_RAID: "HW RAID",
    System.MODE_HBA: "HBA",
}


def system_mode_to_str(system_mode):
    return _SYSTEM_MODE_CONV.get(system_mode, "")


_POOL_STATUS_CONV = {
    Pool.STATUS_UNKNOWN: 'Unknown',
    Pool.STATUS_OK: 'OK',
    Pool.STATUS_OTHER: 'Other',
    Pool.STATUS_DEGRADED: 'Degraded',
    Pool.STATUS_ERROR: 'Error',
    Pool.STATUS_STOPPED: 'Stopped',
    Pool.STATUS_RECONSTRUCTING: 'Reconstructing',
    Pool.STATUS_VERIFYING: 'Verifying',
    Pool.STATUS_INITIALIZING: 'Initializing',
    Pool.STATUS_GROWING: 'Growing',
}


def pool_status_to_str(pool_status):
    return _bit_map_to_str(pool_status, _POOL_STATUS_CONV)


_POOL_ELEMENT_TYPE_CONV = {
    Pool.ELEMENT_TYPE_POOL: 'POOL',
    Pool.ELEMENT_TYPE_VOLUME: 'VOLUME',
    Pool.ELEMENT_TYPE_VOLUME_THIN: 'VOLUME_THIN',
    Pool.ELEMENT_TYPE_VOLUME_FULL: 'VOLUME_FULL',
    Pool.ELEMENT_TYPE_FS: 'FS',
    Pool.ELEMENT_TYPE_SYS_RESERVED: 'SYSTEM_RESERVED',
    Pool.ELEMENT_TYPE_DELTA: "DELTA",
}

_POOL_UNSUPPORTED_ACTION_CO