Move stuff that is not samples out of samples directory (#1943)

* Move samples/go/*perf-reg to go/perf/

They aren't really samples.

* Move samples/go/util/check_error.go to go/d

* Remove samples/go/util/client_flags.go - unused

* remove httpcache.go - unused

* Remove samples/go/util/rungen.go - no generated code here anymore

* move NomsValueFromJSON to go/util/jsontonoms
This commit is contained in:
Aaron Boodman
2016-07-01 11:04:17 -07:00
committed by GitHub
parent fcca02d6b0
commit 2386afc7fb
31 changed files with 52 additions and 164 deletions

View File

@@ -12,9 +12,9 @@ import (
"os"
"github.com/attic-labs/noms/cmd/noms-diff/diff"
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/util/outputpager"
"github.com/attic-labs/noms/samples/go/util"
)
const (
@@ -41,20 +41,20 @@ func main() {
}
if len(flag.Args()) != 2 {
util.CheckErrorNoUsage(errors.New("Expected exactly two arguments"))
d.CheckErrorNoUsage(errors.New("Expected exactly two arguments"))
}
db1, value1, err := spec.GetPath(flag.Arg(0))
util.CheckErrorNoUsage(err)
d.CheckErrorNoUsage(err)
if value1 == nil {
util.CheckErrorNoUsage(fmt.Errorf("Object not found: %s", flag.Arg(0)))
d.CheckErrorNoUsage(fmt.Errorf("Object not found: %s", flag.Arg(0)))
}
defer db1.Close()
db2, value2, err := spec.GetPath(flag.Arg(1))
util.CheckErrorNoUsage(err)
d.CheckErrorNoUsage(err)
if value2 == nil {
util.CheckErrorNoUsage(fmt.Errorf("Object not found: %s", flag.Arg(1)))
d.CheckErrorNoUsage(fmt.Errorf("Object not found: %s", flag.Arg(1)))
}
defer db2.Close()

View File

@@ -9,9 +9,9 @@ import (
"fmt"
"os"
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/samples/go/util"
)
func main() {
@@ -28,15 +28,15 @@ func main() {
if *toDelete != "" {
set, err := spec.GetDataset(*toDelete)
util.CheckError(err)
d.CheckError(err)
oldCommitRef, errBool := set.MaybeHeadRef()
if !errBool {
util.CheckError(fmt.Errorf("Dataset %v not found", set.ID()))
d.CheckError(fmt.Errorf("Dataset %v not found", set.ID()))
}
store, err := set.Database().Delete(set.ID())
util.CheckError(err)
d.CheckError(err)
defer store.Close()
fmt.Printf("Deleted dataset %v (was %v)\n\n", set.ID(), oldCommitRef.TargetHash().String())
@@ -47,7 +47,7 @@ func main() {
}
store, err := spec.GetDatabase(flag.Arg(0))
util.CheckError(err)
d.CheckError(err)
defer store.Close()
store.Datasets().IterAll(func(k, v types.Value) {

View File

@@ -22,7 +22,6 @@ import (
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/go/util/orderedparallel"
"github.com/attic-labs/noms/go/util/outputpager"
"github.com/attic-labs/noms/samples/go/util"
"github.com/mgutz/ansi"
)
@@ -57,26 +56,26 @@ func main() {
}
if len(flag.Args()) != 1 {
util.CheckError(errors.New("expected exactly one argument"))
d.CheckError(errors.New("expected exactly one argument"))
}
useColor = shouldUseColor()
database, value, err := spec.GetPath(flag.Arg(0))
if err != nil {
util.CheckErrorNoUsage(err)
d.CheckErrorNoUsage(err)
}
defer database.Close()
if value == nil {
util.CheckErrorNoUsage(fmt.Errorf("Object not found: %s", flag.Arg(0)))
d.CheckErrorNoUsage(fmt.Errorf("Object not found: %s", flag.Arg(0)))
}
waitChan := outputpager.PageOutput(!*outputpager.NoPager)
origCommit, ok := value.(types.Struct)
if !ok || !origCommit.Type().Equals(datas.CommitType()) {
util.CheckError(fmt.Errorf("%s does not reference a Commit object", flag.Arg(0)))
d.CheckError(fmt.Errorf("%s does not reference a Commit object", flag.Arg(0)))
}
iter := NewCommitIterator(database, origCommit)

View File

@@ -8,11 +8,11 @@ import (
"fmt"
"testing"
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/dataset"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/samples/go/test_util"
"github.com/attic-labs/noms/samples/go/util"
"github.com/attic-labs/testify/assert"
"github.com/attic-labs/testify/suite"
)
@@ -31,7 +31,7 @@ func (testExiter) Exit(code int) {
}
func TestNomsShow(t *testing.T) {
util.UtilExiter = testExiter{}
d.UtilExiter = testExiter{}
suite.Run(t, &nomsShowTestSuite{})
}

View File

@@ -15,7 +15,6 @@ import (
"github.com/attic-labs/noms/go/datas"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/util/profile"
"github.com/attic-labs/noms/samples/go/util"
)
var (
@@ -39,7 +38,7 @@ func main() {
}
cs, err := spec.GetChunkStore(flag.Arg(0))
util.CheckError(err)
d.CheckError(err)
server := datas.NewRemoteDatabaseServer(cs, *port)
// Shutdown server gracefully so that profile may be written

View File

@@ -11,10 +11,10 @@ import (
"fmt"
"os"
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/go/util/outputpager"
"github.com/attic-labs/noms/samples/go/util"
)
var (
@@ -36,11 +36,11 @@ func main() {
}
if len(flag.Args()) != 1 {
util.CheckErrorNoUsage(errors.New("expected exactly one argument"))
d.CheckErrorNoUsage(errors.New("expected exactly one argument"))
}
database, value, err := spec.GetPath(flag.Arg(0))
util.CheckErrorNoUsage(err)
d.CheckErrorNoUsage(err)
if value == nil {
fmt.Fprintf(os.Stderr, "Object not found: %s\n", flag.Arg(0))

View File

@@ -16,7 +16,6 @@ import (
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/go/util/profile"
"github.com/attic-labs/noms/samples/go/util"
)
var (
@@ -38,15 +37,15 @@ func main() {
flag.Parse()
if flag.NArg() != 2 {
util.CheckError(errors.New("expected a source object and destination dataset"))
d.CheckError(errors.New("expected a source object and destination dataset"))
}
sourceStore, sourceObj, err := spec.GetPath(flag.Arg(0))
util.CheckError(err)
d.CheckError(err)
defer sourceStore.Close()
sinkDataset, err := spec.GetDataset(flag.Arg(1))
util.CheckError(err)
d.CheckError(err)
defer sinkDataset.Database().Close()
err = d.Try(func() {

View File

@@ -2,7 +2,7 @@
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package util
package d
import (
"flag"

View File

@@ -2,7 +2,7 @@
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package util
package jsontonoms
import (
"reflect"

View File

@@ -2,13 +2,12 @@
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package test_util
package jsontonoms
import (
"testing"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/samples/go/util"
"github.com/attic-labs/testify/suite"
)
@@ -21,23 +20,23 @@ type LibTestSuite struct {
}
func (suite *LibTestSuite) TestPrimitiveTypes() {
suite.EqualValues(types.String("expected"), util.NomsValueFromDecodedJSON("expected", false))
suite.EqualValues(types.Bool(false), util.NomsValueFromDecodedJSON(false, false))
suite.EqualValues(types.Number(1.7), util.NomsValueFromDecodedJSON(1.7, false))
suite.False(util.NomsValueFromDecodedJSON(1.7, false).Equals(types.Bool(true)))
suite.EqualValues(types.String("expected"), NomsValueFromDecodedJSON("expected", false))
suite.EqualValues(types.Bool(false), NomsValueFromDecodedJSON(false, false))
suite.EqualValues(types.Number(1.7), NomsValueFromDecodedJSON(1.7, false))
suite.False(NomsValueFromDecodedJSON(1.7, false).Equals(types.Bool(true)))
}
func (suite *LibTestSuite) TestCompositeTypes() {
// [false true]
suite.EqualValues(
types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
util.NomsValueFromDecodedJSON([]interface{}{false, true}, false))
NomsValueFromDecodedJSON([]interface{}{false, true}, false))
// [[false true]]
suite.EqualValues(
types.NewList().Append(
types.NewList().Append(types.Bool(false)).Append(types.Bool(true))),
util.NomsValueFromDecodedJSON([]interface{}{[]interface{}{false, true}}, false))
NomsValueFromDecodedJSON([]interface{}{[]interface{}{false, true}}, false))
// {"string": "string",
// "list": [false true],
@@ -52,7 +51,7 @@ func (suite *LibTestSuite) TestCompositeTypes() {
types.NewMap(
types.String("nested"),
types.String("string")))
o := util.NomsValueFromDecodedJSON(map[string]interface{}{
o := NomsValueFromDecodedJSON(map[string]interface{}{
"string": "string",
"list": []interface{}{false, true},
"map": map[string]interface{}{"nested": "string"},
@@ -73,7 +72,7 @@ func (suite *LibTestSuite) TestCompositeTypeWithStruct() {
"nested": types.String("string"),
}),
})
o := util.NomsValueFromDecodedJSON(map[string]interface{}{
o := NomsValueFromDecodedJSON(map[string]interface{}{
"string": "string",
"list": []interface{}{false, true},
"struct": map[string]interface{}{"nested": "string"},
@@ -83,5 +82,5 @@ func (suite *LibTestSuite) TestCompositeTypeWithStruct() {
}
func (suite *LibTestSuite) TestPanicOnUnsupportedType() {
suite.Panics(func() { util.NomsValueFromDecodedJSON(map[int]string{1: "one"}, false) }, "Should panic on map[int]string!")
suite.Panics(func() { NomsValueFromDecodedJSON(map[int]string{1: "one"}, false) }, "Should panic on map[int]string!")
}

View File

@@ -15,7 +15,6 @@ import (
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/util/profile"
"github.com/attic-labs/noms/samples/go/csv"
"github.com/attic-labs/noms/samples/go/util"
)
var (
@@ -37,16 +36,16 @@ func main() {
flag.Parse()
if flag.NArg() != 1 {
util.CheckError(errors.New("expected dataset arg"))
d.CheckError(errors.New("expected dataset arg"))
}
ds, err := spec.GetDataset(flag.Arg(0))
util.CheckError(err)
d.CheckError(err)
defer ds.Database().Close()
comma, err := csv.StringToRune(*delimiter)
util.CheckError(err)
d.CheckError(err)
err = d.Try(func() {
defer profile.MaybeStartProfile().Stop()

View File

@@ -22,7 +22,6 @@ import (
"github.com/attic-labs/noms/go/util/progressreader"
"github.com/attic-labs/noms/go/util/status"
"github.com/attic-labs/noms/samples/go/csv"
"github.com/attic-labs/noms/samples/go/util"
humanize "github.com/dustin/go-humanize"
)
@@ -58,7 +57,7 @@ func main() {
if flag.NArg() != 2 {
err := fmt.Errorf("Expected exactly two parameters (dataset and path) after flags, but you have %d. Maybe you put a flag after the path?", flag.NArg())
util.CheckError(err)
d.CheckError(err)
}
path := flag.Arg(1)
@@ -71,7 +70,7 @@ func main() {
comma, err := csv.StringToRune(*delimiter)
if err != nil {
util.CheckError(err)
d.CheckError(err)
return
}
@@ -106,7 +105,7 @@ func main() {
}
ds, err := spec.GetDataset(flag.Arg(0))
util.CheckError(err)
d.CheckError(err)
defer ds.Database().Close()
kinds := []types.NomsKind{}

View File

@@ -15,7 +15,7 @@ import (
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/samples/go/util"
"github.com/attic-labs/noms/go/util/jsontonoms"
)
func main() {
@@ -28,11 +28,11 @@ func main() {
flag.Parse()
if len(flag.Args()) != 2 {
util.CheckError(errors.New("expected url and dataset flags"))
d.CheckError(errors.New("expected url and dataset flags"))
}
ds, err := spec.GetDataset(flag.Arg(1))
util.CheckError(err)
d.CheckError(err)
url := flag.Arg(0)
if url == "" {
@@ -53,7 +53,7 @@ func main() {
log.Fatalln("Error decoding JSON: ", err)
}
_, err = ds.Commit(util.NomsValueFromDecodedJSON(jsonObject, true))
_, err = ds.Commit(jsontonoms.NomsValueFromDecodedJSON(jsonObject, true))
d.PanicIfError(err)
ds.Database().Close()
}

View File

@@ -20,7 +20,6 @@ import (
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/go/util/progressreader"
"github.com/attic-labs/noms/go/util/status"
"github.com/attic-labs/noms/samples/go/util"
human "github.com/dustin/go-humanize"
)
@@ -38,11 +37,11 @@ func main() {
flag.Parse()
if flag.NArg() != 2 {
util.CheckError(errors.New("expected dataset and url arguments"))
d.CheckError(errors.New("expected dataset and url arguments"))
}
ds, err := spec.GetDataset(flag.Arg(0))
util.CheckError(err)
d.CheckError(err)
defer ds.Database().Close()
url := flag.Arg(1)

View File

@@ -1,60 +0,0 @@
// Copyright 2016 The Noms Authors. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package util
import (
"flag"
"fmt"
"os"
"github.com/attic-labs/noms/go/d"
)
type ClientFlags struct {
concurrencyFlag *int
progressFileFlag *string
progressFile *os.File
}
func NewFlags() ClientFlags {
return NewFlagsWithPrefix("")
}
func NewFlagsWithPrefix(prefix string) ClientFlags {
return ClientFlags{
flag.Int(prefix+"concurrency", 100, "degree of concurrency"),
flag.String(prefix+"progress-file", "", "file for logging progress"),
nil,
}
}
func (cf *ClientFlags) Concurrency() int {
return *cf.concurrencyFlag
}
func (cf *ClientFlags) CreateProgressFile() error {
if *cf.progressFileFlag == "" {
return fmt.Errorf("No progress file specified")
}
pf, err := os.Create(*cf.progressFileFlag)
if err != nil {
return fmt.Errorf("Unable to create progress status file: %s, err: %s", *cf.progressFileFlag, err)
}
cf.progressFile = pf
cf.UpdateProgress(0.0)
return err
}
func (cf *ClientFlags) CloseProgressFile() {
d.Chk.True(cf.progressFile != nil, "Progress file was never created")
cf.progressFile.Close()
}
func (cf *ClientFlags) UpdateProgress(pct float32) {
d.Chk.True(pct >= 0.0 && pct <= 1.0, "%.6f is not a valid percentage, must be in range [0, 1]", pct)
if cf.progressFile != nil {
cf.progressFile.WriteString(fmt.Sprintf("%.6f\n", pct))
}
}

View File

@@ -1,38 +0,0 @@
// Copyright 2016 The Noms Authors. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package util
import (
"flag"
"net/http"
"os/user"
"path"
"github.com/attic-labs/noms/go/d"
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache"
)
const (
defaultDiskCacheDir = "~/noms/httpcache"
)
var (
diskCacheDir = flag.String("http-cache-dir", defaultDiskCacheDir, "a directory to use for an http disk cache between runs")
)
func CachingHttpClient() *http.Client {
if *diskCacheDir == "" {
return nil
}
if *diskCacheDir == defaultDiskCacheDir {
user, err := user.Current()
d.Chk.NoError(err)
*diskCacheDir = path.Join(user.HomeDir, "noms", "httpcache")
}
return httpcache.NewTransport(diskcache.New(*diskCacheDir)).Client()
}

View File

@@ -1,7 +0,0 @@
// Copyright 2016 The Noms Authors. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package util
//go:generate go run ../../nomdl/codegen/codegen.go

View File

@@ -18,8 +18,8 @@ import (
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/types"
"github.com/attic-labs/noms/go/util/jsontonoms"
"github.com/attic-labs/noms/go/util/profile"
"github.com/attic-labs/noms/samples/go/util"
"github.com/clbanning/mxj"
)
@@ -56,11 +56,11 @@ func main() {
flag.Parse()
if flag.NArg() != 2 {
util.CheckError(errors.New("Expected dataset followed by directory path"))
d.CheckError(errors.New("Expected dataset followed by directory path"))
}
dir := flag.Arg(1)
ds, err := spec.GetDataset(flag.Arg(0))
util.CheckError(err)
d.CheckError(err)
defer profile.MaybeStartProfile().Stop()
@@ -97,7 +97,7 @@ func main() {
object := xmlObject.Old()
file.Close()
nomsObj := util.NomsValueFromDecodedJSON(object, false)
nomsObj := jsontonoms.NomsValueFromDecodedJSON(object, false)
d.Chk.IsType(expectedType, nomsObj)
var r types.Ref