Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logging of apt update in case of failure #107

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mobros/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ class Commands(Enum):

MOBROS_CONFIG_PATH = "/etc/mobros/config"
MOBROS_CONFIG_SECTION = "conflict-solving"
MOBROS_CONFIG_BLACKLIST_KEY = "blacklistSource"
MOBROS_CONFIG_BLACKLIST_KEY = "blacklistSource"
7 changes: 6 additions & 1 deletion mobros/types/apt_cache_singleton.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Module defining the apt cache singleton not to be constantly requesting apt for his cache"""
import os
import apt

import mobros.utils.logger as logging
from mobros.exceptions import AptCacheInitializationException
from mobros.utils.utilitary import execute_shell_command


# pylint: disable=R0903,W0107
class AptCache:
"""Apt cache singleton"""
Expand All @@ -31,7 +33,10 @@ def __new__(cls):
message = "Unable to fetch apt cache. Please check your internet connection! Try running 'sudo apt update' for more info."
logging.error(message)

execute_shell_command("sudo apt update", log_output=True)
apt_cmd = ["apt", "update"]
if os.geteuid() != 0:
apt_cmd = ["sudo"] + apt_cmd
execute_shell_command(apt_cmd, log_output=True)
raise AptCacheInitializationException(message) from fetched_failed_exception

cls._installed_cache = []
Expand Down
11 changes: 10 additions & 1 deletion tests/test_utils/test_utilitary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from os import remove
from os import remove, geteuid
from os.path import dirname, exists, realpath

import mock
Expand Down Expand Up @@ -47,6 +47,15 @@ def test_execute_bash_fail_file_not_found(self):
except Exception:
pass

def test_execute_apt_update(self):


apt_cmd = ["apt", "update"]
if geteuid() != 0:
apt_cmd = ["sudo"] + apt_cmd
execute_shell_command(apt_cmd, log_output=True)


def test_is_blacklisted_origin(self):

GlobalData().set_conflict_solving_blacklist(["*.mov.ai/repository/ppa-testing","*.mov.ai/repository/ppa-main"])
Expand Down