Exemplo n.º 1
0
    def write(self,
              fd=None,
              image=_global.ALL_IMAGES,
              write_flags=None,
              threads=4):
        if self.path is None:
            raise WIMError("self.path is None, no file to write to.")

        path = _backend.ffi.new("char[]", self.path)
        write_flags = write_flags if write_flags is not None else 0

        if not self._has_baking_file:
            if fd:
                ret = _backend.lib.wimlib_write_to_fd(self._wim_struct,
                                                      fd.fileno(), image,
                                                      write_flags, threads)
            else:
                ret = _backend.lib.wimlib_write(self._wim_struct, path, image,
                                                write_flags, threads)
        else:
            ret = _backend.lib.wimlib_overwrite(self._wim_struct, write_flags,
                                                threads)

        if ret:
            raise WIMError(ret)
Exemplo n.º 2
0
 def info(self):
     """ Get information about this WIM """
     info = _backend.ffi.new("struct wimlib_wim_info*")
     ret = _backend.lib.wimlib_get_wim_info(self._wim_struct, info)
     if ret:
         raise WIMError(ret)
     return wimlib.info.Info(info)
Exemplo n.º 3
0
 def set_property(self, property_name, value):
     """ Set a property in the XML metadata for the image """
     ret = _backend.lib.wimlib_set_image_property(self._wim_struct,
                                                  self.index, property_name,
                                                  value)
     if ret:
         raise WIMError(ret)
Exemplo n.º 4
0
 def add_empty(self, name=""):
     """ Add an empty image """
     ret = _backend.lib.wimlib_add_empty_image(self._wim_struct, name,
                                               _backend.ffi.NULL)
     if ret:
         raise WIMError(ret)
     return self.refresh(True)
Exemplo n.º 5
0
 def mount(self, mount_dir, flags=0, staging_dir=_backend.ffi.NULL):
     """ Mount the image in the specified target directory """
     ret = _backend.lib.wimlib_mount_image(self._wim_struct, self.index,
                                           mount_dir, flags, staging_dir)
     if ret:
         raise WIMError(ret)
     self.mounts.append(mount_dir)
Exemplo n.º 6
0
 def add(self, source, name="", config="", flags=0):
     """ Add image from filesystem path """
     ret = _backend.lib.wimlib_add_image(self._wim_struct, source, name,
                                         config, flags)
     if ret:
         raise WIMError(ret)
     return self.refresh(True)
Exemplo n.º 7
0
 def extract_pathlist(self, target, pathlist_file, flags):
     """ Like Image.extract_paths but pathlist is a file on the local filesystem"""
     ret = _backend.lib.wimlib_extract_pathlist(self._wim_struct,
                                                self.index, target,
                                                pathlist_file, flags)
     if ret:
         raise WIMError(ret)
Exemplo n.º 8
0
 def create(self):
     decompressor = _backend.ffi.new("struct wimlib_decompressor**")
     ret = _backend.lib.wimlib_create_decompressor(self.compression_type,
                                                   self.block_size,
                                                   decompressor)
     if ret:
         raise WIMError(ret)
     self._decompressor = decompressor[0]
Exemplo n.º 9
0
 def decompress(self, data, original_size):
     out_buffer = _backend.ffi.new(
         "unsigned char[{0}]".format(original_size))
     ret = _backend.lib.wimlib_decompress(data, len(data), out_buffer,
                                          original_size, self._decompressor)
     if ret:
         raise WIMError("wimlib_decompress returned {0}.".format(ret))
     return bytes(_backend.ffi.buffer(out_buffer, original_size))
Exemplo n.º 10
0
 def info(self, value):
     if not isinstance(value, wimlib.info.Info):
         raise ValueError(
             "Error: property info sould be set to type of Info().")
     ret = _backend.lib.wimlib_set_wim_info(self._wim_struct,
                                            value._info_struct)
     if ret:
         raise WIMError(ret)
Exemplo n.º 11
0
 def extract_paths(self, target, paths, flags):
     """ Extract a list of paths from the image """
     paths = [_backend.ffi.new("char[]", path) for path in paths]
     paths_array = _backend.ffi.new("char*[]", paths)
     ret = _backend.lib.wimlib_extract_paths(self._wim_struct, self.index,
                                             target, paths_array,
                                             len(paths), flags)
     if ret:
         raise WIMError(ret)
Exemplo n.º 12
0
 def delete(self, image):
     """ Delete an image """
     try:
         image = int(image)
     except ValueError:
         raise ValueError(
             "Error: Argument image must be of type int() or Image()")
     ret = _backend.lib.wimlib_delete_image(self._wim_struct, image)
     if ret:
         raise WIMError(ret)
Exemplo n.º 13
0
 def xml_data(self, buffer_size=4096):
     """ Get the XML data from the file """
     out_buffer = _backend.ffi.new("void**")
     out_size = _backend.ffi.new("size_t*")
     ret = _backend.lib.wimlib_get_xml_data(self._wim_struct, out_buffer,
                                            out_size)
     if ret:
         raise WIMError(ret)
     return bytes(
         _backend.ffi.buffer(_backend.ffi.cast("char*", out_buffer[0]),
                             out_size[0]))
Exemplo n.º 14
0
 def unmount(self,
             mount_dir,
             flags=0,
             progress_func=None,
             progress_context=None):
     """ Unmount the mounted image in the specified directory. """
     if not progress_func:
         ret = _backend.lib.wimlib_unmount_image(mount_dir, flags)
         if ret:
             raise WIMError(ret)
     else:
         self._unmount_with_progress(mount_dir, flags, callback, context)
     self.mounts.remove(mount_dir)
Exemplo n.º 15
0
 def export_image(self,
                  target_wim,
                  target_name=None,
                  target_description=None,
                  flags=None):
     """ Export the image to a diffrent WIM file """
     target_name = target_name if target_name is not None else self.name
     flags = flags if flags is not None else 0
     target_description = target_description if target_description is not None else self.description
     ret = _backend.lib.wimlib_export_image(self._wim_struct, self.index, target_wim._wim_struct, \
             _backend.ffi.new("char[]", target_name), _backend.ffi.new("char[]", target_description), flags)
     if ret:
         raise WIMError(ret)
     self._wim_obj.images.refresh()
Exemplo n.º 16
0
    def iterate_lookup_table(self, flags, callback, context):
        @_backend.ffi.callback("int(const struct wimlib_resource_entry, void*)"
                               )
        def callback_wrapper(resource_entry, user_context):
            user_context = _backend.ffi.from_handle(user_context)
            # TODO: Cast resource_entry to a pythonic object instead of C struct.
            ret_val = callback(resource_entry, user_context)
            return ret_val if ret_val is not None else 0

        context = _backend.ffi.new_handle(context)
        ret = _backend.lib.wimlib_iterate_lookup_table(self._wim_struct, flags,
                                                       callback_wrapper,
                                                       context)
        if ret:
            raise WIMError(ret)
Exemplo n.º 17
0
    def iterate_dir_tree(self, path, flags, callback, context=None):
        """ Iterate over the files/directories in the image """
        @_backend.ffi.callback("int(struct wimlib_dir_entry*, void*)")
        def callback_wrapper(dir_entry, user_context):
            user_context = _backend.ffi.from_handle(user_context)
            py_dentry = DirEntry(dir_entry)
            # TODO: Cast dir_entry into a more pythonic object instead of C struct.
            ret_val = callback(py_dentry, user_context)
            return ret_val if ret_val is not None else 0

        context = _backend.ffi.new_handle(context)
        ret = _backend.lib.wimlib_iterate_dir_tree(self._wim_struct,
                                                   self.index, path, flags,
                                                   callback_wrapper, context)
        if ret:
            raise WIMError(ret)
Exemplo n.º 18
0
    def _unmount_with_progress(self, mount_dir, flags, callback, context=None):
        """ Like Image.unmount just with a progress function, For internal use only. """
        @_backend.ffi.callback(
            "enum wimlib_progress_status(enum wimlib_progress_msg, union wimlib_progress_info*, void*)"
        )
        def callback_wrapper(progress_msg, progress_info, user_context):
            user_context = _backend.ffi.from_handle(user_context)
            # TODO: Cast progress_info to a pythonic object instead of C union.
            ret_val = callback(progress_msg, progress_info, user_context)
            return ret_val if ret_val is not None else 0

        context = _backend.ffi.new_handle(context)
        ret = _backend.lib.wimlib_unmount_image_with_progress(
            mount_dir, flags, callback_wrapper, context)
        if ret:
            raise WIMError(ret)
Exemplo n.º 19
0
    def _open_with_progress(self, path, flags, callback, context):
        """ Like WIMFile.Open just with a progress function, For internal use only. """
        @_backend.ffi.callback(
            "enum wimlib_progress_status(enum wimlib_progress_msg, union wimlib_progress_info*, void*)"
        )
        def callback_wrapper(progress_msg, progress_info, user_context):
            user_context = _backend.ffi.from_handle(user_context)
            # TODO: Cast progress_info to a pythonic object instead of C union.
            ret_val = callback(progress_msg, progress_info, user_context)
            return ret_val if ret_val is not None else 0

        context = _backend.ffi.new_handle(context)
        wim_struct = _backend.ffi.new("WIMStruct **")
        ret = _backend.lib.wimlib_open_wim_with_progress(
            path, flags, wim_struct, callback_wrapper, context)
        if ret:
            raise WIMError(ret)
        return wim_struct[0]
Exemplo n.º 20
0
    def reference_template(self,
                           image,
                           template_image,
                           template_wim=None,
                           flags=0):
        """ Declare that a newly added image is mostly the same as a prior image. """
        if not template_wim and not isinstance(template_image, Image):
            raise ValueError(
                "Error: template_image must be instance of Image() if no template_wim defined."
            )

        if isinstance(template_image, Image):
            template_wim = template_image._wim_struct

        ret = _backend.lib.wimlib_reference_template_image(
            self._wim_struct, image, template_wim._wim_struct,
            int(template_image), flags)
        if ret:
            raise WIMError(ret)
Exemplo n.º 21
0
def set_default_compression_level(compression_type, level):
    ret = _backend.lib.wimlib_set_default_compression_level(
        compression_type, level)
    if ret:
        raise WIMError(ret)
Exemplo n.º 22
0
 def extract(self, target, flags):
     """ Extract the image to the specified directory or unmounted NTFS volume """
     ret = _backend.lib.wimlib_extract_image(self._wim_struct, self.index,
                                             target, flags)
     if ret:
         raise WIMError(ret)
Exemplo n.º 23
0
def global_init(init_flags=0):
    """ Initialization function for wimlib, called by default with flags=0"""
    ret = _backend.lib.wimlib_global_init(flags)
    if ret:
        raise WIMError(ret)
Exemplo n.º 24
0
 def _create_new(self, compression):
     wim_struct = _backend.ffi.new("WIMStruct **")
     ret = _backend.lib.wimlib_create_new_wim(compression, wim_struct)
     if ret:
         raise WIMError(ret)
     return wim_struct[0]
Exemplo n.º 25
0
 def _open(self, path, flags):
     wim_struct = _backend.ffi.new("WIMStruct **")
     ret = _backend.lib.wimlib_open_wim(path, flags, wim_struct)
     if ret:
         raise WIMError(ret)
     return wim_struct[0]
Exemplo n.º 26
0
 def delete_path(self, path, flags):
     """ Delete a path inside the image """
     ret = _backend.lib.wimlib_delete_path(self._wim_struct, self.index,
                                           path, flags)
     if ret:
         raise WIMError(ret)
Exemplo n.º 27
0
 def set_output_chunk_size(self, chunk_size):
     ret = _backend.lib.wimlib_set_output_chunk_size(
         self._wim_struct, chunk_size)
     if ret:
         raise WIMError(ret)
Exemplo n.º 28
0
 def set_output_compression_type(self, compression_type):
     ret = _backend.lib.wimlib_set_output_compression_type(
         self._wim_struct, compression_type)
     if ret:
         raise WIMError(ret)
Exemplo n.º 29
0
 def split(self, swm_name, part_size, flags):
     ret = _backend.lib.wimlib_split(self._wim_struct, swm_name, part_size,
                                     write_flags)
     if ret:
         raise WIMError(ret)
Exemplo n.º 30
0
 def verify(self, flags):
     ret = _backend.lib.wimlib_verify_wim(self._wim_struct, flags)
     if ret:
         raise WIMError(ret)