[rhinstaller/lorax/pulls/4 master] Add removekmod template command
vpodzime
installerbot-noreply at redhat.com
Thu Mar 5 16:28:33 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)
> +
> + # Remove anything matching keepglobs from the list
> + matches = set()
> + for g in keepglobs:
> + globs_re = re.compile(fnmatch.translate("*"+g+"*"))
> + m = filter(globs_re.match, filelist)
> + if m:
> + matches.update(m)
> + else:
> + logger.debug("removekmod %s: no files matched!", g)
> + remove_files = filelist.difference(matches)
> + else:
> + # Gather glob matches, the full list isn't needed since it will recursively remove
> + # directory matches.
> + keepglobs = []
> + filelist = set()
> + for g in globs:
> + filelist.update(rglob(self._out("/lib/modules/*/kernel/"+g)))
> + remove_files = filelist
I'm leaving it up to you then to chose an approach that better fits your way of thinking. :)
--
To view this pull request on github, visit https://github.com/rhinstaller/lorax/pull/4#discussion_r25877061
More information about the anaconda-patches
mailing list