Skip to content

Commit

Permalink
refactor(meta_helpers: find_aur_pkgs_with_double_requirements): extra…
Browse files Browse the repository at this point in the history
…ct common function
  • Loading branch information
actionless committed Jul 10, 2024
1 parent de950a0 commit 01dd5d5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
25 changes: 3 additions & 22 deletions pikaur_meta_helpers/find_aur_pkgs_with_double_requirements.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
import math
import os
import pickle # nosec B403
from multiprocessing.pool import ThreadPool
from pathlib import Path
from typing import Final, TypedDict
from typing import TypedDict

import tqdm # type: ignore[import-untyped]

from pikaur.aur import AURPackageInfo, get_all_aur_packages
from pikaur.aur import AURPackageInfo
from pikaur.version import VersionMatcher
from pikaur_meta_helpers.util import load_aur_dump


class Item(TypedDict):
deps: list[VersionMatcher]
counter: int


PICKLE_FILE: Final = Path("aur_db.dump")


def load_aur_dump() -> list[AURPackageInfo]:
aur_pkgs: list[AURPackageInfo]
if PICKLE_FILE.exists():
print(f"Opening db dump '{PICKLE_FILE}'...")
with PICKLE_FILE.open("rb") as fobj_read:
aur_pkgs = pickle.load(fobj_read) # nosec B301
else:
print("Fetching...")
aur_pkgs = get_all_aur_packages()
print(f"Saving db dump to '{PICKLE_FILE}'...")
with PICKLE_FILE.open("wb") as fobj_write:
pickle.dump(aur_pkgs, fobj_write)
return aur_pkgs


def filter_thread(
idx: int, aur_pkgs: list[AURPackageInfo], all_aur_pkgnames: dict[str, bool],
) -> dict[str, Item]:
Expand Down
22 changes: 22 additions & 0 deletions pikaur_meta_helpers/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pickle # nosec B403
from pathlib import Path
from typing import Final

from pikaur.aur import AURPackageInfo, get_all_aur_packages

PICKLE_FILE: Final = Path("aur_db.dump")


def load_aur_dump() -> list[AURPackageInfo]:
aur_pkgs: list[AURPackageInfo]
if PICKLE_FILE.exists():
print(f"Opening db dump '{PICKLE_FILE}'...")
with PICKLE_FILE.open("rb") as fobj_read:
aur_pkgs = pickle.load(fobj_read) # nosec B301
else:
print("Fetching...")
aur_pkgs = get_all_aur_packages()
print(f"Saving db dump to '{PICKLE_FILE}'...")
with PICKLE_FILE.open("wb") as fobj_write:
pickle.dump(aur_pkgs, fobj_write)
return aur_pkgs

0 comments on commit 01dd5d5

Please sign in to comment.