def __init__(self, board, dryrun=False): """ :param board: :class:`Board` instance. :param dryrun: Enable dryrun mode. Systems commands will be logged, but not executed. :type dryrun: boolean """ self._l = utils.logger.get_global_logger() self._e = utils.executer.get_global_executer() self._board = board self._ld = LoopDevice() self._dryrun = dryrun self._e.dryrun = dryrun self._ld.dryrun = dryrun self._board.dryrun = dryrun self._partitions = []
class LoopDeviceInstaller(object): """ Class to handle SD-card operations in a loopback file to support the installer. Typical flow: :: 1. read_partitions() 2. format() 3. mount_partitions() 4. install_components() 5. release() """ def __init__(self, board, dryrun=False): """ :param board: :class:`Board` instance. :param dryrun: Enable dryrun mode. Systems commands will be logged, but not executed. :type dryrun: boolean """ self._l = utils.logger.get_global_logger() self._e = utils.executer.get_global_executer() self._board = board self._ld = LoopDevice() self._dryrun = dryrun self._e.dryrun = dryrun self._ld.dryrun = dryrun self._board.dryrun = dryrun self._partitions = [] def __set_dryrun(self, dryrun): self._dryrun = dryrun self._board.dryrun = dryrun self._e.dryrun = dryrun self._ld.dryrun = dryrun def __get_dryrun(self): return self._dryrun dryrun = property(__get_dryrun, __set_dryrun, doc="""Enable dryrun mode. Systems commands will be logged, but not executed.""") def format(self, img_name, img_size_mb): """ Creates and formats the partitions in the SD card. :returns: Returns true on success; false otherwise. :exception DeviceException: On failure formatting the device. """ if not self.dryrun: self._ld.check_img_size(img_size_mb) self._l.info('Formatting %s (this may take a while)' % self._ld.name) self._ld.attach_device(img_name, img_size_mb) self._ld.create_partitions() self._ld.attach_partitions(img_name, img_size_mb) self._ld.format_partitions() def mount_partitions(self, directory): """ Mounts the partitions in the specified directory. :exception DeviceException: When unable to mount. """ self._ld.mount(directory) def install_components(self): """ Installs the specified components for each partition. :exception LoopDeviceInstallerError: On failure installing the components. """ try: self._board.ld_install_components(self._ld) except BoardError as e: raise LoopDeviceInstallerError(e) def release(self): """ Unmounts all partitions and release the given device. :exception DeviceException: On failure releasing the device. """ self._ld.unmount() self._ld.optimize_filesystems() self._ld.check_filesystems() self._ld.detach_partitions() self._ld.detach_device() def read_partitions(self, filename): """ Reads the partitions information from the given file. :param filename: Path to the file with the partitions information. :returns: Returns true on success; false otherwise. """ self._ld.read_partitions(filename)