Пример #1
0
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)
Пример #2
0
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()
Пример #3
0
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()
Пример #4
0
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)
class FileOnBlockDevice:
    def __init__(self, path):
        self.__path = path
        self.__dev = BlockDevice(path)

    def exists(self):
        if self.__dev.is_valid():
            return True
        return False

    def create_empty(self):
        self.__dev.format_device()
        self.__dev.write('')

    def copy_from(self, dest_file):
        self.__dev.write_from_file(dest_file)

    def read(self):
        return self.__dev.read()
class FileOnBlockDevice:
    def __init__(self, path):
        self.__path = path
        self.__dev = BlockDevice(path)

    def exists(self):
        if self.__dev.is_valid():
            return True
        return False

    def create_empty(self):
        self.__dev.format_device()
        self.__dev.write('')

    def copy_from(self, dest_file):
        self.__dev.write_from_file(dest_file)

    def read(self):
        return self.__dev.read()
Пример #7
0
def format_bd(device):
    block_dev = BlockDevice(device)
    block_dev.format()
 def __init__(self, path):
     self.__path = path
     self.__dev = BlockDevice(path)
Пример #9
0
def format_bd(device):
    block_dev = BlockDevice(device)
    block_dev.format()
 def __init__(self, path):
     self.__path = path
     self.__dev = BlockDevice(path)