mirror of
https://github.com/Jguer/yay
synced 2024-09-01 14:18:39 +00:00
![morganamilo](/assets/img/avatar_default.png)
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.
266 lines
7 KiB
Go
266 lines
7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
rpc "github.com/mikkeloscar/aur"
|
|
)
|
|
|
|
// Human returns results in Human readable format.
|
|
func human(size int64) string {
|
|
floatsize := float32(size)
|
|
units := [...]string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
|
|
for _, unit := range units {
|
|
if floatsize < 1024 {
|
|
return fmt.Sprintf("%.1f %sB", floatsize, unit)
|
|
}
|
|
floatsize /= 1024
|
|
}
|
|
return fmt.Sprintf("%d%s", size, "B")
|
|
}
|
|
|
|
// PrintSearch handles printing search results in a given format
|
|
func (q aurQuery) printSearch(start int) {
|
|
localDb, _ := alpmHandle.LocalDb()
|
|
|
|
for i, res := range q {
|
|
var toprint string
|
|
if config.SearchMode == NumberMenu {
|
|
if config.SortMode == BottomUp {
|
|
toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", len(q)+start-i-1)
|
|
} else {
|
|
toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", start+i)
|
|
}
|
|
} else if config.SearchMode == Minimal {
|
|
fmt.Println(res.Name)
|
|
continue
|
|
}
|
|
toprint += fmt.Sprintf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m(%d) ", "aur", res.Name, res.Version, res.NumVotes)
|
|
if res.Maintainer == "" {
|
|
toprint += fmt.Sprintf("\x1b[31;40m(Orphaned)\x1b[0m ")
|
|
}
|
|
|
|
if res.OutOfDate != 0 {
|
|
toprint += fmt.Sprintf("\x1b[31;40m(Out-of-date)\x1b[0m ")
|
|
}
|
|
|
|
if _, err := localDb.PkgByName(res.Name); err == nil {
|
|
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
|
|
}
|
|
toprint += "\n " + res.Description
|
|
fmt.Println(toprint)
|
|
}
|
|
}
|
|
|
|
//PrintSearch receives a RepoSearch type and outputs pretty text.
|
|
func (s repoQuery) printSearch() {
|
|
for i, res := range s {
|
|
var toprint string
|
|
if config.SearchMode == NumberMenu {
|
|
if config.SortMode == BottomUp {
|
|
toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", len(s)-i)
|
|
} else {
|
|
toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", i+1)
|
|
}
|
|
} else if config.SearchMode == Minimal {
|
|
fmt.Println(res.Name())
|
|
continue
|
|
}
|
|
toprint += fmt.Sprintf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m",
|
|
res.DB().Name(), res.Name(), res.Version())
|
|
|
|
if len(res.Groups().Slice()) != 0 {
|
|
toprint += fmt.Sprint(res.Groups().Slice(), " ")
|
|
}
|
|
|
|
localDb, err := alpmHandle.LocalDb()
|
|
if err == nil {
|
|
if _, err = localDb.PkgByName(res.Name()); err == nil {
|
|
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
|
|
}
|
|
}
|
|
|
|
toprint += "\n " + res.Description()
|
|
fmt.Println(toprint)
|
|
}
|
|
}
|
|
|
|
func printDeps(repoDeps []string, aurDeps []string) {
|
|
if len(repoDeps) != 0 {
|
|
fmt.Print("\x1b[1;32m==> Repository dependencies: \x1b[0m")
|
|
for _, repoD := range repoDeps {
|
|
fmt.Print("\x1b[33m", repoD, " \x1b[0m")
|
|
}
|
|
fmt.Print("\n")
|
|
|
|
}
|
|
if len(aurDeps) != 0 {
|
|
fmt.Print("\x1b[1;32m==> AUR dependencies: \x1b[0m")
|
|
for _, aurD := range aurDeps {
|
|
fmt.Print("\x1b[33m", aurD, " \x1b[0m")
|
|
}
|
|
fmt.Print("\n")
|
|
}
|
|
}
|
|
|
|
// PrintInfo prints package info like pacman -Si.
|
|
func PrintInfo(a *rpc.Pkg) {
|
|
fmt.Println("\x1b[1;37mRepository :\x1b[0m", "aur")
|
|
fmt.Println("\x1b[1;37mName :\x1b[0m", a.Name)
|
|
fmt.Println("\x1b[1;37mVersion :\x1b[0m", a.Version)
|
|
fmt.Println("\x1b[1;37mDescription :\x1b[0m", a.Description)
|
|
if a.URL != "" {
|
|
fmt.Println("\x1b[1;37mURL :\x1b[0m", a.URL)
|
|
} else {
|
|
fmt.Println("\x1b[1;37mURL :\x1b[0m", "None")
|
|
}
|
|
fmt.Println("\x1b[1;37mLicenses :\x1b[0m", strings.Join(a.License, " "))
|
|
|
|
// if len(a.Provides) != 0 {
|
|
// fmt.Println("\x1b[1;37mProvides :\x1b[0m",
|
|
// Strings.join(a.Provides, " "))
|
|
// } else {
|
|
// fmt.Println("\x1b[1;37mProvides :\x1b[0m", "None")
|
|
// }
|
|
|
|
if len(a.Depends) != 0 {
|
|
fmt.Println("\x1b[1;37mDepends On :\x1b[0m", strings.Join(a.Depends, " "))
|
|
} else {
|
|
fmt.Println("\x1b[1;37mDepends On :\x1b[0m", "None")
|
|
}
|
|
|
|
if len(a.MakeDepends) != 0 {
|
|
fmt.Println("\x1b[1;37mMake depends On :\x1b[0m", strings.Join(a.MakeDepends, " "))
|
|
} else {
|
|
fmt.Println("\x1b[1;37mMake depends On :\x1b[0m", "None")
|
|
}
|
|
|
|
if len(a.OptDepends) != 0 {
|
|
fmt.Println("\x1b[1;37mOptional Deps :\x1b[0m", strings.Join(a.OptDepends, " "))
|
|
} else {
|
|
fmt.Println("\x1b[1;37mOptional Deps :\x1b[0m", "None")
|
|
}
|
|
|
|
if len(a.Conflicts) != 0 {
|
|
fmt.Println("\x1b[1;37mConflicts With :\x1b[0m", strings.Join(a.Conflicts, " "))
|
|
} else {
|
|
fmt.Println("\x1b[1;37mConflicts With :\x1b[0m", "None")
|
|
}
|
|
|
|
if a.Maintainer != "" {
|
|
fmt.Println("\x1b[1;37mMaintainer :\x1b[0m", a.Maintainer)
|
|
} else {
|
|
fmt.Println("\x1b[1;37mMaintainer :\x1b[0m", "None")
|
|
}
|
|
|
|
fmt.Println("\x1b[1;37mVotes :\x1b[0m", a.NumVotes)
|
|
fmt.Println("\x1b[1;37mPopularity :\x1b[0m", a.Popularity)
|
|
|
|
if a.OutOfDate != 0 {
|
|
fmt.Println("\x1b[1;37mOut-of-date :\x1b[0m", "Yes")
|
|
}
|
|
|
|
fmt.Println()
|
|
}
|
|
|
|
// BiggestPackages prints the name of the ten biggest packages in the system.
|
|
func biggestPackages() {
|
|
localDb, err := alpmHandle.LocalDb()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
pkgCache := localDb.PkgCache()
|
|
pkgS := pkgCache.SortBySize().Slice()
|
|
|
|
if len(pkgS) < 10 {
|
|
return
|
|
}
|
|
|
|
for i := 0; i < 10; i++ {
|
|
fmt.Printf("%s: \x1B[0;33m%s\x1B[0m\n", pkgS[i].Name(), human(pkgS[i].ISize()))
|
|
}
|
|
// Could implement size here as well, but we just want the general idea
|
|
}
|
|
|
|
// localStatistics prints installed packages statistics.
|
|
func localStatistics() error {
|
|
info, err := statistics()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, _, _, remoteNames, err := filterPackages()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("\n Yay version r%s\n", version)
|
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
|
fmt.Printf("\x1B[1;32mTotal installed packages: \x1B[0;33m%d\x1B[0m\n", info.Totaln)
|
|
fmt.Printf("\x1B[1;32mTotal foreign installed packages: \x1B[0;33m%d\x1B[0m\n", len(remoteNames))
|
|
fmt.Printf("\x1B[1;32mExplicitly installed packages: \x1B[0;33m%d\x1B[0m\n", info.Expln)
|
|
fmt.Printf("\x1B[1;32mTotal Size occupied by packages: \x1B[0;33m%s\x1B[0m\n", human(info.TotalSize))
|
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
|
fmt.Println("\x1B[1;32mTen biggest packages\x1B[0m")
|
|
biggestPackages()
|
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
|
|
|
var q aurQuery
|
|
var j int
|
|
for i := len(remoteNames); i != 0; i = j {
|
|
j = i - config.RequestSplitN
|
|
if j < 0 {
|
|
j = 0
|
|
}
|
|
qtemp, err := rpc.Info(remoteNames[j:i])
|
|
q = append(q, qtemp...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
var outcast []string
|
|
for _, s := range remoteNames {
|
|
found := false
|
|
for _, i := range q {
|
|
if s == i.Name {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
outcast = append(outcast, s)
|
|
}
|
|
}
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, res := range q {
|
|
if res.Maintainer == "" {
|
|
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is orphaned.\x1b[0m\n", res.Name)
|
|
}
|
|
if res.OutOfDate != 0 {
|
|
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is out-of-date in AUR.\x1b[0m\n", res.Name)
|
|
}
|
|
}
|
|
|
|
for _, res := range outcast {
|
|
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is not available in AUR.\x1b[0m\n", res)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
//todo make pretty
|
|
func printMissing(missing stringSet) {
|
|
fmt.Print("Packages not found in repos or aur:")
|
|
for pkg := range missing {
|
|
fmt.Print(" ", pkg)
|
|
}
|
|
fmt.Println()
|
|
}
|