import re


def available_space(ctx, device):
    """
    Determine the available space on device such as bootflash or stby-bootflash:

    :param ctx:
    :param device: bootflash / stby-bootflash: / harddisk: / stby-harddisk:
    :return: the available space
    """

    available = -1
    output = ctx.send('dir ' + device)
    m = re.search(r'(\d+) bytes free', output)
    if m:
        available = int(m.group(1))

    return available