Add source for ppp (pika package processor)
This commit is contained in:
parent
8dec3de438
commit
d659f8bed4
5
src/go.mod
Normal file
5
src/go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module ppp/v2
|
||||
|
||||
go 1.21.0
|
||||
|
||||
require github.com/ulikunitz/xz v0.5.11
|
2
src/go.sum
Normal file
2
src/go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
|
||||
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
74
src/main.go
Normal file
74
src/main.go
Normal file
@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/ulikunitz/xz"
|
||||
)
|
||||
|
||||
func main() {
|
||||
base := os.Args[1]
|
||||
target := os.Args[2]
|
||||
|
||||
basePackages := processFile(base)
|
||||
targetPackages := processFile(target)
|
||||
|
||||
compare(basePackages, targetPackages)
|
||||
}
|
||||
|
||||
func processFile(url string) map[string]string {
|
||||
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
rdr := io.Reader(resp.Body)
|
||||
if strings.HasSuffix(url, ".xz") {
|
||||
r, err := xz.NewReader(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalf("xz error %s", err)
|
||||
}
|
||||
rdr = r
|
||||
}
|
||||
|
||||
packages := make(map[string]string)
|
||||
var currentPackage string
|
||||
scanner := bufio.NewScanner(rdr)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
if line == "" {
|
||||
currentPackage = ""
|
||||
}
|
||||
|
||||
if currentPackage == "" {
|
||||
if strings.HasPrefix(line, "Package: ") {
|
||||
currentPackage = strings.TrimPrefix(line, "Package: ")
|
||||
}
|
||||
} else {
|
||||
if strings.HasPrefix(line, "Version: ") {
|
||||
packages[currentPackage] = strings.TrimPrefix(line, "Version: ")
|
||||
}
|
||||
}
|
||||
}
|
||||
return packages
|
||||
|
||||
}
|
||||
|
||||
func compare(basePackages map[string]string, targetPackages map[string]string) {
|
||||
for pack, version := range targetPackages {
|
||||
if baseVersion, ok := basePackages[pack]; ok {
|
||||
if baseVersion != version {
|
||||
println(pack)
|
||||
}
|
||||
} else {
|
||||
println(pack)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user