yay/print.go

268 lines
8.2 KiB
Go
Raw Normal View History

package main
import (
2021-08-12 18:56:23 +02:00
"context"
"fmt"
"io"
2018-02-19 18:36:33 +01:00
"os"
"strconv"
"strings"
"syscall"
"unicode"
2021-05-13 07:27:24 +02:00
aur "github.com/Jguer/aur"
mapset "github.com/deckarep/golang-set/v2"
"github.com/leonelquinteros/gotext"
"golang.org/x/sys/unix"
"github.com/Jguer/yay/v12/pkg/db"
"github.com/Jguer/yay/v12/pkg/dep"
"github.com/Jguer/yay/v12/pkg/query"
"github.com/Jguer/yay/v12/pkg/runtime"
"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"
)
// printInfo prints package info like pacman -Si.
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
if a.OutOfDate != 0 {
printInfoValue(logger, gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
} else {
printInfoValue(logger, gotext.Get("Out-of-date"), "No")
}
2020-07-08 03:22:01 +02:00
if extendedInfo {
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
}
logger.Println()
}
// BiggestPackages prints the name of the ten biggest packages in the system.
func biggestPackages(logger *text.Logger, dbExecutor db.Executor) {
2020-08-04 22:00:07 +02:00
pkgS := dbExecutor.BiggestPackages()
if len(pkgS) < 10 {
return
}
for i := 0; i < 10; i++ {
logger.Printf("%s: %s\n", text.Bold(pkgS[i].Name()), text.Cyan(text.Human(pkgS[i].ISize())))
}
}
2017-10-19 07:59:26 +02:00
// localStatistics prints installed packages statistics.
func localStatistics(ctx context.Context, run *runtime.Runtime, dbExecutor db.Executor) error {
info := statistics(run, dbExecutor)
2017-10-19 07:59:26 +02:00
remoteNames := dbExecutor.InstalledRemotePackageNames()
remote := dbExecutor.InstalledRemotePackages()
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))))
for path, size := range info.pacmanCaches {
run.Logger.Infoln(gotext.Get("Size of pacman cache %s: %s", path, text.Cyan(text.Human(size))))
}
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
aurData, err := run.AURClient.Get(ctx, &aur.Query{
Needles: remoteNames,
By: aur.Name,
})
if err != nil {
return err
}
warnings := query.NewWarnings(run.Logger.Child("warnings"))
for i := range aurData {
warnings.AddToWarnings(remote, &aurData[i])
}
warnings.Print()
2017-10-19 07:59:26 +02:00
return nil
}
New install algorithm I have replaced the old install and dependancy algorithms with a new design that attemps to be more pacaur like. Mostly in minimizing user input. Ask every thing first then do everything with no need for more user input. It is not yet fully complete but is finished enough so that it works, should not fail in most cases and provides a base for more contributors to help address the existing problems. The new install chain is as follows: Source info about the provided targets Fetch a list of all dependancies needed to install targets I put alot of effort into fetching the dependancy tree while making the least amount of aur requests as possible. I'm actually very happy with how it turned out and yay wil now resolve dependancies noticably faster than pacaur when there are many aur dependancies. Install repo targets by passing to pacman Print dependancy tree and ask to confirm Ask to clean build if directory already exists Download all pkgbuilds Ask to edit all pkgbuilds Ask to continue with the install Download the sources for each packagebuild Build and install every package using -s to get repo deps and -i to install Ask to remove make dependancies There are still a lot of things that need to be done for a fully working system. Here are the problems I found with this system, either new or existing: Formating I am not so good at formatting myself, I thought best to leave it until last so I could get feedback on how it should look and help implementing it. Dependancy tree The dependancy tree is usually correct although I have noticed times where it doesnt detect all the dependancies that it should. I have only noticed this when there are circular dependancies so i think this might be the cause. It's not a big deal currently because makepkg -i installed repo deps for us which handles the repo deps for us and will get the correct ones. So yay might not list all the dependancies. but they will get installed so I consider this a visual bug. I have yet to see any circular dependancies in the AUR so I can not say what will happend but I#m guessing that it will break. Versioned packages/dependencies Targets and dependancies with version constriants such as 'linux>=4.1' will not be checked on the aur side of things but will be checked on the repo side. Ignorepkg/Ignoregroup Currently I do not handle this in any way but it shouldn't be too hard to implement. Conflict checking This is not currently implemented either Split Paclages Split packages are not Handles properly. If we only specify one package so install from a split package makepkg -i ends up installing them all anyway. If we specify more than one (n) package it will actually build the package base n times and reinstall every split package n times. Makepkg To get things working I decided to keep using the makepkg -i method. I plan to eventually replace this with a pacman -U based method. This should allow passing args such as --dbpath and --config to aur packages aswell as help solve some problems such as the split packages. Clean build I plan to improve the clean build choice to be a little more smart and instead of check if the directory exists, check if the package is already build and if so skip the build all together.
2018-01-17 22:48:23 +01: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 {
quietMode := cmdArgs.ExistsArg("q", "quiet")
// TODO: handle quiet mode in a better way
logger := text.NewLogger(io.Discard, os.Stderr, os.Stdin, run.Cfg.Debug, "update-list")
dbExecutor.SetLogger(logger.Child("db"))
oldNoConfirm := settings.NoConfirm
settings.NoConfirm = true
// restoring global NoConfirm to make tests work properly
defer func() { settings.NoConfirm = oldNoConfirm }()
2021-08-11 20:13:28 +02:00
targets := mapset.NewThreadUnsafeSet(cmdArgs.Targets...)
grapher := dep.NewGrapher(dbExecutor, run.AURClient, false, true,
false, false, cmdArgs.ExistsArg("needed"), logger.Child("grapher"))
upService := upgrade.NewUpgradeService(
grapher, run.AURClient, dbExecutor, run.VCSStore,
run.Cfg, true, logger.Child("upgrade"))
2021-08-11 20:13:28 +02:00
graph, errSysUp := upService.GraphUpgrades(ctx, nil,
enableDowngrade, filter)
if errSysUp != nil {
return errSysUp
}
if graph.Len() == 0 {
return fmt.Errorf("")
}
noTargets := targets.Cardinality() == 0
foreignFilter := cmdArgs.ExistsArg("m", "foreign")
nativeFilter := cmdArgs.ExistsArg("n", "native")
noUpdates := true
_ = graph.ForEach(func(pkgName string, ii *dep.InstallInfo) error {
if !ii.Upgrade {
return nil
}
if noTargets || targets.Contains(pkgName) {
if ii.Source == dep.Sync && foreignFilter {
return nil
} else if ii.Source == dep.AUR && nativeFilter {
return nil
}
2021-08-11 20:13:28 +02:00
if quietMode {
run.Logger.Printf("%s\n", pkgName)
} else {
run.Logger.Printf("%s %s -> %s\n", text.Bold(pkgName), text.Bold(text.Green(ii.LocalVersion)),
text.Bold(text.Green(ii.Version)))
}
targets.Remove(pkgName)
noUpdates = false
}
return nil
})
missing := false
targets.Each(func(pkgName string) bool {
if dbExecutor.LocalPackage(pkgName) == nil {
run.Logger.Errorln(gotext.Get("package '%s' was not found", pkgName))
missing = true
}
return false
})
if missing || noUpdates {
return fmt.Errorf("")
}
2018-02-19 18:36:33 +01:00
return nil
}
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
}