Skip to content

Commit eaf8c89

Browse files
committed
put limiter in more appropriate places
1 parent 7af5940 commit eaf8c89

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

machine/mirror/wort-mirror.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ async def main(args):
3333
limiter = asyncio.Semaphore(args.max_downloaders)
3434

3535
already_mirrored_locations = set()
36-
async with limiter:
37-
for root, dirs, files in args.basedir.walk(top_down=True):
38-
for name in files:
39-
already_mirrored_locations.add(
40-
str(root.relative_to(args.basedir) / name)
41-
)
36+
for root, dirs, files in args.basedir.walk(top_down=True):
37+
for name in files:
38+
already_mirrored_locations.add(str(root.relative_to(args.basedir) / name))
4239
print(len(already_mirrored_locations))
4340

4441
if args.full_check:
@@ -47,14 +44,15 @@ async def main(args):
4744
sha256_sums = []
4845

4946
for location in already_mirrored_locations:
50-
async with aiofiles.open(args.basedir / location, mode="rb") as f:
51-
h = hashlib.new("sha256")
52-
while (chnk := await f.read(1024 * 1024)) != b"":
53-
h.update(chnk)
54-
sha256 = h.hexdigest()
55-
56-
internal_locations.append(location)
57-
sha256_sums.append(sha256)
47+
async with limiter:
48+
async with aiofiles.open(args.basedir / location, mode="rb") as f:
49+
h = hashlib.new("sha256")
50+
while (chnk := await f.read(1024 * 1024)) != b"":
51+
h.update(chnk)
52+
sha256 = h.hexdigest()
53+
54+
internal_locations.append(location)
55+
sha256_sums.append(sha256)
5856
else:
5957
internal_locations = list(already_mirrored_locations)
6058

@@ -76,7 +74,8 @@ async def main(args):
7674

7775
print(to_mirror_df.collect())
7876

79-
(args.basedir / "sigs").mkdir(parents=True, exist_ok=True)
77+
if not args.dry_run:
78+
(args.basedir / "sigs").mkdir(parents=True, exist_ok=True)
8079

8180
async with httpx.AsyncClient(
8281
timeout=30.0,
@@ -187,7 +186,7 @@ async def download_sig(location, sha256, basedir, client, limiter, dry_run):
187186
"--since",
188187
default=datetime.datetime.strptime("1900-01-01", "%Y-%m-%d"),
189188
type=lambda s: datetime.datetime.strptime(s, "%Y-%m-%d"),
190-
help="Only mirror signatures added since this date",
189+
help="Only mirror signatures added since this date. Default: 1900-01-01",
191190
)
192191
parser.add_argument(
193192
"database",

0 commit comments

Comments
 (0)