1
0
mirror of https://github.com/Jguer/yay synced 2024-07-08 04:16:16 +00:00
yay/print.go

189 lines
5.8 KiB
Go
Raw Normal View History

package main
import (
2021-08-12 16:56:23 +00:00
"context"
"fmt"
2018-02-19 17:36:33 +00:00
"os"
"strconv"
2021-05-13 05:27:24 +00:00
aur "github.com/Jguer/aur"
"github.com/leonelquinteros/gotext"
2021-09-08 20:28:08 +00:00
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/stringset"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/upgrade"
)
// PrintInfo prints package info like pacman -Si.
2021-05-13 05:27:24 +00:00
func PrintInfo(a *aur.Pkg, extendedInfo bool) {
text.PrintInfoValue(gotext.Get("Repository"), "aur")
text.PrintInfoValue(gotext.Get("Name"), a.Name)
text.PrintInfoValue(gotext.Get("Keywords"), a.Keywords...)
text.PrintInfoValue(gotext.Get("Version"), a.Version)
text.PrintInfoValue(gotext.Get("Description"), a.Description)
text.PrintInfoValue(gotext.Get("URL"), a.URL)
text.PrintInfoValue(gotext.Get("AUR URL"), config.AURURL+"/packages/"+a.Name)
text.PrintInfoValue(gotext.Get("Groups"), a.Groups...)
text.PrintInfoValue(gotext.Get("Licenses"), a.License...)
text.PrintInfoValue(gotext.Get("Provides"), a.Provides...)
text.PrintInfoValue(gotext.Get("Depends On"), a.Depends...)
text.PrintInfoValue(gotext.Get("Make Deps"), a.MakeDepends...)
text.PrintInfoValue(gotext.Get("Check Deps"), a.CheckDepends...)
text.PrintInfoValue(gotext.Get("Optional Deps"), a.OptDepends...)
text.PrintInfoValue(gotext.Get("Conflicts With"), a.Conflicts...)
text.PrintInfoValue(gotext.Get("Maintainer"), a.Maintainer)
text.PrintInfoValue(gotext.Get("Votes"), fmt.Sprintf("%d", a.NumVotes))
text.PrintInfoValue(gotext.Get("Popularity"), fmt.Sprintf("%f", a.Popularity))
2020-06-26 07:15:36 +00:00
text.PrintInfoValue(gotext.Get("First Submitted"), text.FormatTimeQuery(a.FirstSubmitted))
text.PrintInfoValue(gotext.Get("Last Modified"), text.FormatTimeQuery(a.LastModified))
2018-07-24 00:48:36 +00:00
if a.OutOfDate != 0 {
2020-06-26 07:15:36 +00:00
text.PrintInfoValue(gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
} else {
text.PrintInfoValue(gotext.Get("Out-of-date"), "No")
}
2020-07-08 01:22:01 +00:00
if extendedInfo {
text.PrintInfoValue("ID", fmt.Sprintf("%d", a.ID))
text.PrintInfoValue(gotext.Get("Package Base ID"), fmt.Sprintf("%d", a.PackageBaseID))
text.PrintInfoValue(gotext.Get("Package Base"), a.PackageBase)
text.PrintInfoValue(gotext.Get("Snapshot URL"), config.AURURL+a.URLPath)
2018-07-24 00:48:36 +00:00
}
fmt.Println()
}
// BiggestPackages prints the name of the ten biggest packages in the system.
2020-08-16 21:41:38 +00:00
func biggestPackages(dbExecutor db.Executor) {
2020-08-04 20:00:07 +00:00
pkgS := dbExecutor.BiggestPackages()
if len(pkgS) < 10 {
return
}
for i := 0; i < 10; i++ {
2020-08-16 22:09:43 +00:00
fmt.Printf("%s: %s\n", text.Bold(pkgS[i].Name()), text.Cyan(text.Human(pkgS[i].ISize())))
}
}
2017-10-19 05:59:26 +00:00
// localStatistics prints installed packages statistics.
2021-08-12 16:56:23 +00:00
func localStatistics(ctx context.Context, dbExecutor db.Executor) error {
2020-08-04 20:00:07 +00:00
info := statistics(dbExecutor)
2017-10-19 05:59:26 +00:00
_, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
2017-10-19 05:59:26 +00:00
if err != nil {
return err
}
text.Infoln(gotext.Get("Yay version v%s", yayVersion))
2020-08-16 22:09:43 +00:00
fmt.Println(text.Bold(text.Cyan("===========================================")))
text.Infoln(gotext.Get("Total installed packages: %s", text.Cyan(strconv.Itoa(info.Totaln))))
text.Infoln(gotext.Get("Total foreign installed packages: %s", text.Cyan(strconv.Itoa(len(remoteNames)))))
text.Infoln(gotext.Get("Explicitly installed packages: %s", text.Cyan(strconv.Itoa(info.Expln))))
text.Infoln(gotext.Get("Total Size occupied by packages: %s", text.Cyan(text.Human(info.TotalSize))))
fmt.Println(text.Bold(text.Cyan("===========================================")))
text.Infoln(gotext.Get("Ten biggest packages:"))
2020-08-04 20:00:07 +00:00
biggestPackages(dbExecutor)
2020-08-16 22:09:43 +00:00
fmt.Println(text.Bold(text.Cyan("===========================================")))
2017-10-19 05:59:26 +00:00
2021-08-12 16:56:23 +00:00
query.AURInfoPrint(ctx, config.Runtime.AURClient, remoteNames, config.RequestSplitN)
2017-10-19 05:59:26 +00: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 21:48:23 +00:00
2021-08-12 16:56:23 +00:00
func printNumberOfUpdates(ctx context.Context, dbExecutor db.Executor, enableDowngrade bool, filter upgrade.Filter) error {
2020-07-10 00:36:45 +00:00
warnings := query.NewWarnings()
2018-02-19 17:36:33 +00:00
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
2021-08-12 16:56:23 +00:00
aurUp, repoUp, err := upList(ctx, warnings, dbExecutor, enableDowngrade, filter)
os.Stdout = old // restoring the real stdout
2021-08-11 18:13:28 +00:00
if err != nil {
return err
}
2021-08-11 18:13:28 +00:00
fmt.Println(len(aurUp.Up) + len(repoUp.Up))
2018-02-21 08:41:25 +00:00
return nil
}
2021-08-12 16:56:23 +00:00
func printUpdateList(ctx context.Context, cmdArgs *parser.Arguments,
dbExecutor db.Executor, enableDowngrade bool, filter upgrade.Filter) error {
2020-07-08 01:22:01 +00:00
targets := stringset.FromSlice(cmdArgs.Targets)
2020-07-10 00:36:45 +00:00
warnings := query.NewWarnings()
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
2021-08-11 18:13:28 +00:00
2020-08-01 07:55:08 +00:00
localNames, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
if err != nil {
os.Stdout = old
return err
}
2021-08-12 16:56:23 +00:00
aurUp, repoUp, err := upList(ctx, warnings, dbExecutor, enableDowngrade, filter)
os.Stdout = old // restoring the real stdout
2021-08-11 18:13:28 +00:00
if err != nil {
return err
}
noTargets := len(targets) == 0
2020-07-08 01:22:01 +00:00
if !cmdArgs.ExistsArg("m", "foreign") {
for _, pkg := range repoUp.Up {
if noTargets || targets.Get(pkg.Name) {
2020-07-08 01:22:01 +00:00
if cmdArgs.ExistsArg("q", "quiet") {
2018-09-24 09:52:17 +00:00
fmt.Printf("%s\n", pkg.Name)
} else {
2020-08-16 22:09:43 +00:00
fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
2018-09-24 09:52:17 +00:00
}
2021-08-11 18:13:28 +00:00
delete(targets, pkg.Name)
}
}
}
2020-07-08 01:22:01 +00:00
if !cmdArgs.ExistsArg("n", "native") {
for _, pkg := range aurUp.Up {
if noTargets || targets.Get(pkg.Name) {
2020-07-08 01:22:01 +00:00
if cmdArgs.ExistsArg("q", "quiet") {
2018-09-24 09:52:17 +00:00
fmt.Printf("%s\n", pkg.Name)
} else {
2020-08-16 22:09:43 +00:00
fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
2018-09-24 09:52:17 +00:00
}
2021-08-11 18:13:28 +00:00
delete(targets, pkg.Name)
}
}
}
missing := false
outer:
for pkg := range targets {
for _, name := range localNames {
if name == pkg {
continue outer
}
}
for _, name := range remoteNames {
if name == pkg {
continue outer
}
}
text.Errorln(gotext.Get("package '%s' was not found", pkg))
missing = true
}
if missing {
return fmt.Errorf("")
}
2018-02-19 17:36:33 +00:00
return nil
}