2017-08-02 19:24:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-08-12 18:56:23 +02:00
|
|
|
"context"
|
2017-08-02 19:24:03 +02:00
|
|
|
"fmt"
|
2023-03-08 22:30:54 +01:00
|
|
|
"io"
|
2018-02-19 18:36:33 +01:00
|
|
|
"os"
|
2018-01-26 02:18:49 +01:00
|
|
|
"strconv"
|
2023-08-06 21:39:41 +02:00
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
"unicode"
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
aur "github.com/Jguer/aur"
|
2023-03-08 22:30:54 +01:00
|
|
|
mapset "github.com/deckarep/golang-set/v2"
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2023-08-06 21:39:41 +02:00
|
|
|
"golang.org/x/sys/unix"
|
2019-10-16 23:36:08 +02:00
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/db"
|
2023-03-08 22:30:54 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/dep"
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/query"
|
2023-08-06 21:39:41 +02:00
|
|
|
"github.com/Jguer/yay/v12/pkg/runtime"
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/settings"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/upgrade"
|
2017-08-02 19:24:03 +02:00
|
|
|
)
|
|
|
|
|
2023-05-24 10:22:18 +02:00
|
|
|
// printInfo prints package info like pacman -Si.
|
2023-08-06 21:39:41 +02:00
|
|
|
func printInfo(logger *text.Logger, config *settings.Configuration, a *aur.Pkg, extendedInfo bool) {
|
|
|
|
printInfoValue(logger, gotext.Get("Repository"), "aur")
|
|
|
|
printInfoValue(logger, gotext.Get("Name"), a.Name)
|
|
|
|
printInfoValue(logger, gotext.Get("Version"), a.Version)
|
|
|
|
printInfoValue(logger, gotext.Get("Description"), a.Description)
|
|
|
|
printInfoValue(logger, gotext.Get("URL"), a.URL)
|
|
|
|
printInfoValue(logger, gotext.Get("Licenses"), a.License...)
|
|
|
|
printInfoValue(logger, gotext.Get("Groups"), a.Groups...)
|
|
|
|
printInfoValue(logger, gotext.Get("Provides"), a.Provides...)
|
|
|
|
printInfoValue(logger, gotext.Get("Depends On"), a.Depends...)
|
|
|
|
printInfoValue(logger, gotext.Get("Optional Deps"), a.OptDepends...)
|
|
|
|
printInfoValue(logger, gotext.Get("Make Deps"), a.MakeDepends...)
|
|
|
|
printInfoValue(logger, gotext.Get("Check Deps"), a.CheckDepends...)
|
|
|
|
printInfoValue(logger, gotext.Get("Conflicts With"), a.Conflicts...)
|
|
|
|
printInfoValue(logger, gotext.Get("Replaces"), a.Replaces...)
|
|
|
|
printInfoValue(logger, gotext.Get("AUR URL"), config.AURURL+"/packages/"+a.Name)
|
|
|
|
printInfoValue(logger, gotext.Get("First Submitted"), text.FormatTimeQuery(a.FirstSubmitted))
|
|
|
|
printInfoValue(logger, gotext.Get("Keywords"), a.Keywords...)
|
|
|
|
printInfoValue(logger, gotext.Get("Last Modified"), text.FormatTimeQuery(a.LastModified))
|
|
|
|
printInfoValue(logger, gotext.Get("Maintainer"), a.Maintainer)
|
|
|
|
printInfoValue(logger, gotext.Get("Popularity"), fmt.Sprintf("%f", a.Popularity))
|
|
|
|
printInfoValue(logger, gotext.Get("Votes"), fmt.Sprintf("%d", a.NumVotes))
|
2018-07-24 02:48:36 +02:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if a.OutOfDate != 0 {
|
2023-08-06 21:39:41 +02:00
|
|
|
printInfoValue(logger, gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
|
2018-05-30 17:00:40 +02:00
|
|
|
} else {
|
2023-08-06 21:39:41 +02:00
|
|
|
printInfoValue(logger, gotext.Get("Out-of-date"), "No")
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-01-07 18:36:31 +01:00
|
|
|
|
2020-07-08 03:22:01 +02:00
|
|
|
if extendedInfo {
|
2023-08-06 21:39:41 +02:00
|
|
|
printInfoValue(logger, "ID", fmt.Sprintf("%d", a.ID))
|
|
|
|
printInfoValue(logger, gotext.Get("Package Base ID"), fmt.Sprintf("%d", a.PackageBaseID))
|
|
|
|
printInfoValue(logger, gotext.Get("Package Base"), a.PackageBase)
|
|
|
|
printInfoValue(logger, gotext.Get("Snapshot URL"), config.AURURL+a.URLPath)
|
2018-07-24 02:48:36 +02:00
|
|
|
}
|
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
logger.Println()
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BiggestPackages prints the name of the ten biggest packages in the system.
|
2023-08-06 21:39:41 +02:00
|
|
|
func biggestPackages(logger *text.Logger, dbExecutor db.Executor) {
|
2020-08-04 22:00:07 +02:00
|
|
|
pkgS := dbExecutor.BiggestPackages()
|
2017-08-02 19:24:03 +02:00
|
|
|
|
|
|
|
if len(pkgS) < 10 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2023-08-06 21:39:41 +02:00
|
|
|
logger.Printf("%s: %s\n", text.Bold(pkgS[i].Name()), text.Cyan(text.Human(pkgS[i].ISize())))
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-19 07:59:26 +02:00
|
|
|
|
|
|
|
// localStatistics prints installed packages statistics.
|
2023-08-06 21:39:41 +02:00
|
|
|
func localStatistics(ctx context.Context, run *runtime.Runtime, dbExecutor db.Executor) error {
|
|
|
|
info := statistics(run, dbExecutor)
|
2017-10-19 07:59:26 +02:00
|
|
|
|
2022-11-20 01:51:55 +01:00
|
|
|
remoteNames := dbExecutor.InstalledRemotePackageNames()
|
2023-05-24 10:22:18 +02:00
|
|
|
remote := dbExecutor.InstalledRemotePackages()
|
2023-08-06 21:39:41 +02:00
|
|
|
run.Logger.Infoln(gotext.Get("Yay version v%s", yayVersion))
|
|
|
|
run.Logger.Println(text.Bold(text.Cyan("===========================================")))
|
|
|
|
run.Logger.Infoln(gotext.Get("Total installed packages: %s", text.Cyan(strconv.Itoa(info.Totaln))))
|
|
|
|
run.Logger.Infoln(gotext.Get("Foreign installed packages: %s", text.Cyan(strconv.Itoa(len(remoteNames)))))
|
|
|
|
run.Logger.Infoln(gotext.Get("Explicitly installed packages: %s", text.Cyan(strconv.Itoa(info.Expln))))
|
|
|
|
run.Logger.Infoln(gotext.Get("Total Size occupied by packages: %s", text.Cyan(text.Human(info.TotalSize))))
|
2022-02-06 10:53:34 +01:00
|
|
|
|
|
|
|
for path, size := range info.pacmanCaches {
|
2023-08-06 21:39:41 +02:00
|
|
|
run.Logger.Infoln(gotext.Get("Size of pacman cache %s: %s", path, text.Cyan(text.Human(size))))
|
2022-02-06 10:53:34 +01:00
|
|
|
}
|
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
run.Logger.Infoln(gotext.Get("Size of yay cache %s: %s", run.Cfg.BuildDir, text.Cyan(text.Human(info.yayCache))))
|
|
|
|
run.Logger.Println(text.Bold(text.Cyan("===========================================")))
|
|
|
|
run.Logger.Infoln(gotext.Get("Ten biggest packages:"))
|
|
|
|
biggestPackages(run.Logger, dbExecutor)
|
|
|
|
run.Logger.Println(text.Bold(text.Cyan("===========================================")))
|
2017-10-19 07:59:26 +02:00
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
aurData, err := run.AURClient.Get(ctx, &aur.Query{
|
2023-05-24 10:22:18 +02:00
|
|
|
Needles: remoteNames,
|
|
|
|
By: aur.Name,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
warnings := query.NewWarnings(run.Logger.Child("warnings"))
|
2023-05-24 10:22:18 +02:00
|
|
|
for i := range aurData {
|
|
|
|
warnings.AddToWarnings(remote, &aurData[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
warnings.Print()
|
2017-10-19 07:59:26 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
func printUpdateList(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Arguments,
|
2022-11-08 01:32:21 +01:00
|
|
|
dbExecutor db.Executor, enableDowngrade bool, filter upgrade.Filter,
|
|
|
|
) error {
|
2023-03-08 22:30:54 +01:00
|
|
|
quietMode := cmdArgs.ExistsArg("q", "quiet")
|
2023-04-05 13:43:30 +02:00
|
|
|
|
2023-04-04 00:05:45 +02:00
|
|
|
// TODO: handle quiet mode in a better way
|
2023-08-06 21:39:41 +02:00
|
|
|
logger := text.NewLogger(io.Discard, os.Stderr, os.Stdin, run.Cfg.Debug, "update-list")
|
2023-04-04 00:05:45 +02:00
|
|
|
dbExecutor.SetLogger(logger.Child("db"))
|
2023-05-15 10:33:12 +02:00
|
|
|
oldNoConfirm := settings.NoConfirm
|
2023-04-05 13:43:30 +02:00
|
|
|
settings.NoConfirm = true
|
2023-05-15 10:33:12 +02:00
|
|
|
// restoring global NoConfirm to make tests work properly
|
|
|
|
defer func() { settings.NoConfirm = oldNoConfirm }()
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
targets := mapset.NewThreadUnsafeSet(cmdArgs.Targets...)
|
2023-08-06 21:39:41 +02:00
|
|
|
grapher := dep.NewGrapher(dbExecutor, run.AURClient, false, true,
|
2023-03-08 22:30:54 +01:00
|
|
|
false, false, cmdArgs.ExistsArg("needed"), logger.Child("grapher"))
|
2018-04-27 02:25:40 +02:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
upService := upgrade.NewUpgradeService(
|
2023-08-06 21:39:41 +02:00
|
|
|
grapher, run.AURClient, dbExecutor, run.VCSStore,
|
|
|
|
run.Cfg, true, logger.Child("upgrade"))
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
graph, errSysUp := upService.GraphUpgrades(ctx, nil,
|
|
|
|
enableDowngrade, filter)
|
|
|
|
if errSysUp != nil {
|
|
|
|
return errSysUp
|
2018-01-25 21:39:26 +01:00
|
|
|
}
|
2018-03-21 05:50:54 +01:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
if graph.Len() == 0 {
|
2023-02-21 03:00:39 +01:00
|
|
|
return fmt.Errorf("")
|
|
|
|
}
|
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
noTargets := targets.Cardinality() == 0
|
|
|
|
foreignFilter := cmdArgs.ExistsArg("m", "foreign")
|
|
|
|
nativeFilter := cmdArgs.ExistsArg("n", "native")
|
2018-03-21 05:50:54 +01:00
|
|
|
|
2023-05-22 20:35:27 +02:00
|
|
|
noUpdates := true
|
2023-03-08 22:30:54 +01:00
|
|
|
_ = graph.ForEach(func(pkgName string, ii *dep.InstallInfo) error {
|
2023-04-06 18:32:22 +02:00
|
|
|
if !ii.Upgrade {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
if noTargets || targets.Contains(pkgName) {
|
|
|
|
if ii.Source == dep.Sync && foreignFilter {
|
|
|
|
return nil
|
|
|
|
} else if ii.Source == dep.AUR && nativeFilter {
|
|
|
|
return nil
|
2018-03-21 05:50:54 +01:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
if quietMode {
|
2023-08-06 21:39:41 +02:00
|
|
|
run.Logger.Printf("%s\n", pkgName)
|
2023-03-08 22:30:54 +01:00
|
|
|
} else {
|
2023-08-06 21:39:41 +02:00
|
|
|
run.Logger.Printf("%s %s -> %s\n", text.Bold(pkgName), text.Bold(text.Green(ii.LocalVersion)),
|
2023-04-04 00:05:45 +02:00
|
|
|
text.Bold(text.Green(ii.Version)))
|
2018-03-21 05:50:54 +01:00
|
|
|
}
|
2018-01-25 21:39:26 +01:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
targets.Remove(pkgName)
|
2023-05-22 20:35:27 +02:00
|
|
|
noUpdates = false
|
2018-03-23 20:49:51 +01:00
|
|
|
}
|
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
return nil
|
|
|
|
})
|
2018-03-23 20:49:51 +01:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
missing := false
|
|
|
|
targets.Each(func(pkgName string) bool {
|
|
|
|
if dbExecutor.LocalPackage(pkgName) == nil {
|
2023-08-06 21:39:41 +02:00
|
|
|
run.Logger.Errorln(gotext.Get("package '%s' was not found", pkgName))
|
2023-03-08 22:30:54 +01:00
|
|
|
missing = true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
2018-03-23 20:49:51 +01:00
|
|
|
|
2023-05-22 20:35:27 +02:00
|
|
|
if missing || noUpdates {
|
2018-03-23 20:49:51 +01:00
|
|
|
return fmt.Errorf("")
|
2018-01-25 21:39:26 +01:00
|
|
|
}
|
2018-02-19 18:36:33 +01:00
|
|
|
|
2018-01-25 21:39:26 +01:00
|
|
|
return nil
|
|
|
|
}
|
2023-08-06 21:39:41 +02:00
|
|
|
|
|
|
|
func printInfoValue(logger *text.Logger, key string, values ...string) {
|
|
|
|
const (
|
|
|
|
keyLength = 32
|
|
|
|
delimCount = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
specialWordsCount := 0
|
|
|
|
|
|
|
|
for _, runeValue := range key {
|
|
|
|
// CJK handling: the character 'ー' is Katakana
|
|
|
|
// but if use unicode.Katakana, it will return false
|
|
|
|
if unicode.IsOneOf([]*unicode.RangeTable{
|
|
|
|
unicode.Han,
|
|
|
|
unicode.Hiragana,
|
|
|
|
unicode.Katakana,
|
|
|
|
unicode.Hangul,
|
|
|
|
}, runeValue) || runeValue == 'ー' {
|
|
|
|
specialWordsCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
keyTextCount := specialWordsCount - keyLength + delimCount
|
|
|
|
str := fmt.Sprintf(text.Bold("%-*s: "), keyTextCount, key)
|
|
|
|
|
|
|
|
if len(values) == 0 || (len(values) == 1 && values[0] == "") {
|
|
|
|
logger.Printf("%s%s\n", str, gotext.Get("None"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
maxCols := getColumnCount()
|
|
|
|
cols := keyLength + len(values[0])
|
|
|
|
str += values[0]
|
|
|
|
|
|
|
|
for _, value := range values[1:] {
|
|
|
|
if maxCols > keyLength && cols+len(value)+delimCount >= maxCols {
|
|
|
|
cols = keyLength
|
|
|
|
str += "\n" + strings.Repeat(" ", keyLength)
|
|
|
|
} else if cols != keyLength {
|
|
|
|
str += strings.Repeat(" ", delimCount)
|
|
|
|
cols += delimCount
|
|
|
|
}
|
|
|
|
|
|
|
|
str += value
|
|
|
|
cols += len(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Println(str)
|
|
|
|
}
|
|
|
|
|
|
|
|
var cachedColumnCount = -1
|
|
|
|
|
|
|
|
func getColumnCount() int {
|
|
|
|
if cachedColumnCount > 0 {
|
|
|
|
return cachedColumnCount
|
|
|
|
}
|
|
|
|
|
|
|
|
if count, err := strconv.Atoi(os.Getenv("COLUMNS")); err == nil {
|
|
|
|
cachedColumnCount = count
|
|
|
|
return cachedColumnCount
|
|
|
|
}
|
|
|
|
|
|
|
|
if ws, err := unix.IoctlGetWinsize(syscall.Stdout, unix.TIOCGWINSZ); err == nil {
|
|
|
|
cachedColumnCount = int(ws.Col)
|
|
|
|
return cachedColumnCount
|
|
|
|
}
|
|
|
|
|
|
|
|
return 80
|
|
|
|
}
|