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

chore: remove progress bar as it brings so many problems with it #42

Merged
merged 6 commits into from
Dec 21, 2024
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
20 changes: 16 additions & 4 deletions cmd/imageOutdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ import (
"log/slog"

"github.com/spf13/cobra"
"github.com/ublue-os/uupd/drv"
"github.com/ublue-os/uupd/drv/generic"
"github.com/ublue-os/uupd/drv/system"
)

func ImageOutdated(cmd *cobra.Command, args []string) {
systemUpdater, err := drv.SystemUpdater{}.New(drv.UpdaterInitConfiguration{})
initConfiguration := generic.UpdaterInitConfiguration{}.New()
initConfiguration.Ci = false
initConfiguration.DryRun = false
initConfiguration.Verbose = false

mainSystemDriver, _, _, err := system.InitializeSystemDriver(*initConfiguration)
if err != nil {
slog.Error("Failed getting system driver", slog.Any("error", err))
slog.Error("Failed")
return
}

println(systemUpdater.Outdated)
systemOutdated, err := mainSystemDriver.Outdated()

if err != nil {
slog.Error("Failed checking if system is out of date")
}

println(systemOutdated)
}
17 changes: 0 additions & 17 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import (
"path"
"path/filepath"

"github.com/jedib0t/go-pretty/v6/text"
"github.com/spf13/cobra"
appLogging "github.com/ublue-os/uupd/pkg/logging"
"golang.org/x/term"
)

func assertRoot(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -118,19 +116,4 @@ func init() {
rootCmd.PersistentFlags().StringVar(&fLogFile, "log-file", "-", "File where user-facing logs will be written to")
rootCmd.PersistentFlags().StringVar(&fLogLevel, "log-level", "info", "Log level for user-facing logs")
rootCmd.PersistentFlags().BoolVar(&fNoLogging, "quiet", false, "Make logs quiet")

interactiveProgress := true
if fLogFile != "-" {
interactiveProgress = false
}
isTerminal := term.IsTerminal(int(os.Stdout.Fd()))
if !isTerminal {
interactiveProgress = false
}
if !text.ANSICodesSupported {
interactiveProgress = false
text.DisableColors()
}

rootCmd.Flags().BoolP("no-progress", "p", !interactiveProgress, "Do not show progress bars")
}
114 changes: 36 additions & 78 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@ import (
"log/slog"
"os"

"github.com/jedib0t/go-pretty/v6/progress"
"github.com/spf13/cobra"
"github.com/ublue-os/uupd/checks"
"github.com/ublue-os/uupd/drv"
"github.com/ublue-os/uupd/drv/brew"
"github.com/ublue-os/uupd/drv/distrobox"
"github.com/ublue-os/uupd/drv/flatpak"
drv "github.com/ublue-os/uupd/drv/generic"
"github.com/ublue-os/uupd/drv/system"

"github.com/ublue-os/uupd/pkg/filelock"
"github.com/ublue-os/uupd/pkg/percent"
"github.com/ublue-os/uupd/pkg/session"
)

func Update(cmd *cobra.Command, args []string) {
lock, err := filelock.AcquireLock()
lockfile, err := filelock.OpenLockfile(filelock.GetDefaultLockfile())
if err != nil {
slog.Error(fmt.Sprintf("%v, is uupd already running?", err))
slog.Error("Failed creating and opening lockfile. Is uupd already running?", slog.Any("error", err))
return
}
defer func() {
err := filelock.ReleaseLock(lock)
defer func(lockfile *os.File) {
err := filelock.ReleaseLock(lockfile)
if err != nil {
slog.Error("Failed releasing lock")
slog.Error("Failed releasing lock", slog.Any("error", err))
}
}()
}(lockfile)
if err := filelock.AcquireLock(lockfile, filelock.TimeoutConfig{Tries: 5}); err != nil {
slog.Error(fmt.Sprintf("%v, is uupd already running?", err))
return
}

hwCheck, err := cmd.Flags().GetBool("hw-check")
if err != nil {
Expand Down Expand Up @@ -64,86 +72,40 @@ func Update(cmd *cobra.Command, args []string) {
initConfiguration.DryRun = dryRun
initConfiguration.Verbose = verboseRun

brewUpdater, err := drv.BrewUpdater{}.New(*initConfiguration)
brewUpdater, err := brew.BrewUpdater{}.New(*initConfiguration)
brewUpdater.Config.Enabled = err == nil

flatpakUpdater, err := drv.FlatpakUpdater{}.New(*initConfiguration)
flatpakUpdater, err := flatpak.FlatpakUpdater{}.New(*initConfiguration)
flatpakUpdater.Config.Enabled = err == nil
flatpakUpdater.SetUsers(users)

distroboxUpdater, err := drv.DistroboxUpdater{}.New(*initConfiguration)
distroboxUpdater, err := distrobox.DistroboxUpdater{}.New(*initConfiguration)
distroboxUpdater.Config.Enabled = err == nil
distroboxUpdater.SetUsers(users)

var enableUpd bool = true

rpmOstreeUpdater, err := drv.RpmOstreeUpdater{}.New(*initConfiguration)
if err != nil {
enableUpd = false
}

systemUpdater, err := drv.SystemUpdater{}.New(*initConfiguration)
if err != nil {
enableUpd = false
}

isBootc, err := drv.BootcCompatible(systemUpdater.BinaryPath)
if err != nil {
isBootc = false
}

if !isBootc {
slog.Debug("Using rpm-ostree fallback as system driver")
}

systemUpdater.Config.Enabled = isBootc && enableUpd
rpmOstreeUpdater.Config.Enabled = !isBootc && enableUpd
mainSystemDriver, mainSystemDriverConfig, _, _ := system.InitializeSystemDriver(*initConfiguration)

// The system driver to be applied needs to have the correct "enabled" value since it will NOT update from here onwards.
var mainSystemDriver drv.SystemUpdateDriver = &systemUpdater
if !isBootc {
mainSystemDriver = &rpmOstreeUpdater
}

enableUpd, err = mainSystemDriver.Check()
enableUpd, err := mainSystemDriver.Check()
if err != nil {
slog.Error("Failed checking for updates")
}
mainSystemDriverConfig.Enabled = mainSystemDriverConfig.Enabled && enableUpd

slog.Debug("System Updater module status", slog.Bool("enabled", enableUpd))
slog.Debug("System Updater module status", slog.Bool("enabled", mainSystemDriverConfig.Enabled))

totalSteps := brewUpdater.Steps() + flatpakUpdater.Steps() + distroboxUpdater.Steps()
if enableUpd {
if mainSystemDriverConfig.Enabled {
totalSteps += mainSystemDriver.Steps()
}
pw := percent.NewProgressWriter()
pw.SetNumTrackersExpected(1)
pw.SetAutoStop(false)

progressEnabled, err := cmd.Flags().GetBool("no-progress")
if err != nil {
slog.Error("Failed to get no-progress flag", "error", err)
return
}
// Move this to its actual boolean value (~no-progress)
progressEnabled = !progressEnabled

if progressEnabled {
go pw.Render()
percent.ResetOscProgress()
}
// FIXME: check if is interactive
percent.ResetOscProgress()

// -1 because 0 index
tracker := percent.NewIncrementTracker(&progress.Tracker{Message: "Updating", Units: progress.UnitsDefault, Total: int64(totalSteps - 1)}, totalSteps-1)
pw.AppendTracker(tracker.Tracker)
tracker := &percent.Incrementer{MaxIncrements: totalSteps - 1}

var trackerConfig = &drv.TrackerConfiguration{
Tracker: tracker,
Writer: &pw,
Progress: progressEnabled,
}
flatpakUpdater.Tracker = trackerConfig
distroboxUpdater.Tracker = trackerConfig
flatpakUpdater.Tracker = tracker
distroboxUpdater.Tracker = tracker

var outputs = []drv.CommandOutput{}

Expand All @@ -155,7 +117,7 @@ func Update(cmd *cobra.Command, args []string) {

if systemOutdated {
const OUTDATED_WARNING = "There hasn't been an update in over a month. Consider rebooting or running updates manually"
err := session.Notify("System Warning", OUTDATED_WARNING)
err := session.Notify(users, "System Warning", OUTDATED_WARNING)
if err != nil {
slog.Error("Failed showing warning notification")
}
Expand All @@ -165,9 +127,9 @@ func Update(cmd *cobra.Command, args []string) {
// This section is ugly but we cant really do much about it.
// Using interfaces doesn't preserve the "Config" struct state and I dont know any other way to make this work without cursed workarounds.

if enableUpd {
slog.Debug(fmt.Sprintf("%s module", systemUpdater.Config.Title), slog.String("module_name", systemUpdater.Config.Title), slog.Any("module_configuration", systemUpdater.Config))
percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: systemUpdater.Config.Title, Description: systemUpdater.Config.Description})
if mainSystemDriverConfig.Enabled {
slog.Debug(fmt.Sprintf("%s module", mainSystemDriverConfig.Title), slog.String("module_name", mainSystemDriverConfig.Title), slog.Any("module_configuration", mainSystemDriverConfig))
percent.ReportStatusChange(tracker, percent.TrackerMessage{Title: mainSystemDriverConfig.Title, Description: mainSystemDriverConfig.Description})
var out *[]drv.CommandOutput
out, err = mainSystemDriver.Update()
outputs = append(outputs, *out...)
Expand All @@ -176,7 +138,7 @@ func Update(cmd *cobra.Command, args []string) {

if brewUpdater.Config.Enabled {
slog.Debug(fmt.Sprintf("%s module", brewUpdater.Config.Title), slog.String("module_name", brewUpdater.Config.Title), slog.Any("module_configuration", brewUpdater.Config))
percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: brewUpdater.Config.Title, Description: brewUpdater.Config.Description})
percent.ReportStatusChange(tracker, percent.TrackerMessage{Title: brewUpdater.Config.Title, Description: brewUpdater.Config.Description})
var out *[]drv.CommandOutput
out, err = brewUpdater.Update()
outputs = append(outputs, *out...)
Expand All @@ -185,7 +147,6 @@ func Update(cmd *cobra.Command, args []string) {

if flatpakUpdater.Config.Enabled {
slog.Debug(fmt.Sprintf("%s module", flatpakUpdater.Config.Title), slog.String("module_name", flatpakUpdater.Config.Title), slog.Any("module_configuration", flatpakUpdater.Config))
percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: flatpakUpdater.Config.Title, Description: flatpakUpdater.Config.Description})
var out *[]drv.CommandOutput
out, err = flatpakUpdater.Update()
outputs = append(outputs, *out...)
Expand All @@ -194,17 +155,14 @@ func Update(cmd *cobra.Command, args []string) {

if distroboxUpdater.Config.Enabled {
slog.Debug(fmt.Sprintf("%s module", distroboxUpdater.Config.Title), slog.String("module_name", distroboxUpdater.Config.Title), slog.Any("module_configuration", distroboxUpdater.Config))
percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: distroboxUpdater.Config.Title, Description: distroboxUpdater.Config.Description})
var out *[]drv.CommandOutput
out, err = distroboxUpdater.Update()
outputs = append(outputs, *out...)
tracker.IncrementSection(err)
}

if progressEnabled {
pw.Stop()
percent.ResetOscProgress()
}
// FIXME: detect interactive session
percent.ResetOscProgress()
if verboseRun {
slog.Info("Verbose run requested")

Expand Down
40 changes: 9 additions & 31 deletions cmd/updateCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,20 @@ import (
"log/slog"

"github.com/spf13/cobra"
"github.com/ublue-os/uupd/drv"
"github.com/ublue-os/uupd/drv/generic"
"github.com/ublue-os/uupd/drv/system"
)

func UpdateCheck(cmd *cobra.Command, args []string) {
var enableUpd bool = true
initConfiguration := generic.UpdaterInitConfiguration{}.New()
initConfiguration.Ci = false
initConfiguration.DryRun = false
initConfiguration.Verbose = false

initConfiguration := drv.UpdaterInitConfiguration{}.New()
rpmOstreeUpdater, err := drv.RpmOstreeUpdater{}.New(*initConfiguration)
mainSystemDriver, _, _, err := system.InitializeSystemDriver(*initConfiguration)
if err != nil {
enableUpd = false
}

systemUpdater, err := drv.SystemUpdater{}.New(*initConfiguration)
if err != nil {
enableUpd = false
}

isBootc, err := drv.BootcCompatible(systemUpdater.BinaryPath)
if err != nil {
isBootc = false
}

if !isBootc {
slog.Debug("Using rpm-ostree fallback as system driver")
}

systemUpdater.Config.Enabled = isBootc && enableUpd
rpmOstreeUpdater.Config.Enabled = !isBootc && enableUpd

var mainSystemDriver drv.SystemUpdateDriver
if !isBootc {
slog.Debug("Using the rpm-ostree driver")
mainSystemDriver = &rpmOstreeUpdater
} else {
slog.Debug("Using the bootc driver")
mainSystemDriver = &systemUpdater
slog.Error("Failed")
return
}

updateAvailable, err := mainSystemDriver.Check()
Expand Down
Loading