mirror of https://github.com/gogits/gogs.git
Unknown
12 years ago
8 changed files with 112 additions and 230 deletions
@ -1,7 +1,7 @@ |
|||||||
# This is a configuration file for gpm with toml format. |
# This is a configuration file for gpm with toml format. |
||||||
|
|
||||||
title = "gpm(Go Package Manager)" |
title = "gpm(Go Package Manager)" |
||||||
version = "v0.1.2 Build 0522" |
version = "v0.1.3 Build 0522" |
||||||
username = "" |
username = "" |
||||||
password = "" |
password = "" |
||||||
user_language = "en-US" |
user_language = "en-US" |
@ -0,0 +1,28 @@ |
|||||||
|
LoadCommandUsage=Fail to load command(%s) usage[ %s ] |
||||||
|
ReadCoammndUsage=Unacceptable command(%s) usage file. |
||||||
|
LoadLocalData=Fail to load local data[ %s ] |
||||||
|
ParseJSON=Fail to parse JSON[ %s ] |
||||||
|
OpenFile=Fail to open file[ %s ] |
||||||
|
RemoveFile=Fail to remove file[ %s ] |
||||||
|
UnknownCommand=gpm: Unknown command %q. Run 'gpm help' for usage. |
||||||
|
MoveFile=Fail to move file from $GOPATH(%s) to current directory(%s). |
||||||
|
UnknownFlag=Unknown flag: %s. |
||||||
|
DownloadError=Fail to download package(%s)[ %s ] |
||||||
|
NotFoundError=Import path prefix matches known service, but regexp does not. |
||||||
|
ErrNoMatch=Unsupported VCS platform. |
||||||
|
|
||||||
|
MovedFile=Moved file from $GOPATH(%s) to current directory(%s). |
||||||
|
PureDownload=You enabled pure download. |
||||||
|
DownloadOnly=You enabled download without installing. |
||||||
|
DownloadExDeps=You enabled download dependencies in example. |
||||||
|
DownloadFromSrcs=You enabled download from sources. |
||||||
|
NoPackage=Please list at least one package/bundle/snapshot. |
||||||
|
DownloadPath=Packages will be downloaded to GOPATH(%s). |
||||||
|
InstallStatus=Installing package: %s. |
||||||
|
BundleInfo=Bundle(%s) contains following nodes: |
||||||
|
ContinueDownload=Continue to download?(Y/n). |
||||||
|
SkipDownloaded=Skipped downloaded package: %s. |
||||||
|
SkipInvalidPath=Skipped invalid import path: %s. |
||||||
|
InstallByGoGet=Installing package(%s) through 'go get'. |
||||||
|
NoVCSTool=No version control tool is available, pure download enabled! |
||||||
|
DownloadStatus=Downloading package: %s. |
@ -1,185 +0,0 @@ |
|||||||
// Copyright (c) 2013 GPMGo Members. All rights reserved.
|
|
||||||
// Use of this source code is governed by a MIT-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package models implemented database access funtions.
|
|
||||||
|
|
||||||
package models |
|
||||||
|
|
||||||
import ( |
|
||||||
"database/sql" |
|
||||||
"errors" |
|
||||||
//"os"
|
|
||||||
"strconv" |
|
||||||
"strings" |
|
||||||
"time" |
|
||||||
|
|
||||||
"github.com/coocood/qbs" |
|
||||||
_ "github.com/mattn/go-sqlite3" |
|
||||||
) |
|
||||||
|
|
||||||
const ( |
|
||||||
DB_NAME = "./data/gowalker.db" |
|
||||||
_SQLITE3_DRIVER = "sqlite3" |
|
||||||
) |
|
||||||
|
|
||||||
// PkgInfo is package information.
|
|
||||||
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.
|
|
||||||
Commit string // Revision tag and project tags.
|
|
||||||
} |
|
||||||
|
|
||||||
func connDb() *qbs.Qbs { |
|
||||||
// 'sql.Open' only returns error when unknown driver, so it's not necessary to check in other places.
|
|
||||||
db, err := sql.Open(_SQLITE3_DRIVER, DB_NAME) |
|
||||||
if err != nil { |
|
||||||
//beego.Error("models.connDb():", err)
|
|
||||||
} |
|
||||||
q := qbs.New(db, qbs.NewSqlite3()) |
|
||||||
return q |
|
||||||
} |
|
||||||
|
|
||||||
func setMg() (*qbs.Migration, error) { |
|
||||||
db, err := sql.Open(_SQLITE3_DRIVER, DB_NAME) |
|
||||||
mg := qbs.NewMigration(db, DB_NAME, qbs.NewSqlite3()) |
|
||||||
return mg, err |
|
||||||
} |
|
||||||
|
|
||||||
/*func init() { |
|
||||||
// Initialize database.
|
|
||||||
os.Mkdir("./data", os.ModePerm) |
|
||||||
|
|
||||||
// Connect to database.
|
|
||||||
q := connDb() |
|
||||||
defer q.Db.Close() |
|
||||||
|
|
||||||
mg, err := setMg() |
|
||||||
if err != nil { |
|
||||||
beego.Error("models.init():", err) |
|
||||||
} |
|
||||||
defer mg.Db.Close() |
|
||||||
|
|
||||||
// Create data tables.
|
|
||||||
mg.CreateTableIfNotExists(new(PkgInfo)) |
|
||||||
|
|
||||||
beego.Trace("Initialized database ->", DB_NAME) |
|
||||||
}*/ |
|
||||||
|
|
||||||
// GetProInfo returns package information from database.
|
|
||||||
func GetPkgInfo(path string) (*PkgInfo, error) { |
|
||||||
// Check path length to reduce connect times.
|
|
||||||
if len(path) == 0 { |
|
||||||
return nil, errors.New("models.GetPkgInfo(): Empty path as not found.") |
|
||||||
} |
|
||||||
|
|
||||||
// Connect to database.
|
|
||||||
q := connDb() |
|
||||||
defer q.Db.Close() |
|
||||||
|
|
||||||
pinfo := new(PkgInfo) |
|
||||||
err := q.WhereEqual("path", path).Find(pinfo) |
|
||||||
|
|
||||||
return pinfo, err |
|
||||||
} |
|
||||||
|
|
||||||
// GetGroupPkgInfo returns group of package infomration in order to reduce database connect times.
|
|
||||||
func GetGroupPkgInfo(paths []string) ([]*PkgInfo, error) { |
|
||||||
// Connect to database.
|
|
||||||
q := connDb() |
|
||||||
defer q.Db.Close() |
|
||||||
|
|
||||||
pinfos := make([]*PkgInfo, 0, len(paths)) |
|
||||||
for _, v := range paths { |
|
||||||
if len(v) > 0 { |
|
||||||
pinfo := new(PkgInfo) |
|
||||||
err := q.WhereEqual("path", v).Find(pinfo) |
|
||||||
if err == nil { |
|
||||||
pinfos = append(pinfos, pinfo) |
|
||||||
} else { |
|
||||||
pinfos = append(pinfos, &PkgInfo{Path: v}) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return pinfos, nil |
|
||||||
} |
|
||||||
|
|
||||||
// GetPkgInfoById returns package information from database by pid.
|
|
||||||
func GetPkgInfoById(pid int) (*PkgInfo, error) { |
|
||||||
// Connect to database.
|
|
||||||
q := connDb() |
|
||||||
defer q.Db.Close() |
|
||||||
|
|
||||||
pinfo := new(PkgInfo) |
|
||||||
err := q.WhereEqual("id", pid).Find(pinfo) |
|
||||||
|
|
||||||
return pinfo, err |
|
||||||
} |
|
||||||
|
|
||||||
// GetGroupPkgInfoById returns group of package infomration by pid in order to reduce database connect times.
|
|
||||||
// The formatted pid looks like '$<pid>|', so we need to cut '$' here.
|
|
||||||
func GetGroupPkgInfoById(pids []string) ([]*PkgInfo, error) { |
|
||||||
// Connect to database.
|
|
||||||
q := connDb() |
|
||||||
defer q.Db.Close() |
|
||||||
|
|
||||||
pinfos := make([]*PkgInfo, 0, len(pids)) |
|
||||||
for _, v := range pids { |
|
||||||
if len(v) > 1 { |
|
||||||
pid, err := strconv.Atoi(v[1:]) |
|
||||||
if err == nil { |
|
||||||
pinfo := new(PkgInfo) |
|
||||||
err = q.WhereEqual("id", pid).Find(pinfo) |
|
||||||
if err == nil { |
|
||||||
pinfos = append(pinfos, pinfo) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return pinfos, nil |
|
||||||
} |
|
||||||
|
|
||||||
// DeleteProject deletes everything about the path in database, and update import information.
|
|
||||||
func DeleteProject(path string) error { |
|
||||||
// Check path length to reduce connect times. (except launchpad.net)
|
|
||||||
if path[0] != 'l' && len(strings.Split(path, "/")) <= 2 { |
|
||||||
return errors.New("models.DeleteProject(): Short path as not needed.") |
|
||||||
} |
|
||||||
|
|
||||||
// Connect to database.
|
|
||||||
q := connDb() |
|
||||||
defer q.Db.Close() |
|
||||||
|
|
||||||
var i1 int64 |
|
||||||
// Delete package information.
|
|
||||||
info := new(PkgInfo) |
|
||||||
err := q.WhereEqual("path", path).Find(info) |
|
||||||
if err == nil { |
|
||||||
i1, err = q.Delete(info) |
|
||||||
if err != nil { |
|
||||||
//beego.Error("models.DeleteProject(): Information:", err)
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if i1 > 0 { |
|
||||||
//beego.Info("models.DeleteProject(", path, i1, ")")
|
|
||||||
} |
|
||||||
|
|
||||||
return nil |
|
||||||
} |
|
||||||
|
|
||||||
// SearchDoc returns packages information that contain keyword
|
|
||||||
func SearchDoc(key string) ([]*PkgInfo, error) { |
|
||||||
// Connect to database.
|
|
||||||
q := connDb() |
|
||||||
defer q.Db.Close() |
|
||||||
|
|
||||||
var pkgInfos []*PkgInfo |
|
||||||
condition := qbs.NewCondition("path like ?", "%"+key+"%") |
|
||||||
err := q.Condition(condition).OrderBy("path").FindAll(&pkgInfos) |
|
||||||
return pkgInfos, err |
|
||||||
} |
|
Loading…
Reference in new issue