* [gentoo-catalyst] [PATCH] Enable recursive globbing for clear_path
@ 2021-02-13 23:18 Felix Bier
2021-02-21 1:59 ` Matt Turner
0 siblings, 1 reply; 2+ messages in thread
From: Felix Bier @ 2021-02-13 23:18 UTC (permalink / raw
To: gentoo-catalyst@lists.gentoo.org
This commit enables recursive globbing in clear_path, allowing the
usage of '**' to match an arbitrary number of sub-directories.
Before this commit, clear_path used only non-recursive globbing. This
allowed to use '*' to expand names within one directory, e.g. '/a/*/c'
can expand to '/a/b/c', but not '/a/b/b/c'. With this commit, '/a/**/c'
can be used to expand to '/a/b/c', '/a/b/b/c', '/a/b/b/b/c' etc.
This is motivated by wanting to recursively delete all occurences of a
filename with the 'stage4/rm' entry of a spec file. The '/rm' entries
are processed with 'clear_path' in the existing code.
Additionally, 'glob.glob' is replaced with 'glob.iglob',
which returns the same files as 'glob.glob', but as an iterator
instead of as a list (so it no longer necessary to hold
all matches in memory at once).
Recursive globbing has been added in Python 3.5.
References:
https://docs.python.org/3/library/glob.html#glob.glob
https://docs.python.org/3/library/glob.html#glob.iglob
---
catalyst/fileops.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index 5c6f5cd8..59525420 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -99,7 +99,7 @@ def clear_dir(target, mode=0o755, remove=False,
def clear_path(target_path):
"""Nuke |target_path| regardless of it being a dir, file or glob."""
- targets = glob.glob(target_path)
+ targets = glob.iglob(target_path, recursive=True)
for path in targets:
clear_dir(path, remove=True)
--
2.30.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [gentoo-catalyst] [PATCH] Enable recursive globbing for clear_path
2021-02-13 23:18 [gentoo-catalyst] [PATCH] Enable recursive globbing for clear_path Felix Bier
@ 2021-02-21 1:59 ` Matt Turner
0 siblings, 0 replies; 2+ messages in thread
From: Matt Turner @ 2021-02-21 1:59 UTC (permalink / raw
To: gentoo-catalyst
On Sat, Feb 13, 2021 at 6:18 PM Felix Bier <Felix.Bier@rohde-schwarz.com> wrote:
>
> This commit enables recursive globbing in clear_path, allowing the
> usage of '**' to match an arbitrary number of sub-directories.
>
> Before this commit, clear_path used only non-recursive globbing. This
> allowed to use '*' to expand names within one directory, e.g. '/a/*/c'
> can expand to '/a/b/c', but not '/a/b/b/c'. With this commit, '/a/**/c'
> can be used to expand to '/a/b/c', '/a/b/b/c', '/a/b/b/b/c' etc.
>
> This is motivated by wanting to recursively delete all occurences of a
> filename with the 'stage4/rm' entry of a spec file. The '/rm' entries
> are processed with 'clear_path' in the existing code.
>
> Additionally, 'glob.glob' is replaced with 'glob.iglob',
> which returns the same files as 'glob.glob', but as an iterator
> instead of as a list (so it no longer necessary to hold
> all matches in memory at once).
>
> Recursive globbing has been added in Python 3.5.
>
> References:
> https://docs.python.org/3/library/glob.html#glob.glob
> https://docs.python.org/3/library/glob.html#glob.iglob
Nice, thank you. Committed!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-21 1:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-13 23:18 [gentoo-catalyst] [PATCH] Enable recursive globbing for clear_path Felix Bier
2021-02-21 1:59 ` Matt Turner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox