Add new pkg/client/android, to clean up Android API gunk from pkg/client's godoc.

This is just a start. AndroidStatsTransport and AndroidStatusReceiver and most (all?)
of pkg/client/android.go should migrate too.

Change-Id: Id4140730bbdd218fdf7ba7cedc7870ce5164e06c
This commit is contained in:
Brad Fitzpatrick 2013-10-22 07:37:08 -07:00
parent cf15b2be90
commit 2040d2e442
4 changed files with 58 additions and 25 deletions

View File

@ -19,7 +19,7 @@ limitations under the License.
package main
import (
"camlistore.org/pkg/client"
"camlistore.org/pkg/client/android"
)
type allStats struct {
@ -35,7 +35,7 @@ func printAndroidCamputStatus(t *TreeUpload) {
}
lastStatBroadcast = bcast
client.Androidf("STATS nfile=%d nbyte=%d skfile=%d skbyte=%d upfile=%d upbyte=%d\n",
android.Printf("STATS nfile=%d nbyte=%d skfile=%d skbyte=%d upfile=%d upbyte=%d\n",
t.total.files, t.total.bytes,
t.skipped.files, t.skipped.bytes,
t.uploaded.files, t.uploaded.bytes)

View File

@ -40,6 +40,7 @@ import (
"camlistore.org/pkg/blobserver"
statspkg "camlistore.org/pkg/blobserver/stats"
"camlistore.org/pkg/client"
"camlistore.org/pkg/client/android"
"camlistore.org/pkg/cmdmain"
"camlistore.org/pkg/schema"
)
@ -91,7 +92,7 @@ func init() {
cmd.havecache = true
cmd.statcache = true
}
if client.AndroidOutput() {
if android.IsChild() {
flags.BoolVar(&cmd.argsFromInput, "stdinargs", false, "If true, filenames to upload are sent one-per-line on stdin. EOF means to quit the process with exit status 0.")
}
flagCacheLog = flags.Bool("logcache", false, "log caching details")
@ -412,7 +413,7 @@ func (up *Uploader) statReceiver(n *node) blobserver.StatReceiver {
// see TODO in cmd/camput/uploader.go
statReceiver = up.Client
}
if client.AndroidOutput() && n != nil && n.fi.Mode()&os.ModeType == 0 {
if android.IsChild() && n != nil && n.fi.Mode()&os.ModeType == 0 {
return client.AndroidStatusReceiver{Sr: statReceiver, Path: n.fullPath}
}
return statReceiver
@ -929,7 +930,7 @@ func (t *TreeUpload) run() {
var lastStat, lastUpload string
dumpStats := func() {
if client.AndroidOutput() {
if android.IsChild() {
printAndroidCamputStatus(t)
return
}

View File

@ -32,10 +32,10 @@ import (
"os/exec"
"path/filepath"
"regexp"
"strconv"
"sync"
"camlistore.org/pkg/blob"
"camlistore.org/pkg/client/android"
"camlistore.org/pkg/blobserver"
"camlistore.org/pkg/schema"
)
@ -73,7 +73,7 @@ func (ni *namedInt) Incr(delta int64) {
ni.val += delta
nv := ni.val
ni.Unlock()
Androidf("STAT %s %d\n", ni.name, nv)
android.Printf("STAT %s %d\n", ni.name, nv)
}
var (
@ -235,23 +235,10 @@ func androidTLSConfig() (*tls.Config, error) {
return cfg, nil
}
// TODO(mpl): distinguish CAMPUT, CAMGET, etc
var androidOutput, _ = strconv.ParseBool(os.Getenv("CAMPUT_ANDROID_OUTPUT"))
func AndroidOutput() bool {
return androidOutput
}
var androidOutMu sync.Mutex
func Androidf(format string, args ...interface{}) {
androidOutMu.Lock()
defer androidOutMu.Unlock()
fmt.Printf(format, args...)
}
// NoteFileUploaded is a hook for camput to report that a file
// was uploaded. TODO: move this to pkg/client/android probably.
func NoteFileUploaded(fullPath string, uploaded bool) {
if !AndroidOutput() {
if !android.IsChild() {
return
}
if uploaded {
@ -259,7 +246,7 @@ func NoteFileUploaded(fullPath string, uploaded bool) {
} else {
statFileExisted.Incr(1)
}
Androidf("FILE_UPLOADED %s\n", fullPath)
android.Printf("FILE_UPLOADED %s\n", fullPath)
}
// androidStatusReceiver is a blobserver.StatReceiver wrapper that
@ -271,7 +258,7 @@ type AndroidStatusReceiver struct {
}
func (asr AndroidStatusReceiver) noteChunkOnServer(sb blob.SizedRef) {
Androidf("CHUNK_UPLOADED %d %s %s\n", sb.Size, sb.Ref, asr.Path)
android.Printf("CHUNK_UPLOADED %d %s %s\n", sb.Size, sb.Ref, asr.Path)
}
func (asr AndroidStatusReceiver) ReceiveBlob(blob blob.Ref, source io.Reader) (blob.SizedRef, error) {

View File

@ -0,0 +1,45 @@
/*
Copyright 2013 The Camlistore Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package android contains code specific to running the Camlistore client
// code as a child process on Android. This removes ugly API from the
// client package itself.
package android
import (
"fmt"
"strconv"
"os"
"sync"
)
// TODO(mpl): distinguish CAMPUT, CAMGET, etc
var androidOutput, _ = strconv.ParseBool(os.Getenv("CAMPUT_ANDROID_OUTPUT"))
// IsChild reports whether this process is running as an Android
// child process and should report its output in the form that the
// Android uploader app expects.
func IsChild() bool {
return androidOutput
}
var androidOutMu sync.Mutex
func Printf(format string, args ...interface{}) {
androidOutMu.Lock()
defer androidOutMu.Unlock()
fmt.Printf(format, args...)
}