Skip to content

Commit 12655d7

Browse files
committed
refact: using scandir instead of glob in catalog too; adding quite mode to supress progress bar
1 parent 1760823 commit 12655d7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

spacesavers2_catalog

+13-5
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ def main():
131131
action=argparse.BooleanOptionalAction,
132132
help="output per-user geezer files list.",
133133
)
134+
parser.add_argument(
135+
"-q",
136+
"--quite",
137+
dest="quite",
138+
required=False,
139+
action=argparse.BooleanOptionalAction,
140+
help="Do not show progress",
141+
)
134142
parser.add_argument(
135143
"-a",
136144
"--geezerage",
@@ -154,16 +162,16 @@ def main():
154162
global args
155163
args = parser.parse_args()
156164

165+
tqdm_disable = False
166+
if args.quite: tqdm_disable = True
167+
157168
global sed
158169
sed = dict()
159170
for s in args.se.split(","):
160171
sed[s] = 1
161172

162173
folder = args.folder
163-
p = Path(folder)
164-
files = [p]
165-
files2 = p.glob("**/*")
166-
files.extend(files2)
174+
p = Path(folder).absolute()
167175

168176
broken_links = dict()
169177
geezers = dict()
@@ -174,7 +182,7 @@ def main():
174182
outfh = sys.stdout
175183

176184
with Pool(processes=args.threads) as pool:
177-
for fd in tqdm.tqdm(pool.imap_unordered(task, files),total=len(files)):
185+
for fd in tqdm.tqdm(pool.imap_unordered(task, scantree(p)),disable=tqdm_disable):
178186
uid = fd.get_userid()
179187
if fd.get_type() == "L": # broken link
180188
if not uid in broken_links: broken_links[uid] = list()

src/utils.py

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
import sys
66
import time
77

8+
def scantree(path):
9+
# requires global dirs
10+
"""Recursively yield DirEntry objects for given directory."""
11+
for entry in os.scandir(path):
12+
try:
13+
if entry.is_dir(follow_symlinks=False):
14+
dirs.append(entry.path)
15+
yield from scantree(entry.path)
16+
else:
17+
yield entry.path
18+
except:
19+
return
820

921
def which(program):
1022
def is_exe(fpath):

0 commit comments

Comments
 (0)