Skip to content

Commit

Permalink
2024-09 update
Browse files Browse the repository at this point in the history
  • Loading branch information
KumaTea committed Sep 21, 2024
1 parent 1b81e4a commit 3736833
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from gen_index import gen_index
# from gen_index import gen_index
from gen_whl import gen_html
from col_whl import get_all_repo_data
from tools import get_saved_hash, get_assets, trim_hash_dict
from gen_whl import gen_html, get_local_whl, extend_hash_dict, save_hash
from tools import get_saved_hash, get_assets, update_hash_dict, get_local_whl, save_hash


if __name__ == '__main__':
Expand All @@ -11,10 +11,10 @@
wheels = get_assets(hash_dict)

local_whl = get_local_whl()
hash_dict = extend_hash_dict(hash_dict, local_whl)

hash_dict = trim_hash_dict(wheels, hash_dict)
hash_dict = update_hash_dict(saved_hash=hash_dict, whl_files=local_whl, upl_whl=wheels)
save_hash(hash_dict)

gen_html(hash_dict)
# gen_index(wheels)

# don't forget to run check_hash.py
43 changes: 24 additions & 19 deletions src/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,32 @@ def get_local_whl() -> list[tuple[str, str]]:
return whl_files


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

print('Calculating hash for local wheels...')
for name, path in tqdm(whl_files):
saved_hash[name] = {
'sha256': calculate_hash(path),
'verify': False
new_saved_hash = {}
for item in upl_whl:
name = item['name']
new_saved_hash[name] = {
'sha256': saved_hash.get(name, {}).get('sha256', ''),
'verify': saved_hash.get(name, {}).get('verify', False)
}
return saved_hash


def trim_hash_dict(pkgs: list[dict], saved_hash: dict) -> dict:
"""
Remove entries in saved_hash that are not in pkgs
"""
new_saved_hash = {}
for pkg in pkgs:
# if pkg['name'] in saved_hash:
# assert
new_saved_hash[pkg['name']] = saved_hash[pkg['name']]
print('Calculating hash for local wheels...')
for name, path in whl_files:
if name in new_saved_hash:
new_saved_hash[name]['sha256'] = calculate_hash(path)
new_saved_hash[name]['verify'] = False

return new_saved_hash


def remove_local_dup():
saved_hash = get_saved_hash()
local_whl = get_local_whl()

for name, path in local_whl:
if name in saved_hash:
input(f'{name} already exists, remove?')
os.remove(path)
Loading

0 comments on commit 3736833

Please sign in to comment.