Skip to content

Commit

Permalink
refactor: no need to condition on app
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlaltf24 authored and thw26 committed Oct 24, 2024
1 parent 5078b2a commit 2baff88
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions ou_dedetai/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,43 +420,42 @@ def query_packages(packages, mode="install", app=None):
logging.debug(f"packages to check: {packages}")
status = {package: "Unchecked" for package in packages}

if app is not None:
for p in packages:
logging.debug(f"Checking for: {p}")
l_num = 0
for line in package_list.split('\n'):
# logging.debug(f"{line=}")
l_num += 1
if config.PACKAGE_MANAGER_COMMAND_QUERY[0] == 'dpkg':
parts = line.strip().split()
if l_num < 6 or len(parts) < 2: # skip header, etc.
continue
state = parts[0]
pkg = parts[1].split(':')[0] # remove :arch if present
if pkg == p and state[1] == 'i':
if mode == 'install':
status[p] = "Installed"
elif mode == 'remove':
conflicting_packages.append(p)
status[p] = 'Conflicting'
break
else:
if line.strip().startswith(f"{config.QUERY_PREFIX}{p}") and mode == "install": # noqa: E501
logging.debug(f"'{p}' installed: {line}")
for p in packages:
logging.debug(f"Checking for: {p}")
l_num = 0
for line in package_list.split('\n'):
# logging.debug(f"{line=}")
l_num += 1
if config.PACKAGE_MANAGER_COMMAND_QUERY[0] == 'dpkg':
parts = line.strip().split()
if l_num < 6 or len(parts) < 2: # skip header, etc.
continue
state = parts[0]
pkg = parts[1].split(':')[0] # remove :arch if present
if pkg == p and state[1] == 'i':
if mode == 'install':
status[p] = "Installed"
break
elif line.strip().startswith(p) and mode == "remove":
elif mode == 'remove':
conflicting_packages.append(p)
status[p] = "Conflicting"
break

if status[p] == "Unchecked":
if mode == "install":
missing_packages.append(p)
status[p] = "Missing"
elif mode == "remove":
status[p] = "Not Installed"
logging.debug(f"{p} status: {status.get(p)}")
status[p] = 'Conflicting'
break
else:
if line.strip().startswith(f"{config.QUERY_PREFIX}{p}") and mode == "install": # noqa: E501
logging.debug(f"'{p}' installed: {line}")
status[p] = "Installed"
break
elif line.strip().startswith(p) and mode == "remove":
conflicting_packages.append(p)
status[p] = "Conflicting"
break

if status[p] == "Unchecked":
if mode == "install":
missing_packages.append(p)
status[p] = "Missing"
elif mode == "remove":
status[p] = "Not Installed"
logging.debug(f"{p} status: {status.get(p)}")

logging.debug(f"Packages status: {status}")

Expand Down

0 comments on commit 2baff88

Please sign in to comment.