Browse Source

Move common functions to files that make more sense

pull/8/head
Daniel Martí 11 years ago
parent
commit
1ab44f4b2a
  1. 14
      cmd/fdroidcl/devices.go
  2. 14
      cmd/fdroidcl/installed.go
  3. 23
      cmd/fdroidcl/search.go
  4. 22
      cmd/fdroidcl/update.go

14
cmd/fdroidcl/devices.go

@ -39,3 +39,17 @@ func startAdbIfNeeded() {
log.Fatalf("Could not start ADB server: %v", err)
}
}
func oneDevice() adb.Device {
devices, err := adb.Devices()
if err != nil {
log.Fatalf("Could not get devices: %v", err)
}
if len(devices) == 0 {
log.Fatalf("No devices found")
}
if len(devices) > 1 {
log.Fatalf("Too many devices found")
}
return devices[0]
}

14
cmd/fdroidcl/installed.go

@ -28,20 +28,6 @@ func runInstalled(args []string) {
printApps(apps)
}
func oneDevice() adb.Device {
devices, err := adb.Devices()
if err != nil {
log.Fatalf("Could not get devices: %v", err)
}
if len(devices) == 0 {
log.Fatalf("No devices found")
}
if len(devices) > 1 {
log.Fatalf("Too many devices found")
}
return devices[0]
}
func mustInstalled(device adb.Device) []string {
installed, err := device.Installed()
if err != nil {

23
cmd/fdroidcl/search.go

@ -5,8 +5,6 @@ package main
import (
"fmt"
"log"
"os"
"regexp"
"strings"
@ -38,27 +36,6 @@ func runSearch(args []string) {
}
}
func mustLoadIndex() *fdroidcl.Index {
p := indexPath(repoName)
f, err := os.Open(p)
if err != nil {
log.Fatalf("Could not open index file: %v", err)
}
stat, err := f.Stat()
if err != nil {
log.Fatalf("Could not stat index file: %v", err)
}
//pubkey, err := hex.DecodeString(repoPubkey)
//if err != nil {
// log.Fatalf("Could not decode public key: %v", err)
//}
index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil)
if err != nil {
log.Fatalf("Could not load index: %v", err)
}
return index
}
func filterAppsSearch(apps []fdroidcl.App, terms []string) []fdroidcl.App {
regexes := make([]*regexp.Regexp, len(terms))
for i, term := range terms {

22
cmd/fdroidcl/update.go

@ -13,6 +13,7 @@ import (
"path/filepath"
"github.com/mvdan/appdir"
"github.com/mvdan/fdroidcl"
)
var cmdUpdate = &Command{
@ -97,3 +98,24 @@ func appSubdir(appdir string) string {
}
return p
}
func mustLoadIndex() *fdroidcl.Index {
p := indexPath(repoName)
f, err := os.Open(p)
if err != nil {
log.Fatalf("Could not open index file: %v", err)
}
stat, err := f.Stat()
if err != nil {
log.Fatalf("Could not stat index file: %v", err)
}
//pubkey, err := hex.DecodeString(repoPubkey)
//if err != nil {
// log.Fatalf("Could not decode public key: %v", err)
//}
index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil)
if err != nil {
log.Fatalf("Could not load index: %v", err)
}
return index
}

Loading…
Cancel
Save