Browse Source

broken

pull/103/head
Unknown 12 years ago
parent
commit
a5674f90c7
  1. 41
      doc/github.go
  2. 20
      doc/struct.go
  3. 4
      doc/walker.go
  4. 12
      install.go
  5. 1
      models/models.go

41
doc/github.go

@ -15,7 +15,6 @@ import (
"regexp"
"strings"
"github.com/GPMGo/gpm/models"
"github.com/GPMGo/gpm/utils"
)
@ -29,7 +28,7 @@ func SetGithubCredentials(id, secret string) {
githubCred = "client_id=" + id + "&client_secret=" + secret
}
func GetGithubDoc(client *http.Client, match map[string]string, commit string) (*models.PkgInfo, error) {
func GetGithubDoc(client *http.Client, match map[string]string, commit string) (*Package, error) {
SetGithubCredentials("1862bcb265171f37f36c", "308d71ab53ccd858416cfceaed52d5d5b7d53c5f")
match["cred"] = githubCred
@ -88,11 +87,17 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
// Create destination directory
os.Mkdir(installPath, os.ModePerm)
files := make([]*source, 0, len(r.File))
dirs := make([]string, 0, 5)
for _, f := range r.File {
srcName := f.FileInfo().Name()[strings.Index(f.FileInfo().Name(), "/")+1:]
fmt.Printf("Unzipping %s...", srcName)
fn := strings.Replace(f.FileInfo().Name(), shaName, installPath, 1)
absPath := strings.Replace(f.FileInfo().Name(), shaName, installPath, 1)
fmt.Printf("Unzipping %s...", absPath)
// Check if it is directory or not.
if strings.HasSuffix(absPath, "/") {
// Directory.
dirs = append(dirs, absPath)
continue
}
// Get files from archive
rc, err := f.Open()
@ -101,38 +106,38 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
}
// Create diretory before create file
os.MkdirAll(path.Dir(fn), os.ModePerm)
os.MkdirAll(path.Dir(absPath), os.ModePerm)
// Write data to file
fw, _ := os.Create(fn)
fw, _ := os.Create(absPath)
if err != nil {
return nil, err
}
_, err = io.Copy(fw, rc)
n, err := io.Copy(fw, rc)
if err != nil {
return nil, err
}
fmt.Println(n)
localF, _ := os.Open(fn)
/*localF, _ := os.Open(absPath)
fbytes := make([]byte, f.FileInfo().Size())
n, _ := localF.Read(fbytes)
fmt.Println(n)
// Check if Go source file.
if n > 0 && strings.HasSuffix(fn, ".go") {
if n > 0 && strings.HasSuffix(absPath, ".go") {
files = append(files, &source{
name: srcName,
data: fbytes,
})
}
}*/
}
w := &walker{
pinfo: &models.PkgInfo{
Path: importPath,
pkg := &Package{
ImportPath: importPath,
AbsPath: installPath,
Commit: commit,
},
Dirs: dirs,
}
return w.build(files)
return pkg, nil
}

20
doc/struct.go

@ -8,10 +8,24 @@ import (
"go/token"
"os"
"time"
"github.com/GPMGo/gpm/models"
)
// Package represents a package.
type Package struct {
// Package import path.
ImportPath string
AbsPath string
// Revision tag and project tags.
Commit string
// Imports.
Imports []string
// Directories.
Dirs []string
}
// source is source code file.
type source struct {
name string
@ -29,7 +43,7 @@ func (s *source) Sys() interface{} { return nil }
// walker holds the state used when building the documentation.
type walker struct {
pinfo *models.PkgInfo
pkg *Package
srcs map[string]*source // Source files.
fset *token.FileSet
}

4
doc/walker.go

@ -91,7 +91,7 @@ func simpleImporter(imports map[string]*ast.Object, path string) (*ast.Object, e
var buildPicPattern = regexp.MustCompile(`\[+!+\[+([a-zA-Z ]*)+\]+\(+[a-zA-z]+://[^\s]*`)
// build generates data from source files.
func (w *walker) build(srcs []*source) (*models.PkgInfo, error) {
/*func (w *walker) build(srcs []*source) (*models.PkgInfo, error) {
// Set created time.
w.pinfo.Created = time.Now().UTC()
@ -125,7 +125,6 @@ func (w *walker) build(srcs []*source) (*models.PkgInfo, error) {
if nogo {
err = nil
} else {
fmt.Println(w.pinfo)
return w.pinfo, errors.New("doc.walker.build(): " + err.Error())
}
}
@ -147,3 +146,4 @@ func (w *walker) build(srcs []*source) (*models.PkgInfo, error) {
// beego.Info("doc.walker.build(", pdoc.ImportPath, "), Goroutine #", runtime.NumGoroutine())
return w.pinfo, err
}
*/

12
install.go

@ -12,12 +12,12 @@ import (
"strings"
"github.com/GPMGo/gpm/doc"
"github.com/GPMGo/gpm/models"
"github.com/GPMGo/gpm/utils"
)
var (
isHasGit, isHasHg bool
downloadCache map[string]bool // Saves packages that have downloaded.
)
var cmdInstall = &Command{
@ -25,6 +25,7 @@ var cmdInstall = &Command{
}
func init() {
downloadCache = make(map[string]bool)
cmdInstall.Run = runInstall
cmdInstall.Flags = map[string]bool{
"-p": false,
@ -107,10 +108,13 @@ func downloadPackage(path, commit string) {
}
fmt.Printf("Downloading package: %s.\n", path)
_, err := pureDownload(path, commit)
pkg, err := pureDownload(path, commit)
if err != nil {
fmt.Printf("Fail to download package(%s) with error: %s.\n", path, err)
} else {
fmt.Println(pkg)
fmt.Printf("Checking imports(%s).\n", path)
fmt.Printf("Installing package: %s.\n", path)
}
}
@ -133,7 +137,7 @@ func checkGoGetFlags() (args []string) {
type service struct {
pattern *regexp.Regexp
prefix string
get func(*http.Client, map[string]string, string) (*models.PkgInfo, error)
get func(*http.Client, map[string]string, string) (*doc.Package, error)
}
// services is the list of source code control services handled by gopkgdoc.
@ -145,7 +149,7 @@ var services = []*service{
}
// pureDownload downloads package without control control.
func pureDownload(path, commit string) (pinfo *models.PkgInfo, err error) {
func pureDownload(path, commit string) (pinfo *doc.Package, err error) {
for _, s := range services {
if s.get == nil || !strings.HasPrefix(path, s.prefix) {
continue

1
models/models.go

@ -27,6 +27,7 @@ const (
type PkgInfo struct {
Id int64
Path string `qbs:"index"` // Import path of package.
AbsPath string
Imports []string
Note string
Created time.Time `qbs:"index"` // Time when information last updated.

Loading…
Cancel
Save