[rhinstaller/lorax/pulls/4 master] Add removekmod template command

vpodzime installerbot-noreply at redhat.com
Thu Mar 5 16:29:51 UTC 2015


> @@ -597,12 +597,75 @@ def removefrom(self, pkg, *globs):
>              remove_files = matches
>          # remove the files
>          if remove_files:
> -            logger.debug("%s: removed %i/%i files, %ikb/%ikb", cmd,
> +            logger.debug("removefrom %s: removed %i/%i files, %ikb/%ikb", cmd,
>                               len(remove_files), len(filelist),
>                               self._getsize(*remove_files)/1024, self._getsize(*filelist)/1024)
>              self.remove(*remove_files)
>          else:
> -            logger.debug("%s: no files to remove!", cmd)
> +            logger.debug("removefrom %s: no files to remove!", cmd)
> +
> +    def removekmod(self, *globs):
> +        '''
> +        removekmod GLOB [GLOB...] [--allbut] KEEPGLOB [KEEPGLOB...]
> +          Remove all files and directories matching the given file globs from the kernel
> +          modules directory.
> +
> +          If '--allbut' is used, all the files from the modules will be removed *except*
> +          the ones which match the file globs. There must be at least one initial GLOB
> +          to search and one KEEPGLOB to keep. The KEEPGLOB is expanded to be *KEEPGLOB*
> +          so that it will match anywhere in the path.
> +
> +          This only removes files from under /lib/modules/*/kernel/
> +
> +          Examples:
> +            removekmod sound drivers/media drivers/hwmon drivers/video
> +            removekmod drivers/char --allbut virtio_console hw_random
> +        '''
> +        cmd = " ".join(globs)
> +        if "--allbut" in globs:
> +            idx = globs.index("--allbut")
> +            if idx == 0:
> +                raise ValueError("removekmod needs at least one GLOB before --allbut")
> +
> +            # Apply keepglobs anywhere they appear in the path
> +            keepglobs = globs[idx+1:]
> +            if len(keepglobs) == 0:
> +                raise ValueError("removekmod needs at least one GLOB after --allbut")
> +
> +            globs = globs[:idx]
> +
> +            # --allbut needs the full list of files to match keepglobs against, gather up every
> +            # file under each glob pattern's results.
> +            filelist = set()
> +            for g in globs:
> +                for top_dir in rglob(self._out("/lib/modules/*/kernel/"+g)):
> +                    for root, _dirs, files in os.walk(top_dir):
> +                        filelist.update(root+"/"+f for f in files)

Hmm, seems like GitHub squashed my glob! I meant appending ``**/*``, but that won't work neither so just ignore this suggestion.

-- 
To view this pull request on github, visit https://github.com/rhinstaller/lorax/pull/4#discussion_r25877217


More information about the anaconda-patches mailing list