Browse Source

Load an index, not a repo

pull/8/head
Daniel Martí 11 years ago
parent
commit
c7ce004912
  1. 22
      cmd/fdroidcl/main.go
  2. 26
      index.go

22
cmd/fdroidcl/main.go

@ -157,12 +157,12 @@ func init() {
}
}
func mustLoadRepo(repoName string) *fdroidcl.Repo {
repo, err := fdroidcl.LoadRepo(repoName)
func mustLoadIndex(repoName string) *fdroidcl.Index {
index, err := fdroidcl.LoadIndex(repoName)
if err != nil {
log.Fatalf("Could not load apps: %v", err)
}
return repo
return index
}
func mustInstalled(device adb.Device) []string {
@ -208,19 +208,19 @@ func main() {
log.Fatalf("Could not update index: %v", err)
}
case "list":
repo := mustLoadRepo(repoName)
printApps(repo.Apps)
index := mustLoadIndex(repoName)
printApps(index.Apps)
case "search":
repo := mustLoadRepo(repoName)
apps := filterAppsSearch(repo.Apps, args)
index := mustLoadIndex(repoName)
apps := filterAppsSearch(index.Apps, args)
printApps(apps)
case "show":
repo := mustLoadRepo(repoName)
index := mustLoadIndex(repoName)
found := make(map[string]*fdroidcl.App, len(args))
for _, appID := range args {
found[appID] = nil
}
for _, app := range repo.Apps {
for _, app := range index.Apps {
_, e := found[app.ID]
if !e {
continue
@ -243,10 +243,10 @@ func main() {
fmt.Printf("%s - %s (%s)\n", device.Id, device.Model, device.Product)
}
case "installed":
repo := mustLoadRepo(repoName)
index := mustLoadIndex(repoName)
device := oneDevice()
installed := mustInstalled(device)
apps := filterAppsInstalled(repo.Apps, installed)
apps := filterAppsInstalled(index.Apps, installed)
printApps(apps)
default:
log.Printf("Unrecognised command '%s'\n\n", cmd)

26
index.go

@ -17,9 +17,17 @@ import (
"strings"
)
// Repo is an F-Droid repository holding apps and apks
type Repo struct {
type Index struct {
Apps []App `xml:"application"`
Repo struct {
Name string `xml:"name,attr"`
PubKey string `xml:"pubkey,attr"`
Timestamp int `xml:"timestamp,attr"`
URL string `xml:"url,attr"`
Version int `xml:"version,attr"`
MaxAge int `xml:"maxage,attr"`
Description string `xml:"description"`
} `repo`
}
type CommaList []string
@ -223,7 +231,7 @@ func (al appList) Len() int { return len(al) }
func (al appList) Swap(i, j int) { al[i], al[j] = al[j], al[i] }
func (al appList) Less(i, j int) bool { return al[i].ID < al[j].ID }
func LoadRepo(repoName string) (*Repo, error) {
func LoadIndex(repoName string) (*Index, error) {
path := indexPath(repoName)
r, err := zip.OpenReader(path)
if err != nil {
@ -247,16 +255,16 @@ func LoadRepo(repoName string) (*Repo, error) {
break
}
var repo Repo
if err := xml.Unmarshal(buf.Bytes(), &repo); err != nil {
var index Index
if err := xml.Unmarshal(buf.Bytes(), &index); err != nil {
return nil, err
}
sort.Sort(appList(repo.Apps))
sort.Sort(appList(index.Apps))
for i := range repo.Apps {
app := &repo.Apps[i]
for i := range index.Apps {
app := &index.Apps[i]
app.prepareData()
}
return &repo, nil
return &index, nil
}

Loading…
Cancel
Save