Skip to content

Commit 32c15c0

Browse files
committed
fix: failing to downlaod if cache dir does not yet exist
1 parent 05ce9d7 commit 32c15c0

File tree

5 files changed

+49
-83
lines changed

5 files changed

+49
-83
lines changed

.idea/cody_history.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 25 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/_man_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def path_ensure_remove(cls, path: str):
6868
@classmethod
6969
def path_ensure_exists(cls, path: str):
7070
""" ensure that dir/file with 'path' exists, creating (parents recursively) if necessary """
71-
71+
print(f"start ... os.makedirs....{path}")
7272
os.makedirs(path, exist_ok=True)
73+
print(f"finish ... os.makedirs....{path}")
7374

7475
# ---------------------------------------------------------
7576
@classmethod

src/_man_web.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ def full_path(cls, rel_path: str, base_path: str = None) -> str:
5151
def download(cls, url: str, dir_path: str, want_lazy_download=None) -> str:
5252
""" download from url to local dir_path """
5353

54+
if url.endswith('/'):
55+
# Assume we want to save it as index.html in the specified directory
56+
file_name = "index.html"
57+
else:
58+
# Otherwise, use the basename of the URL as the filename
59+
file_name = os.path.basename(url)
60+
5461
# save the output to this file
55-
file_path = os.path.join(dir_path, os.path.basename(url))
62+
file_path = os.path.join(dir_path, file_name)
5663

5764
# eg for url: http://ftp.uk.debian.org/debian/dists/stable/main/
5865
# save url pointing to director as "index.html" file
5966
is_dir = os.path.isdir(file_path)
67+
print(f"is_dir = {is_dir}")
6068
if is_dir:
6169
file_path = os.path.join(file_path, "index.html")
6270

@@ -66,8 +74,9 @@ def download(cls, url: str, dir_path: str, want_lazy_download=None) -> str:
6674
print(f"already downloaded {url} ... reusing cached copy at {file_path}")
6775
return file_path
6876

69-
print(f"downloading {url} ...")
70-
77+
print(f"downloading {url} ... to {dir_path}")
78+
print(f"dir_path: {dir_path}")
79+
print(f"file_path: {file_path}")
7180
# ensure local destination dir exists
7281
ManFile.path_ensure_exists(dir_path)
7382

src/main.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,6 @@
33
import sys
44
from ._man_app import ManApp
55

6-
def async_test():
7-
import asyncio
8-
import time
9-
10-
async def say_after(delay, what):
11-
await asyncio.sleep(delay)
12-
print(what)
13-
14-
async def main():
15-
print(f"started at {time.strftime('%X')}")
16-
17-
#await say_after(2, 'world')
18-
#await say_after(1, 'hello')
19-
20-
await asyncio.gather(say_after(4, 'world'), say_after(1, 'hello'))
21-
22-
23-
print(f"finished at {time.strftime('%X')}")
24-
25-
asyncio.run(main())
26-
276
# ---------------------------------------
287
def main():
298
""" delegates most work to the application manager, ManApp,
@@ -40,21 +19,6 @@ def main():
4019
print(txt)
4120
print("")
4221

43-
# ---------------------------------------
44-
def test():
45-
class A:
46-
pass
47-
48-
49-
a = A();
50-
b1 = bool(a)
51-
52-
a = None
53-
b2 = bool(a)
54-
halt =1
55-
5622
# ---------------------------------------
5723
if __name__ == "__main__":
58-
# test()
5924
main()
60-
# async_test()

0 commit comments

Comments
 (0)