Skip to content

Commit 3736833

Browse files
committed
2024-09 update
1 parent 1b81e4a commit 3736833

File tree

3 files changed

+66
-26
lines changed

3 files changed

+66
-26
lines changed

src/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from gen_index import gen_index
1+
# from gen_index import gen_index
2+
from gen_whl import gen_html
23
from col_whl import get_all_repo_data
3-
from tools import get_saved_hash, get_assets, trim_hash_dict
4-
from gen_whl import gen_html, get_local_whl, extend_hash_dict, save_hash
4+
from tools import get_saved_hash, get_assets, update_hash_dict, get_local_whl, save_hash
55

66

77
if __name__ == '__main__':
@@ -11,10 +11,10 @@
1111
wheels = get_assets(hash_dict)
1212

1313
local_whl = get_local_whl()
14-
hash_dict = extend_hash_dict(hash_dict, local_whl)
15-
16-
hash_dict = trim_hash_dict(wheels, hash_dict)
14+
hash_dict = update_hash_dict(saved_hash=hash_dict, whl_files=local_whl, upl_whl=wheels)
1715
save_hash(hash_dict)
1816

1917
gen_html(hash_dict)
2018
# gen_index(wheels)
19+
20+
# don't forget to run check_hash.py

src/tools.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,32 @@ def get_local_whl() -> list[tuple[str, str]]:
9999
return whl_files
100100

101101

102-
def extend_hash_dict(saved_hash: dict, whl_files: list[tuple[str, str]]) -> dict:
103-
saved_wheels = saved_hash.keys()
104-
assert not any(name in saved_wheels for name, _ in whl_files), r'E:\Cache\whl is not empty!'
102+
def update_hash_dict(saved_hash: dict[str, dict], whl_files: list[tuple[str, str]], upl_whl: list[dict[str, str]]) -> dict:
103+
# saved_wheels = saved_hash.keys()
104+
# assert not any(name in saved_wheels for name, _ in whl_files), r'E:\Cache\whl is not empty!'
105105

106-
print('Calculating hash for local wheels...')
107-
for name, path in tqdm(whl_files):
108-
saved_hash[name] = {
109-
'sha256': calculate_hash(path),
110-
'verify': False
106+
new_saved_hash = {}
107+
for item in upl_whl:
108+
name = item['name']
109+
new_saved_hash[name] = {
110+
'sha256': saved_hash.get(name, {}).get('sha256', ''),
111+
'verify': saved_hash.get(name, {}).get('verify', False)
111112
}
112-
return saved_hash
113-
114113

115-
def trim_hash_dict(pkgs: list[dict], saved_hash: dict) -> dict:
116-
"""
117-
Remove entries in saved_hash that are not in pkgs
118-
"""
119-
new_saved_hash = {}
120-
for pkg in pkgs:
121-
# if pkg['name'] in saved_hash:
122-
# assert
123-
new_saved_hash[pkg['name']] = saved_hash[pkg['name']]
114+
print('Calculating hash for local wheels...')
115+
for name, path in whl_files:
116+
if name in new_saved_hash:
117+
new_saved_hash[name]['sha256'] = calculate_hash(path)
118+
new_saved_hash[name]['verify'] = False
124119

125120
return new_saved_hash
121+
122+
123+
def remove_local_dup():
124+
saved_hash = get_saved_hash()
125+
local_whl = get_local_whl()
126+
127+
for name, path in local_whl:
128+
if name in saved_hash:
129+
input(f'{name} already exists, remove?')
130+
os.remove(path)

0 commit comments

Comments
 (0)