Skip to content

Commit

Permalink
[FAB-1535]Cleanup several pycharm warnings
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1535

Some warings are reported by pycharm IDE, this commit
fixs warnings. Specific warnings list in JIRA ticket.

Change-Id: I122ea6627627893e74227580468309e31a5d47e3
Signed-off-by: grapebaba <281165273@qq.com>
  • Loading branch information
GrapeBaBa committed Jan 11, 2017
1 parent b3c0fba commit d0e6fe8
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
4 changes: 3 additions & 1 deletion core/chaincode/platforms/car/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io/ioutil"

"errors"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
Expand All @@ -36,7 +38,7 @@ func generateHashcode(spec *pb.ChaincodeSpec, path string) (string, error) {

ctor := spec.CtorMsg
if ctor == nil || len(ctor.Args) == 0 {
return "", fmt.Errorf("Cannot generate hashcode from empty ctor")
return "", errors.New("Cannot generate hashcode from empty ctor")
}
ctorbytes, err := proto.Marshal(ctor)
if err != nil {
Expand Down
9 changes: 3 additions & 6 deletions core/chaincode/platforms/car/test/car_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,19 @@ func TestCar_BuildImage(t *testing.T) {
vm, err := container.NewVM()

if err != nil {
t.Fail()
t.Logf("Error getting VM: %s", err)
t.Errorf("Error getting VM: %s", err)
return
}
// Build the spec
cwd, err := os.Getwd()
if err != nil {
t.Fail()
t.Logf("Error getting CWD: %s", err)
t.Errorf("Error getting CWD: %s", err)
return
}

chaincodePath := cwd + "/org.hyperledger.chaincode.example02-0.1-SNAPSHOT.car"
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_CAR, ChaincodeID: &pb.ChaincodeID{Name: "cartest", Path: chaincodePath}, CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
if _, err := vm.BuildChaincodeContainer(spec); err != nil {
t.Fail()
t.Log(err)
t.Error(err)
}
}
10 changes: 5 additions & 5 deletions core/chaincode/platforms/golang/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getCodeFromHTTP(path string) (codegopath string, err error) {
}
}
if origgopath == "" {
err = fmt.Errorf("GOPATH not defined")
err = errors.New("GOPATH not defined")
return
}
// Only take the first element of GOPATH
Expand Down Expand Up @@ -126,7 +126,7 @@ func getCodeFromFS(path string) (codegopath string, err error) {
logger.Debugf("getCodeFromFS %s", path)
gopath := os.Getenv("GOPATH")
if gopath == "" {
err = fmt.Errorf("GOPATH not defined")
err = errors.New("GOPATH not defined")
return
}
// Only take the first element of GOPATH
Expand All @@ -143,17 +143,17 @@ func getCodeFromFS(path string) (codegopath string, err error) {
//with the same (name, ctor, args)
func collectChaincodeFiles(spec *pb.ChaincodeSpec, tw *tar.Writer) (string, error) {
if spec == nil {
return "", fmt.Errorf("Cannot collect files from nil spec")
return "", errors.New("Cannot collect files from nil spec")
}

chaincodeID := spec.ChaincodeID
if chaincodeID == nil || chaincodeID.Path == "" {
return "", fmt.Errorf("Cannot collect files from empty chaincode path")
return "", errors.New("Cannot collect files from empty chaincode path")
}

ctor := spec.CtorMsg
if ctor == nil || len(ctor.Args) == 0 {
return "", fmt.Errorf("Cannot collect files from empty ctor")
return "", errors.New("Cannot collect files from empty ctor")
}

//code root will point to the directory where the code exists
Expand Down
4 changes: 3 additions & 1 deletion core/chaincode/platforms/golang/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

"github.com/spf13/viper"

"errors"

cutil "github.com/hyperledger/fabric/core/container/util"
pb "github.com/hyperledger/fabric/protos/peer"
)
Expand All @@ -42,7 +44,7 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
}

if urlLocation == "" {
return fmt.Errorf("empty url location")
return errors.New("ChaincodeSpec's path/URL cannot be empty")
}

if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 {
Expand Down
6 changes: 3 additions & 3 deletions core/chaincode/platforms/golang/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func pathExists(path string) (bool, error) {

// ValidateSpec validates Go chaincodes
func (goPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
url, err := url.Parse(spec.ChaincodeID.Path)
if err != nil || url == nil {
path, err := url.Parse(spec.ChaincodeID.Path)
if err != nil || path == nil {
return fmt.Errorf("invalid path: %s", err)
}

//we have no real good way of checking existence of remote urls except by downloading and testin
//which we do later anyway. But we *can* - and *should* - test for existence of local paths.
//Treat empty scheme as a local filesystem path
if url.Scheme == "" {
if path.Scheme == "" {
gopath := os.Getenv("GOPATH")
// Only take the first element of GOPATH
gopath = filepath.SplitList(gopath)[0]
Expand Down
15 changes: 8 additions & 7 deletions core/chaincode/platforms/java/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"os/exec"
"strings"

"errors"

"github.com/golang/protobuf/proto"
ccutil "github.com/hyperledger/fabric/core/chaincode/platforms/util"
"github.com/hyperledger/fabric/core/util"
Expand All @@ -34,22 +36,21 @@ import (

func getCodeFromHTTP(path string) (codegopath string, err error) {

var tmp string
tmp, err = ioutil.TempDir("", "javachaincode")
codegopath, err = ioutil.TempDir("", "javachaincode")

if err != nil {
return "", fmt.Errorf("Error creating temporary file: %s", err)
}
var out bytes.Buffer

cmd := exec.Command("git", "clone", path, tmp)
cmd := exec.Command("git", "clone", path, codegopath)
cmd.Stderr = &out
cmderr := cmd.Run()
if cmderr != nil {
return "", fmt.Errorf("Error cloning git repository %s", cmderr)
}

return tmp, nil
return codegopath, nil

}

Expand All @@ -61,17 +62,17 @@ func getCodeFromHTTP(path string) (codegopath string, err error) {
//with the same (name, ctor, args)
func collectChaincodeFiles(spec *pb.ChaincodeSpec, tw *tar.Writer) (string, error) {
if spec == nil {
return "", fmt.Errorf("Cannot collect chaincode files from nil spec")
return "", errors.New("Cannot collect chaincode files from nil spec")
}

chaincodeID := spec.ChaincodeID
if chaincodeID == nil || chaincodeID.Path == "" {
return "", fmt.Errorf("Cannot collect chaincode files from empty chaincode path")
return "", errors.New("Cannot collect chaincode files from empty chaincode path")
}

ctor := spec.CtorMsg
if ctor == nil || len(ctor.Args) == 0 {
return "", fmt.Errorf("Cannot collect chaincode files from empty ctor")
return "", errors.New("Cannot collect chaincode files from empty ctor")
}

codepath := chaincodeID.Path
Expand Down
8 changes: 5 additions & 3 deletions core/chaincode/platforms/java/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (

"os"

"errors"

cutil "github.com/hyperledger/fabric/core/container/util"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/spf13/viper"
Expand All @@ -35,7 +37,7 @@ var buildCmd = map[string]string{
"pom.xml": "mvn -f pom.xml clean && mvn -f pom.xml package",
}

//return the type of build gradle/maven based on the file
//getBuildCmd returns the type of build gradle/maven based on the file
//found in java chaincode project root
//build.gradle - gradle - returns the first found build type
//pom.xml - maven
Expand All @@ -51,7 +53,7 @@ func getBuildCmd(packagePath string) (string, error) {
}
}
}
return "", fmt.Errorf("Build file not found")
return "", errors.New("Build file not found")
}
}

Expand All @@ -77,7 +79,7 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
}

if urlLocation == "" {
return fmt.Errorf("empty url location")
return errors.New("ChaincodeSpec's path/URL cannot be empty")
}

if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 {
Expand Down
4 changes: 2 additions & 2 deletions core/chaincode/platforms/java/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Platform struct {

//ValidateSpec validates the java chaincode specs
func (javaPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
url, err := url.Parse(spec.ChaincodeID.Path)
if err != nil || url == nil {
path, err := url.Parse(spec.ChaincodeID.Path)
if err != nil || path == nil {
return fmt.Errorf("invalid path: %s", err)
}

Expand Down

0 comments on commit d0e6fe8

Please sign in to comment.