Gentoo Archives: gentoo-commits

From: Matt Turner <mattst88@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/
Date: Thu, 10 Jun 2021 00:48:47
Message-Id: 1613856449.4fd2ac23250ab2ac1f6a506ee433f466a4f9e026.mattst88@gentoo
1 commit: 4fd2ac23250ab2ac1f6a506ee433f466a4f9e026
2 Author: Felix Bier <Felix.Bier <AT> rohde-schwarz <DOT> com>
3 AuthorDate: Sat Feb 13 23:18:17 2021 +0000
4 Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
5 CommitDate: Sat Feb 20 21:27:29 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=4fd2ac23
7
8 Enable recursive globbing for clear_path
9
10 This commit enables recursive globbing in clear_path, allowing the
11 usage of '**' to match an arbitrary number of sub-directories.
12
13 Before this commit, clear_path used only non-recursive globbing. This
14 allowed to use '*' to expand names within one directory, e.g. '/a/*/c'
15 can expand to '/a/b/c', but not '/a/b/b/c'. With this commit, '/a/**/c'
16 can be used to expand to '/a/b/c', '/a/b/b/c', '/a/b/b/b/c' etc.
17
18 This is motivated by wanting to recursively delete all occurences of a
19 filename with the 'stage4/rm' entry of a spec file. The '/rm' entries
20 are processed with 'clear_path' in the existing code.
21
22 Additionally, 'glob.glob' is replaced with 'glob.iglob',
23 which returns the same files as 'glob.glob', but as an iterator
24 instead of as a list (so it no longer necessary to hold
25 all matches in memory at once).
26
27 Recursive globbing has been added in Python 3.5.
28
29 References:
30 https://docs.python.org/3/library/glob.html#glob.glob
31 https://docs.python.org/3/library/glob.html#glob.iglob
32
33 Signed-off-by: Felix Bier <felix.bier <AT> rohde-schwarz.com>
34 Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
35
36 catalyst/fileops.py | 2 +-
37 1 file changed, 1 insertion(+), 1 deletion(-)
38
39 diff --git a/catalyst/fileops.py b/catalyst/fileops.py
40 index 5c6f5cd8..59525420 100644
41 --- a/catalyst/fileops.py
42 +++ b/catalyst/fileops.py
43 @@ -99,7 +99,7 @@ def clear_dir(target, mode=0o755, remove=False,
44
45 def clear_path(target_path):
46 """Nuke |target_path| regardless of it being a dir, file or glob."""
47 - targets = glob.glob(target_path)
48 + targets = glob.iglob(target_path, recursive=True)
49 for path in targets:
50 clear_dir(path, remove=True)