Skip to content

Commit 71526e2

Browse files
committed
[fix] : Re Fixed #245
1 parent 7a12b40 commit 71526e2

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tools/package.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313

1414
import sys
15-
from argparse import SUPPRESS, ArgumentParser, RawTextHelpFormatter
15+
from argparse import ArgumentParser, RawTextHelpFormatter, SUPPRESS
1616
from os.path import abspath, dirname
1717
from pathlib import Path
1818
from subprocess import run
@@ -30,7 +30,7 @@
3030

3131

3232
try:
33-
from pyalpm import Package
33+
from pyalpm import find_satisfier, Package
3434
from pycman.config import init_with_config
3535
except:
3636
pyalpm_error = True
@@ -41,18 +41,29 @@ def msg(string: str, level: str) -> None:
4141
run([f"{script_dir}/msg.sh", "-a", "package.py", level, string])
4242

4343

44+
def get_from_localdb(package: str) -> Optional[Package]:
45+
localdb = handle.get_localdb()
46+
pkg = localdb.get_pkg(package)
47+
48+
if pkg:
49+
return pkg
50+
else:
51+
for pkg in localdb.search(package):
52+
if package in pkg.provides:
53+
return pkg
54+
55+
4456
def get_from_syncdb(package: str) -> Optional[Package]:
4557
for db in handle.get_syncdbs():
4658
pkg = db.get_pkg(package)
4759

48-
if pkg: break
49-
50-
return pkg
60+
if pkg:
61+
return pkg
5162

5263

5364
def compare(package: str) -> tuple[int,Optional[tuple[str]]]:
54-
pkg_from_local = handle.get_localdb().get_pkg(package)
55-
pkg_from_sync = get_from_syncdb(package)
65+
pkg_from_local = get_from_localdb(package)
66+
pkg_from_sync = get_from_syncdb(pkg_from_local.name) if pkg_from_local else None
5667

5768
if not pkg_from_local:
5869
msg(f"{package} is not installed.", "error")

0 commit comments

Comments
 (0)