Commits

Yoshifumi YAMAGUCHI committed 267d951

made -pkg option work

Comments (0)

Files changed (4)

 	"fmt"
 	"log"
 	"os"
-	"path"
 	"pypi"
 	"strings"
 	"time"
 	}
 
 	if err != nil {
-		return nil, err
+		log.Printf("%s: error on fetching deps", name)
 	}
 
 	return result, nil
 	} else if Pkg != "" {
 		deps, err := pkg(Pkg)
 		if err != nil {
-			log.Fatalf("error, %s", err)
+			log.Fatalf("%s", err)
 		}
 		for _, d := range deps {
 			fmt.Printf("%v\n", d)

src/pypi/fetch.go

 import (
 	"encoding/json"
 	"errors"
-	"fmt"
 	"io/ioutil"
 	"net/http"
 	"os"
 	var setupPyPtn = regexp.MustCompile("setup.py$")
 	depth := 100
 	return func(path string, f os.FileInfo, err error) error {
-		if setupPyPtn.MatchStrig(path) && f.IsFile() {
-			curDepth = len(strings.Split(path, "/"))
+		if setupPyPtn.MatchString(path) && !f.IsDir() {
+			curDepth := len(strings.Split(path, "/"))
 			if curDepth < depth {
 				*setupPyPath = path
 				depth = curDepth
 			}
 		}
+		return nil
 	}
 }
 
 	cmd := exec.Command("python", "setup.py", "egg_info")
 	err = cmd.Run()
 	if err != nil {	return err }
+
+	return nil
 }
 
 // Run egg_info with assumption that setup.py uses 'setuptools'.
-func readRequires(buf []byte) filepath.WalkFunc {
-	var eggInfoDirPtn = regexp.MustCompile("\.egg_info$")
+func readRequires(buf *[]byte) filepath.WalkFunc {
+	var eggInfoDirPtn = regexp.MustCompile("egg-info$")
 
 	return func(path string, f os.FileInfo, err error) error {
 		if eggInfoDirPtn.MatchString(path) && f.IsDir() {
 			if err != nil {	return err }
 
 			requirementsFile := filepath.Join(path, "requires.txt")
-			buf, err = ioutil.ReadFile(requirements_file)
+			*buf, err = ioutil.ReadFile(requirementsFile)
 			if err != nil { return err }
-
 		}
 		return nil
 	}
 	pwd, err := os.Getwd()
 
 	tmpDir := filepath.Join(pwd, "tmp")
-	err := os.Mkdir(tmpDir)
+	err = os.MkdirAll(tmpDir, os.ModePerm)
 	if err != nil {	return []string{}, err }
 
 	err = os.Chdir(tmpDir)
 	if err != nil {	return []string{}, err }
 
 	var setupPy string
-	err = filepath.Walk(pwd, findSetupPy(&setupPy))
+	err = filepath.Walk(tmpDir, findSetupPy(&setupPy))
 	if err != nil {	return []string{}, err }
+
 	err = runSetupPy(setupPy)
-	if err != nil {	return []string{}, err }
+	if err != nil {
+		_ = os.RemoveAll(tmpDir)
+		return []string{}, err
+	}
 
 	var buf []byte
-	err = filepath.Walk(pwd, readRequires(buf))
+	err = filepath.Walk(filepath.Dir(setupPy), readRequires(&buf))
 	if err != nil {	return []string{}, err }
 
 	lines := strings.Split(string(buf), "\n")
 		}
 	}
 
-	_ = os.RemoveAll(tmpDir)
-
 	return deps, nil
 }
 

src/pypi/types.go

 
 package pypi
 
+import "time"
+
 type PackageInfo struct {
 	Name            string
 	Version         string
 	return err
 }
 
-func Untarbz2(f *os.File) errror {
+func Untarbz2(f *os.File) error {
 	cmd := exec.Command("tar", "xjf", f.Name())
 	err := cmd.Run()
 	return err
 }
 
-func Expand(f *.os.File) error {
+func Expand(f *os.File) error {
 	ext := filepath.Ext(f.Name())
 	switch {
 	case ".zip" == ext: