Prints partition information of given <device>

    CLI Examples:

    .. code-block:: bash

        salt '*' partition.list /dev/sda
        salt '*' partition.list /dev/sda unit=s
        salt '*' partition.list /dev/sda unit=kB

def list_(device, unit=None):
    '''
    Prints partition information of given <device>

    CLI Examples:

    .. code-block:: bash

        salt '*' partition.list /dev/sda
        salt '*' partition.list /dev/sda unit=s
        salt '*' partition.list /dev/sda unit=kB
    '''
    _validate_device(device)

    if unit:
        if unit not in VALID_UNITS:
            raise CommandExecutionError(
                'Invalid unit passed to partition.part_list'
            )
        cmd = 'parted -m -s {0} unit {1} print'.format(device, unit)
    else:
        cmd = 'parted -m -s {0} print'.format(device)

    out = __salt__['cmd.run_stdout'](cmd).splitlines()
    ret = {'info': {}, 'partitions': {}}
    mode = 'info'
    for line in out:
        if line in ('BYT;', 'CHS;', 'CYL;'):
            continue
        cols = line.rstrip(';').split(':')
        if mode == 'info':
            if 7 <= len(cols) <= 8:
                ret['info'] = {
                    'disk': cols[0],
                    'size': cols[1],
                    'interface': cols[2],
                    'logical sector': cols[3],
                    'physical sector': cols[4],
                    'partition table': cols[5],
                    'model': cols[6]}
                if len(cols) == 8:
                    ret['info']['disk flags'] = cols[7]
                    # Older parted (2.x) doesn't show disk flags in the 'print'
                    # output, and will return a 7-column output for the info
                    # line. In these cases we just leave this field out of the
                    # return dict.
                mode = 'partitions'
            else:
                raise CommandExecutionError(
                    'Problem encountered while parsing output from parted')
        else:
            # Parted (v3.1) have a variable field list in machine
            # readable output:
            #
            # number:start:end:[size:]([file system:name:flags;]|[free;])
            #
            # * If units are in CHS 'size' is not printed.
            # * If is a logical partition with PED_PARTITION_FREESPACE
            #   set, the last three fields are replaced with the
            #   'free' text.
            #
            fields = ['number', 'start', 'end']
            if unit != 'chs':
                fields.append('size')
            if cols[-1] == 'free':
                # Drop the last element from the list
                cols.pop()
            else:
                fields.extend(['file system', 'name', 'flags'])
            if len(fields) == len(cols):
                ret['partitions'][cols[0]] = dict(six.moves.zip(fields, cols))
            else:
                raise CommandExecutionError(
                    'Problem encountered while parsing output from parted')
    return ret