mirror of
https://github.com/Jguer/yay
synced 2024-10-01 13:53:32 +00:00
fix(statistics): use alpm executor
This commit is contained in:
parent
94f650f4d3
commit
7bcf2ecb4c
2
cmd.go
2
cmd.go
|
@ -237,7 +237,7 @@ func handlePrint(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecuto
|
|||
case cmdArgs.ExistsArg("c", "complete"):
|
||||
err = completion.Show(dbExecutor, config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, false)
|
||||
case cmdArgs.ExistsArg("s", "stats"):
|
||||
err = localStatistics(alpmHandle)
|
||||
err = localStatistics(dbExecutor)
|
||||
default:
|
||||
err = nil
|
||||
}
|
||||
|
|
|
@ -320,3 +320,12 @@ func (ae *AlpmExecutor) RepoUpgrades(enableDowngrade bool) (upgrade.UpSlice, err
|
|||
func (ae *AlpmExecutor) AlpmArch() (string, error) {
|
||||
return ae.handle.Arch()
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) BiggestPackages() []RepoPackage {
|
||||
localPackages := []RepoPackage{}
|
||||
_ = ae.localDB.PkgCache().SortBySize().ForEach(func(pkg alpm.Package) error {
|
||||
localPackages = append(localPackages, RepoPackage(&pkg))
|
||||
return nil
|
||||
})
|
||||
return localPackages
|
||||
}
|
||||
|
|
|
@ -16,4 +16,5 @@ type RepoPackage interface {
|
|||
ShouldIgnore() bool
|
||||
Size() int64
|
||||
Version() string
|
||||
Reason() alpm.PkgReason
|
||||
}
|
||||
|
|
21
print.go
21
print.go
|
@ -9,8 +9,6 @@ import (
|
|||
"github.com/leonelquinteros/gotext"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
|
||||
"github.com/Jguer/go-alpm"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/query"
|
||||
"github.com/Jguer/yay/v10/pkg/settings"
|
||||
|
@ -144,14 +142,8 @@ func PrintInfo(a *rpc.Pkg, extendedInfo bool) {
|
|||
}
|
||||
|
||||
// BiggestPackages prints the name of the ten biggest packages in the system.
|
||||
func biggestPackages(alpmHandle *alpm.Handle) {
|
||||
localDB, err := alpmHandle.LocalDB()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
pkgCache := localDB.PkgCache()
|
||||
pkgS := pkgCache.SortBySize().Slice()
|
||||
func biggestPackages(dbExecutor *db.AlpmExecutor) {
|
||||
pkgS := dbExecutor.BiggestPackages()
|
||||
|
||||
if len(pkgS) < 10 {
|
||||
return
|
||||
|
@ -164,11 +156,8 @@ func biggestPackages(alpmHandle *alpm.Handle) {
|
|||
}
|
||||
|
||||
// localStatistics prints installed packages statistics.
|
||||
func localStatistics(alpmHandle *alpm.Handle) error {
|
||||
info, err := statistics(alpmHandle)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func localStatistics(dbExecutor *db.AlpmExecutor) error {
|
||||
info := statistics(dbExecutor)
|
||||
|
||||
_, remoteNames, err := query.GetPackageNamesBySource(config.Runtime.DBExecutor)
|
||||
if err != nil {
|
||||
|
@ -183,7 +172,7 @@ func localStatistics(alpmHandle *alpm.Handle) error {
|
|||
text.Infoln(gotext.Get("Total Size occupied by packages: %s", cyan(text.Human(info.TotalSize))))
|
||||
fmt.Println(bold(cyan("===========================================")))
|
||||
text.Infoln(gotext.Get("Ten biggest packages:"))
|
||||
biggestPackages(alpmHandle)
|
||||
biggestPackages(dbExecutor)
|
||||
fmt.Println(bold(cyan("===========================================")))
|
||||
|
||||
query.AURInfoPrint(remoteNames, config.RequestSplitN)
|
||||
|
|
30
query.go
30
query.go
|
@ -383,25 +383,21 @@ func hangingPackages(removeOptional bool, alpmHandle *alpm.Handle) (hanging []st
|
|||
}
|
||||
|
||||
// Statistics returns statistics about packages installed in system
|
||||
func statistics(alpmHandle *alpm.Handle) (*struct {
|
||||
func statistics(dbExecutor *db.AlpmExecutor) *struct {
|
||||
Totaln int
|
||||
Expln int
|
||||
TotalSize int64
|
||||
}, error) {
|
||||
var tS int64 // TotalSize
|
||||
var nPkg int
|
||||
var ePkg int
|
||||
} {
|
||||
var totalSize int64
|
||||
localPackages := dbExecutor.LocalPackages()
|
||||
totalInstalls := 0
|
||||
explicitInstalls := 0
|
||||
|
||||
localDB, err := alpmHandle.LocalDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, pkg := range localDB.PkgCache().Slice() {
|
||||
tS += pkg.ISize()
|
||||
nPkg++
|
||||
if pkg.Reason() == 0 {
|
||||
ePkg++
|
||||
for _, pkg := range localPackages {
|
||||
totalSize += pkg.ISize()
|
||||
totalInstalls++
|
||||
if pkg.Reason() == alpm.PkgReasonExplicit {
|
||||
explicitInstalls++
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,8 +406,8 @@ func statistics(alpmHandle *alpm.Handle) (*struct {
|
|||
Expln int
|
||||
TotalSize int64
|
||||
}{
|
||||
nPkg, ePkg, tS,
|
||||
totalInstalls, explicitInstalls, totalSize,
|
||||
}
|
||||
|
||||
return info, err
|
||||
return info
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue