We now install python-nikola with style
This commit is contained in:
1 parent
1e47622d44
commit
1297ad7c17
4 files changed
+120
-37
No files matched your search
+10
-14
@@ -22,6 +22,9 @@ const SearchMode int = -1
|
||||
// SortMode NumberMenu and Search
|
||||
var SortMode = DownTop
|
||||
|
||||
// NoConfirm ignores prompts.
|
||||
var NoConfirm = false
|
||||
|
||||
// Determines NumberMenu and Search Order
|
||||
const (
|
||||
DownTop = iota
|
||||
@@ -32,13 +35,14 @@ const (
|
||||
func Config() {
|
||||
aur.SortMode = SortMode
|
||||
pac.SortMode = SortMode
|
||||
aur.NoConfirm = NoConfirm
|
||||
pac.NoConfirm = NoConfirm
|
||||
}
|
||||
|
||||
// NumberMenu presents a CLI for selecting packages to install.
|
||||
func NumberMenu(pkgName string, flags []string) (err error) {
|
||||
var num int
|
||||
var numberString string
|
||||
var args []string
|
||||
|
||||
a, nA, err := aur.Search(pkgName, true)
|
||||
if err != nil {
|
||||
@@ -61,8 +65,6 @@ func NumberMenu(pkgName string, flags []string) (err error) {
|
||||
a.PrintSearch(nR)
|
||||
}
|
||||
|
||||
args = append(args, "pacman", "-S")
|
||||
|
||||
fmt.Printf("\x1b[32m%s\x1b[0m\nNumbers:", "Type numbers to install. Separate each number with a space.")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
numberString, err = reader.ReadString('\n')
|
||||
@@ -72,6 +74,7 @@ func NumberMenu(pkgName string, flags []string) (err error) {
|
||||
}
|
||||
|
||||
var aurInstall []aur.Result
|
||||
var repoInstall []string
|
||||
result := strings.Fields(numberString)
|
||||
for _, numS := range result {
|
||||
num, err = strconv.Atoi(numS)
|
||||
@@ -90,22 +93,15 @@ func NumberMenu(pkgName string, flags []string) (err error) {
|
||||
}
|
||||
} else {
|
||||
if aur.SortMode == aur.DownTop {
|
||||
args = append(args, r[nR-num-1].Name)
|
||||
repoInstall = append(repoInstall, r[nR-num-1].Name)
|
||||
} else {
|
||||
args = append(args, r[num].Name)
|
||||
repoInstall = append(repoInstall, r[num].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, flags...)
|
||||
|
||||
if len(args) > 2 {
|
||||
var cmd *exec.Cmd
|
||||
cmd = exec.Command("sudo", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if len(repoInstall) != 0 {
|
||||
pac.Install(repoInstall, flags)
|
||||
}
|
||||
|
||||
for _, aurpkg := range aurInstall {
|
||||
|
||||
+66
-18
@@ -23,6 +23,9 @@ const MakepkgBin string = "/usr/bin/makepkg"
|
||||
// SearchMode is search without numbers.
|
||||
const SearchMode int = -1
|
||||
|
||||
// NoConfirm ignores prompts.
|
||||
var NoConfirm = false
|
||||
|
||||
// SortMode determines top down package or down top package display
|
||||
var SortMode = DownTop
|
||||
|
||||
@@ -218,7 +221,7 @@ func Upgrade(baseDir string, flags []string) error {
|
||||
}
|
||||
|
||||
// Install updated packages
|
||||
if !NoConfirm(flags) {
|
||||
if !NoConfirm {
|
||||
fmt.Println("\x1b[1m\x1b[32m==> Proceed with upgrade\x1b[0m\x1b[1m (Y/n)\x1b[0m")
|
||||
var response string
|
||||
fmt.Scanln(&response)
|
||||
@@ -265,7 +268,7 @@ func (a *Result) Install(baseDir string, flags []string) (err error) {
|
||||
dir.WriteString(a.Name)
|
||||
dir.WriteString("/")
|
||||
|
||||
if !NoConfirm(flags) {
|
||||
if !NoConfirm {
|
||||
fmt.Println("\x1b[1m\x1b[32m==> Edit PKGBUILD?\x1b[0m\x1b[1m (y/N)\x1b[0m")
|
||||
fmt.Scanln(&response)
|
||||
if strings.ContainsAny(response, "y & Y") {
|
||||
@@ -281,19 +284,42 @@ func (a *Result) Install(baseDir string, flags []string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
printDependencies(aurDeps, repoDeps)
|
||||
if !NoConfirm && (len(aurDeps) != 0 || len(repoDeps) != 0) {
|
||||
fmt.Println("\x1b[1m\x1b[32m==> Continue?\x1b[0m\x1b[1m (Y/n)\x1b[0m")
|
||||
fmt.Scanln(&response)
|
||||
if strings.ContainsAny(response, "n & N") {
|
||||
return fmt.Errorf("user did not like the dependencies")
|
||||
}
|
||||
}
|
||||
|
||||
aurQ, n, err := MultiInfo(aurDeps)
|
||||
if n != len(aurDeps) {
|
||||
fmt.Printf("Unable to find a dependency on AUR")
|
||||
missingDeps(aurDeps, aurQ)
|
||||
if !NoConfirm {
|
||||
fmt.Println("\x1b[1m\x1b[32m==> Continue?\x1b[0m\x1b[1m (Y/n)\x1b[0m")
|
||||
fmt.Scanln(&response)
|
||||
if strings.ContainsAny(response, "n & N") {
|
||||
return fmt.Errorf("unable to install dependencies")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle AUR dependencies first
|
||||
for _, dep := range aurQ {
|
||||
dep.Install(baseDir, []string{"--asdeps"})
|
||||
errA := dep.Install(baseDir, []string{"--asdeps", "--noconfirm"})
|
||||
if errA != nil {
|
||||
return errA
|
||||
}
|
||||
}
|
||||
|
||||
// Repo dependencies
|
||||
if len(repoDeps) != 0 {
|
||||
pacman.Install(repoDeps, []string{"--asdeps", "--needed"})
|
||||
errR := pacman.Install(repoDeps, []string{"--asdeps", "--noconfirm"})
|
||||
if errR != nil {
|
||||
pacman.CleanRemove(aurDeps)
|
||||
return errR
|
||||
}
|
||||
}
|
||||
|
||||
err = os.Chdir(dir.String())
|
||||
@@ -314,6 +340,41 @@ func (a *Result) Install(baseDir string, flags []string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func printDependencies(aurDeps []string, repoDeps []string) {
|
||||
if len(repoDeps) != 0 {
|
||||
fmt.Print("\x1b[1m\x1b[32m==> Repository dependencies: \x1b[0m")
|
||||
for _, repoD := range repoDeps {
|
||||
fmt.Print("\x1b[33m", repoD, " \x1b[0m")
|
||||
}
|
||||
fmt.Print("\n")
|
||||
|
||||
}
|
||||
if len(repoDeps) != 0 {
|
||||
fmt.Print("\x1b[1m\x1b[32m==> AUR dependencies: \x1b[0m")
|
||||
for _, aurD := range aurDeps {
|
||||
fmt.Print("\x1b[33m", aurD, " \x1b[0m")
|
||||
}
|
||||
fmt.Print("\n")
|
||||
}
|
||||
}
|
||||
|
||||
func missingDeps(aurDeps []string, aurQ Query) {
|
||||
for _, depName := range aurDeps {
|
||||
found := false
|
||||
for _, dep := range aurQ {
|
||||
if dep.Name == depName {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
fmt.Println("\x1b[31mUnable to find", depName, "in AUR\x1b[0m")
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Dependencies returns package dependencies not installed belonging to AUR
|
||||
func (a *Result) Dependencies() (aur []string, repo []string, err error) {
|
||||
var q Query
|
||||
@@ -331,16 +392,3 @@ func (a *Result) Dependencies() (aur []string, repo []string, err error) {
|
||||
aur, repo, err = pacman.OutofRepo(append(q[0].MakeDepends, q[0].Depends...))
|
||||
return
|
||||
}
|
||||
|
||||
// NoConfirm returns true if prompts should be ignored
|
||||
func NoConfirm(flags []string) bool {
|
||||
noconf := false
|
||||
for _, flag := range flags {
|
||||
if strings.Contains(flag, "noconfirm") {
|
||||
noconf = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return noconf
|
||||
}
|
||||
+4
-1
@@ -24,7 +24,7 @@ func usage() {
|
||||
yay -Qstats displays system information
|
||||
|
||||
New options:
|
||||
--topdown shows repository's packages first and then aur's
|
||||
--topdown shows repository's packages first and then aur's
|
||||
--downtop shows aur's packages first and then repository's
|
||||
--noconfirm skip user input on package install
|
||||
`)
|
||||
@@ -50,6 +50,9 @@ func parser() (op string, options []string, packages []string, err error) {
|
||||
yay.SortMode = yay.TopDown
|
||||
} else if arg == "--downtop" {
|
||||
yay.SortMode = yay.DownTop
|
||||
} else if arg == "--noconfirm" {
|
||||
yay.NoConfirm = true
|
||||
options = append(options, arg)
|
||||
} else {
|
||||
options = append(options, arg)
|
||||
}
|
||||
|
||||
+40
-4
@@ -25,6 +25,9 @@ type Result struct {
|
||||
// PacmanConf describes the default pacman config file
|
||||
const PacmanConf string = "/etc/pacman.conf"
|
||||
|
||||
// NoConfirm ignores prompts.
|
||||
var NoConfirm = false
|
||||
|
||||
// SortMode NumberMenu and Search
|
||||
var SortMode = DownTop
|
||||
|
||||
@@ -256,10 +259,22 @@ func OutofRepo(toCheck []string) (aur []string, repo []string, err error) {
|
||||
return c == '>' || c == '<' || c == '=' || c == ' '
|
||||
}
|
||||
|
||||
// First, Check if they're provided by package name.
|
||||
toCheckLoop:
|
||||
for _, dep := range toCheck {
|
||||
field := strings.FieldsFunc(dep, f)
|
||||
|
||||
for _, checkR := range repo {
|
||||
if field[0] == checkR {
|
||||
continue toCheckLoop
|
||||
}
|
||||
}
|
||||
|
||||
for _, checkA := range aur {
|
||||
if field[0] == checkA {
|
||||
continue toCheckLoop
|
||||
}
|
||||
}
|
||||
|
||||
// Check if dep is installed
|
||||
_, err = localDb.PkgByName(field[0])
|
||||
if err == nil {
|
||||
@@ -269,6 +284,7 @@ func OutofRepo(toCheck []string) (aur []string, repo []string, err error) {
|
||||
found := false
|
||||
Loop:
|
||||
for _, db := range dbList.Slice() {
|
||||
// First, Check if they're provided by package name.
|
||||
_, err = db.PkgByName(field[0])
|
||||
if err == nil {
|
||||
found = true
|
||||
@@ -304,10 +320,30 @@ func Install(pkgName []string, flags []string) (err error) {
|
||||
|
||||
var cmd *exec.Cmd
|
||||
var args []string
|
||||
args = append(args, "pacman")
|
||||
args = append(args, "-S")
|
||||
args = append(args, "pacman", "-S")
|
||||
args = append(args, pkgName...)
|
||||
if len(flags) != 0 {
|
||||
args = append(args, flags...)
|
||||
}
|
||||
|
||||
cmd = exec.Command("sudo", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Run()
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanRemove sends a full removal command to pacman with the pkgName slice
|
||||
func CleanRemove(pkgName []string) (err error) {
|
||||
if len(pkgName) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var cmd *exec.Cmd
|
||||
var args []string
|
||||
args = append(args, "pacman", "-Rnsc")
|
||||
args = append(args, pkgName...)
|
||||
args = append(args, flags...)
|
||||
|
||||
cmd = exec.Command("sudo", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
Reference in new issue
Block a user