def write_to_dev(device, s_path):
    if not os.path.exists(s_path):
        raise Exception('source path %s does not found!' % s_path)

    block_dev = BlockDevice(device)
    block_dev.check_id_mbr()
    try:
        data = open(s_path, 'rb').read()
    except IOError:
        raise IOError('Can not read from "%s"' % s_path)
    block_dev.int_write(data)
def write_to_dev(device, s_path):
    if not os.path.exists(s_path):
        raise Exception('source path %s does not found!'%s_path)

    block_dev = BlockDevice(device)
    block_dev.check_id_mbr()
    try:
        data = open(s_path, 'rb').read()
    except IOError:
        raise IOError('Can not read from "%s"'%s_path)
    block_dev.int_write(data)
def read_from_dev(device, d_path):
    try:
        fd = open(d_path, 'wb')
    except IOError:
        raise Exception('permission denied to %s!' % d_path)
    try:
        block_dev = BlockDevice(device)
        block_dev.check_id_mbr()
        data = block_dev.int_read()
        fd.write(data)
    finally:
        fd.close()
def read_from_dev(device, d_path):
    try:
        fd = open(d_path, 'wb')
    except IOError:
        raise Exception('permission denied to %s!'%d_path)
    try:
        block_dev = BlockDevice(device)
        block_dev.check_id_mbr()
        data = block_dev.int_read()
        fd.write(data)
    finally:
        fd.close()