Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Nov 25, 2024
1 parent 2a99145 commit 31a07c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def run_updates(system: bool, system_update_available: bool, dry_run: bool):

if out.returncode != 0:
log.error(f"topgrade returned code {out.returncode}, program output:")
log.error(out.stdout.decode("utf-8"))
log.error(out.stderr.decode("utf-8"))
os._exit(out.returncode)

"""Users"""
Expand Down
19 changes: 9 additions & 10 deletions src/ublue_update/update_drivers/brew.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
BREW_PREFIX = "/home/linuxbrew/.linuxbrew"
BREW_CELLAR = f"{BREW_PREFIX}/Cellar"
BREW_REPO = f"{BREW_PREFIX}/Homebrew"
BREW_PATH: str = f"{BREW_PREFIX}/bin/brew"



def detect_user() -> int:
Expand All @@ -20,29 +22,26 @@ def brew_update(dry_run: bool):
if uid == -1 or dry_run:
return
log.info(f"running brew updates for uid: {uid}")
env_path: str = os.environ["PATH"]
path: str = f"{env_path}:{BREW_PREFIX}/bin:{BREW_PREFIX}/sbin"
args: list[str] = [
f"--E=HOMEBREW_PREFIX='{BREW_PREFIX}'",
f"--E=HOMEBREW_CELLAR='{BREW_CELLAR}'",
f"--E=HOMEBREW_REPOSITORY='{BREW_REPO}'",
f"--E=PATH='{path}'",
f"--setenv=HOMEBREW_PREFIX='{BREW_PREFIX}'",
f"--setenv=HOMEBREW_CELLAR='{BREW_CELLAR}'",
f"--setenv=HOMEBREW_REPOSITORY='{BREW_REPO}'",
]

out = run_uid(uid, args + ["brew", "update"])
out = run_uid(uid, args + [f"{BREW_PATH}", "update"])
if out.returncode != 0:
log.error(
f"brew update failed, returned code {out.returncode}, program output:"
)
log.error(out.stdout.decode("utf-8"))
log.error(out.stderr.decode("utf-8"))
return

out = run_uid(uid, args + ["brew", "upgrade"])
out = run_uid(uid, args + [f"{BREW_PATH}", "upgrade"])
if out.returncode != 0:
log.error(
f"brew upgrade failed, returned code {out.returncode}, program output:"
)
log.error(out.stdout.decode("utf-8"))
log.error(out.stderr.decode("utf-8"))
return

log.info("brew updates completed")
13 changes: 7 additions & 6 deletions tests/unit/test_brew.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)

from ublue_update.update_drivers.brew import (
BREW_PATH,
detect_user,
brew_update,
BREW_PREFIX,
Expand Down Expand Up @@ -55,14 +56,14 @@ def test_brew_update(mock_log, mock_stat, mock_isdir, mock_run_uid):

brew_update(False)
env = [
f"--E=HOMEBREW_PREFIX='{BREW_PREFIX}'",
f"--E=HOMEBREW_CELLAR='{BREW_CELLAR}'",
f"--E=HOMEBREW_REPOSITORY='{BREW_REPO}'",
f"--E=PATH='/usr/bin:{BREW_PREFIX}/bin:{BREW_PREFIX}/sbin'",
f"--setenv=HOMEBREW_PREFIX='{BREW_PREFIX}'",
f"--setenv=HOMEBREW_CELLAR='{BREW_CELLAR}'",
f"--setenv=HOMEBREW_REPOSITORY='{BREW_REPO}'",
f"--setenv=PATH='/usr/bin:{BREW_PREFIX}/bin:{BREW_PREFIX}/sbin'",
]

mock_run_uid.assert_any_call(1001, env + ["brew", "update"])
mock_run_uid.assert_any_call(1001, env + ["brew", "upgrade"])
mock_run_uid.assert_any_call(1001, env + [f"{BREW_PATH}", "update"])
mock_run_uid.assert_any_call(1001, env + [f"{BREW_PATH}", "upgrade"])


@patch("ublue_update.update_drivers.brew.run_uid")
Expand Down

0 comments on commit 31a07c4

Please sign in to comment.