legal: package for compiled-in licenses

Initial implementation, printing helper and 'wiring' for cam* tools.

Change-Id: Icf8baa77ee1f12495be8f1a57b7d575d6918cb5c
This commit is contained in:
Piotr S. Staszewski 2014-07-03 22:03:31 +02:00
parent a9b25eca93
commit 5e61e2d84e
7 changed files with 149 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import (
"camlistore.org/pkg/client"
"camlistore.org/pkg/httputil"
"camlistore.org/pkg/index"
"camlistore.org/pkg/legal/legalprint"
"camlistore.org/pkg/osutil"
"camlistore.org/pkg/schema"
"camlistore.org/pkg/types"
@ -61,6 +62,10 @@ func main() {
return
}
if legalprint.MaybePrint(os.Stderr) {
return
}
if *flagGraph && flag.NArg() != 1 {
log.Fatalf("The --graph option requires exactly one parameter.")
}

View File

@ -36,6 +36,7 @@ import (
"camlistore.org/pkg/cacher"
"camlistore.org/pkg/client"
"camlistore.org/pkg/fs"
"camlistore.org/pkg/legal/legalprint"
"camlistore.org/pkg/osutil"
"camlistore.org/pkg/search"
"camlistore.org/third_party/bazil.org/fuse"
@ -63,6 +64,10 @@ func main() {
flag.Usage = usage
flag.Parse()
if legalprint.MaybePrint(os.Stderr) {
return
}
narg := flag.NArg()
if narg > 2 {
usage()

View File

@ -29,6 +29,7 @@ import (
"sync"
"camlistore.org/pkg/buildinfo"
"camlistore.org/pkg/legal/legalprint"
)
var (
@ -246,6 +247,9 @@ func Main() {
if *FlagHelp {
usage("")
}
if legalprint.MaybePrint(Stderr) {
return
}
if len(args) == 0 {
usage("No mode given.")
}

50
pkg/legal/legal.go Normal file
View File

@ -0,0 +1,50 @@
/*
Copyright 2014 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 legal provides project-wide storage for compiled-in licenses.
package legal
var licenses []string
func init() {
RegisterLicense(`
Copyright 2014 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.
`)
}
// RegisterLicense stores the license text.
// It doesn't check whether the text was already present.
func RegisterLicense(text string) {
licenses = append(licenses, text)
return
}
// Licenses returns a slice of the licenses.
func Licenses() []string {
return licenses
}

39
pkg/legal/legal_test.go Normal file
View File

@ -0,0 +1,39 @@
/*
Copyright 2014 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 legal
import (
"testing"
)
func TestRegisterLicense(t *testing.T) {
initial := len(licenses)
RegisterLicense("dummy")
if initial+1 != len(licenses) {
t.Fatal("didn't add a license")
}
}
func TestLicenses(t *testing.T) {
licenses := Licenses()
if len(licenses) < 2 {
t.Fatal("no second license text")
}
if licenses[1] != "dummy" {
t.Error("license text mismatch")
}
}

View File

@ -0,0 +1,42 @@
/*
Copyright 2014 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 legalprint provides a printing helper for the legal package.
package legalprint
import (
"flag"
"fmt"
"io"
"camlistore.org/pkg/legal"
)
var (
flagLegal = flag.Bool("legal", false, "show licenses")
)
// MaybePrint will print the licenses if flagLegal has been set.
// It will return the value of the flagLegal.
func MaybePrint(out io.Writer) bool {
if !*flagLegal {
return false
}
for _, text := range legal.Licenses() {
fmt.Fprintln(out, text)
}
return true
}

View File

@ -40,6 +40,7 @@ import (
"time"
"camlistore.org/pkg/buildinfo"
"camlistore.org/pkg/legal/legalprint"
"camlistore.org/pkg/misc"
"camlistore.org/pkg/osutil"
"camlistore.org/pkg/serverinit"
@ -340,6 +341,9 @@ func Main(up chan<- struct{}, down <-chan struct{}) {
buildinfo.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
return
}
if legalprint.MaybePrint(os.Stderr) {
return
}
if *flagReindex {
index.SetImpendingReindex()
}