Browse Source

broken

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

43
doc/github.go

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

24
doc/struct.go

@ -8,10 +8,24 @@ import (
"go/token" "go/token"
"os" "os"
"time" "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. // source is source code file.
type source struct { type source struct {
name string name string
@ -29,7 +43,7 @@ func (s *source) Sys() interface{} { return nil }
// walker holds the state used when building the documentation. // walker holds the state used when building the documentation.
type walker struct { type walker struct {
pinfo *models.PkgInfo pkg *Package
srcs map[string]*source // Source files. srcs map[string]*source // Source files.
fset *token.FileSet 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]*`) var buildPicPattern = regexp.MustCompile(`\[+!+\[+([a-zA-Z ]*)+\]+\(+[a-zA-z]+://[^\s]*`)
// build generates data from source files. // 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. // Set created time.
w.pinfo.Created = time.Now().UTC() w.pinfo.Created = time.Now().UTC()
@ -125,7 +125,6 @@ func (w *walker) build(srcs []*source) (*models.PkgInfo, error) {
if nogo { if nogo {
err = nil err = nil
} else { } else {
fmt.Println(w.pinfo)
return w.pinfo, errors.New("doc.walker.build(): " + err.Error()) 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()) // beego.Info("doc.walker.build(", pdoc.ImportPath, "), Goroutine #", runtime.NumGoroutine())
return w.pinfo, err return w.pinfo, err
} }
*/

12
install.go

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

1
models/models.go

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

Loading…
Cancel
Save