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"
|
2018-02-19 18:36:33 +01:00
|
|
|
"os"
|
2018-01-26 02:18:49 +01:00
|
|
|
"strconv"
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
aur "github.com/Jguer/aur"
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2019-10-16 23:36:08 +02:00
|
|
|
|
2021-09-08 22:28:08 +02: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"
|
2017-08-02 19:24:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// PrintInfo prints package info like pacman -Si.
|
2021-05-13 07:27:24 +02:00
|
|
|
func PrintInfo(a *aur.Pkg, extendedInfo bool) {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("Repository"), "aur")
|
|
|
|
text.PrintInfoValue(gotext.Get("Name"), a.Name)
|
2020-08-30 23:13:04 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("Keywords"), a.Keywords...)
|
2020-05-04 09:24:32 +02:00
|
|
|
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)
|
2020-08-30 23:13:04 +02:00
|
|
|
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...)
|
2020-05-04 09:24:32 +02:00
|
|
|
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 09:15:36 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("First Submitted"), text.FormatTimeQuery(a.FirstSubmitted))
|
|
|
|
text.PrintInfoValue(gotext.Get("Last Modified"), text.FormatTimeQuery(a.LastModified))
|
2018-07-24 02:48:36 +02:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if a.OutOfDate != 0 {
|
2020-06-26 09:15:36 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
|
2018-05-30 17:00:40 +02:00
|
|
|
} else {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.PrintInfoValue(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 {
|
2020-05-04 09:24:32 +02:00
|
|
|
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 02:48:36 +02:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:36:31 +01:00
|
|
|
fmt.Println()
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BiggestPackages prints the name of the ten biggest packages in the system.
|
2020-08-16 23:41:38 +02:00
|
|
|
func biggestPackages(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++ {
|
2020-08-17 00:09:43 +02:00
|
|
|
fmt.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.
|
2021-08-12 18:56:23 +02:00
|
|
|
func localStatistics(ctx context.Context, dbExecutor db.Executor) error {
|
2020-08-04 22:00:07 +02:00
|
|
|
info := statistics(dbExecutor)
|
2017-10-19 07:59:26 +02:00
|
|
|
|
2020-08-17 00:02:14 +02:00
|
|
|
_, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
|
2017-10-19 07:59:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Infoln(gotext.Get("Yay version v%s", yayVersion))
|
2020-08-17 00:09:43 +02: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("===========================================")))
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Infoln(gotext.Get("Ten biggest packages:"))
|
2020-08-04 22:00:07 +02:00
|
|
|
biggestPackages(dbExecutor)
|
2020-08-17 00:09:43 +02:00
|
|
|
fmt.Println(text.Bold(text.Cyan("===========================================")))
|
2017-10-19 07:59:26 +02:00
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
query.AURInfoPrint(ctx, config.Runtime.AURClient, remoteNames, config.RequestSplitN)
|
2017-10-19 07:59:26 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
func printNumberOfUpdates(ctx context.Context, dbExecutor db.Executor, enableDowngrade bool, filter upgrade.Filter) error {
|
2020-07-10 02:36:45 +02:00
|
|
|
warnings := query.NewWarnings()
|
2018-02-19 18:36:33 +01:00
|
|
|
old := os.Stdout // keep backup of the real stdout
|
2018-01-25 21:39:26 +01:00
|
|
|
os.Stdout = nil
|
2021-08-12 18:56:23 +02:00
|
|
|
aurUp, repoUp, err := upList(ctx, warnings, dbExecutor, enableDowngrade, filter)
|
2018-01-25 21:39:26 +01:00
|
|
|
os.Stdout = old // restoring the real stdout
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-01-25 21:39:26 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-04-19 13:23:40 +02:00
|
|
|
fmt.Println(len(aurUp.Up) + len(repoUp.Up))
|
2018-02-21 09:41:25 +01:00
|
|
|
|
2018-01-25 21:39:26 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
func printUpdateList(ctx context.Context, cmdArgs *parser.Arguments,
|
|
|
|
dbExecutor db.Executor, enableDowngrade bool, filter upgrade.Filter) error {
|
2020-07-08 03:22:01 +02:00
|
|
|
targets := stringset.FromSlice(cmdArgs.Targets)
|
2020-07-10 02:36:45 +02:00
|
|
|
warnings := query.NewWarnings()
|
2018-03-29 04:42:11 +02:00
|
|
|
old := os.Stdout // keep backup of the real stdout
|
2018-01-25 21:39:26 +01:00
|
|
|
os.Stdout = nil
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-08-01 09:55:08 +02:00
|
|
|
localNames, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
|
2018-04-27 02:25:40 +02:00
|
|
|
if err != nil {
|
2020-12-23 18:45:24 +01:00
|
|
|
os.Stdout = old
|
2018-04-27 02:25:40 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
aurUp, repoUp, err := upList(ctx, warnings, dbExecutor, enableDowngrade, filter)
|
2018-03-29 04:42:11 +02:00
|
|
|
os.Stdout = old // restoring the real stdout
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-01-25 21:39:26 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-21 05:50:54 +01:00
|
|
|
|
2018-06-02 16:01:39 +02:00
|
|
|
noTargets := len(targets) == 0
|
2018-03-21 05:50:54 +01:00
|
|
|
|
2020-07-08 03:22:01 +02:00
|
|
|
if !cmdArgs.ExistsArg("m", "foreign") {
|
2021-04-19 13:23:40 +02:00
|
|
|
for _, pkg := range repoUp.Up {
|
2019-10-05 19:39:31 +02:00
|
|
|
if noTargets || targets.Get(pkg.Name) {
|
2020-07-08 03:22:01 +02:00
|
|
|
if cmdArgs.ExistsArg("q", "quiet") {
|
2018-09-24 11:52:17 +02:00
|
|
|
fmt.Printf("%s\n", pkg.Name)
|
|
|
|
} else {
|
2020-08-17 00:09:43 +02:00
|
|
|
fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
|
2018-09-24 11:52:17 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-06-02 16:01:39 +02:00
|
|
|
delete(targets, pkg.Name)
|
2018-03-21 05:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 03:22:01 +02:00
|
|
|
if !cmdArgs.ExistsArg("n", "native") {
|
2021-04-19 13:23:40 +02:00
|
|
|
for _, pkg := range aurUp.Up {
|
2019-10-05 19:39:31 +02:00
|
|
|
if noTargets || targets.Get(pkg.Name) {
|
2020-07-08 03:22:01 +02:00
|
|
|
if cmdArgs.ExistsArg("q", "quiet") {
|
2018-09-24 11:52:17 +02:00
|
|
|
fmt.Printf("%s\n", pkg.Name)
|
|
|
|
} else {
|
2020-08-17 00:09:43 +02:00
|
|
|
fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
|
2018-09-24 11:52:17 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-06-02 16:01:39 +02:00
|
|
|
delete(targets, pkg.Name)
|
2018-03-21 05:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-25 21:39:26 +01:00
|
|
|
}
|
|
|
|
|
2018-03-23 20:49:51 +01:00
|
|
|
missing := false
|
|
|
|
|
|
|
|
outer:
|
2018-06-02 16:01:39 +02:00
|
|
|
for pkg := range targets {
|
2018-03-23 20:49:51 +01:00
|
|
|
for _, name := range localNames {
|
|
|
|
if name == pkg {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range remoteNames {
|
|
|
|
if name == pkg {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Errorln(gotext.Get("package '%s' was not found", pkg))
|
2018-03-23 20:49:51 +01:00
|
|
|
missing = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if missing {
|
|
|
|
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
|
|
|
|
}
|